mark export works
This commit is contained in:
parent
b7d5f08978
commit
98457565c9
|
@ -1,11 +1,11 @@
|
||||||
$(document).ready( function () {
|
$(document).ready( function () {
|
||||||
$("#datepicker").datepicker();
|
$("#datepicker").datepicker();
|
||||||
|
|
||||||
$("confirm-export").confirm({
|
$(".confirm-export").confirm({
|
||||||
"text": "Mark current batch exported?",
|
"text": "Mark current batch exported?",
|
||||||
"title": "Export confrimation",
|
"title": "Export confrimation",
|
||||||
confirm: function() {
|
confirm: function() {
|
||||||
alert('exported!');
|
window.location = "/export";
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
11
news/news.go
11
news/news.go
|
@ -105,4 +105,15 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
|
||||||
|
|
||||||
func (this *NewsContainer) HeaderDepth(start int) int {
|
func (this *NewsContainer) HeaderDepth(start int) int {
|
||||||
return start + this.Category.Depth()
|
return start + this.Category.Depth()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark the current batch (news.exported is null) as exported in this batch (exported = now())
|
||||||
|
func MarkExported(db *sql.DB) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
_, err := db.Exec("UPDATE news SET exported=$1 WHERE exported is null", now)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("DB errror: news.MarkExported():", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
|
@ -219,8 +219,18 @@ func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User
|
||||||
ShowTemplate("list", w, map[string]interface{}{"user": user, "flashes": flashes, "template": &templateBuf, "url": config.Url})
|
ShowTemplate("list", w, map[string]interface{}{"user": user, "flashes": flashes, "template": &templateBuf, "url": config.Url})
|
||||||
}
|
}
|
||||||
|
|
||||||
func templatePostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func exportHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
session, _ := store.Get(r, "c_user")
|
||||||
|
|
||||||
|
err := news.MarkExported(db)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
session.AddFlash("Error marking last batch of news exported", flash_err)
|
||||||
|
} else {
|
||||||
|
session.AddFlash("Last batch of news marked exported", flash_info)
|
||||||
|
}
|
||||||
|
session.Save(r, w)
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,7 +245,8 @@ func init_route_handlers() {
|
||||||
r.HandleFunc("/logout", userHandler(LogoutHandler))
|
r.HandleFunc("/logout", userHandler(LogoutHandler))
|
||||||
|
|
||||||
r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler)))
|
r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler)))
|
||||||
r.HandleFunc("/", getPostHandler(userHandler(templateFormHandler), userHandler(templatePostHandler)))
|
r.HandleFunc("/", userHandler(templateFormHandler))
|
||||||
|
r.HandleFunc("/export", userHandler(exportHandler))
|
||||||
|
|
||||||
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
|
Loading…
Reference in New Issue