From 6bbb2e9801ed170bab70c7452e067e425731c61c Mon Sep 17 00:00:00 2001 From: akuma06 Date: Fri, 14 Jul 2017 17:53:37 +0200 Subject: [PATCH] Preload User on find. Should fix the edit not showing up for anonymous. Fix issue with hidden checkbox and remake one on chrome. Refactor flag list on edit/upload form. Now a helper function in flags helper. --- models/torrent.go | 3 +++ models/torrents/find.go | 2 +- templates/admin/paneltorrentedit.jet.html | 10 +++------- templates/layouts/partials/helpers/flags.jet.html | 8 ++++++++ templates/site/torrents/edit.jet.html | 12 ++++-------- templates/site/torrents/upload.jet.html | 12 ++++-------- utils/upload/upload.go | 2 ++ 7 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 templates/layouts/partials/helpers/flags.jet.html diff --git a/models/torrent.go b/models/torrent.go index b5942630..fe22a756 100644 --- a/models/torrent.go +++ b/models/torrent.go @@ -17,6 +17,7 @@ import ( "net/url" "github.com/NyaaPantsu/nyaa/config" + "github.com/NyaaPantsu/nyaa/utils/cache" "github.com/NyaaPantsu/nyaa/utils/format" "github.com/NyaaPantsu/nyaa/utils/log" "github.com/NyaaPantsu/nyaa/utils/sanitize" @@ -362,6 +363,7 @@ func TorrentsToJSON(t []Torrent) []TorrentJSON { // Update : Update a torrent based on model func (t *Torrent) Update(unscope bool) (int, error) { + cache.C.Delete(t.Identifier()) db := ORM if unscope { db = ORM.Unscoped() @@ -391,6 +393,7 @@ func (t *Torrent) UpdateUnscope() (int, error) { // DeleteTorrent : delete a torrent based on id func (t *Torrent) Delete(definitely bool) (*Torrent, int, error) { + cache.C.Delete(t.Identifier()) db := ORM if definitely { db = ORM.Unscoped() diff --git a/models/torrents/find.go b/models/torrents/find.go index cb0afeb9..6744ba8d 100644 --- a/models/torrents/find.go +++ b/models/torrents/find.go @@ -29,7 +29,7 @@ func FindByID(id uint) (*models.Torrent, error) { } - tmp := models.ORM.Where("torrent_id = ?", id).Preload("Scrape").Preload("Comments") + tmp := models.ORM.Where("torrent_id = ?", id).Preload("Scrape").Preload("Uploader").Preload("Comments") if id > config.Get().Models.LastOldTorrentID { tmp = tmp.Preload("FileList") } diff --git a/templates/admin/paneltorrentedit.jet.html b/templates/admin/paneltorrentedit.jet.html index 77554905..572cde44 100644 --- a/templates/admin/paneltorrentedit.jet.html +++ b/templates/admin/paneltorrentedit.jet.html @@ -1,4 +1,5 @@ {{ extends "layouts/index_admin" }} +{{ import "layouts/partials/helpers/flags" }} {{block title()}}{{ T("torrent_edit_panel") }}{{end}} {{ block content_body()}}
@@ -20,12 +21,7 @@
- {{ range _, language := GetTorrentLanguages() }} - - - - - {{ end }} + {{ yield flagList(languages=GetTorrentLanguages(), selected=Form.Languages) }}
@@ -39,7 +35,7 @@

- +

diff --git a/templates/layouts/partials/helpers/flags.jet.html b/templates/layouts/partials/helpers/flags.jet.html new file mode 100644 index 00000000..bb1690ad --- /dev/null +++ b/templates/layouts/partials/helpers/flags.jet.html @@ -0,0 +1,8 @@ +{{ block flagList(languages=nil, selected="")}} + {{ range _, language := languages }} + + + + + {{ end }} +{{ end }} \ No newline at end of file diff --git a/templates/site/torrents/edit.jet.html b/templates/site/torrents/edit.jet.html index d29d22e3..7d75f436 100644 --- a/templates/site/torrents/edit.jet.html +++ b/templates/site/torrents/edit.jet.html @@ -1,6 +1,7 @@ {{ extends "layouts/index_site" }} {{ import "layouts/partials/helpers/csrf" }} {{ import "layouts/partials/helpers/errors" }} +{{ import "layouts/partials/helpers/flags" }} {{block title()}}{{T("torrent_edit_panel")}}{{end}} {{block content_body()}}
@@ -25,23 +26,18 @@
- {{ range _, language := GetTorrentLanguages() }} - - - - - - {{ end }} + {{ yield flagList(languages=GetTorrentLanguages(), selected=Form.Languages) }}
{{ yield errors(name="language")}}
- + {{ yield errors(name="remake")}}
{{ if User.ID > 0 }}

- + {{ yield errors(name="hidden")}}

diff --git a/templates/site/torrents/upload.jet.html b/templates/site/torrents/upload.jet.html index 781b1c6f..0a904b89 100644 --- a/templates/site/torrents/upload.jet.html +++ b/templates/site/torrents/upload.jet.html @@ -1,6 +1,7 @@ {{ extends "layouts/index_site" }} {{ import "layouts/partials/helpers/csrf" }} {{ import "layouts/partials/helpers/captcha" }} +{{ import "layouts/partials/helpers/flags" }} {{block title()}}{{ T("upload")}}{{end}} {{block content_body()}}
@@ -31,25 +32,20 @@

{{ T("torrent_language") }}

- {{ range _, language := GetTorrentLanguages() }} - - - - - {{ end }} + {{ yield flagList(languages=GetTorrentLanguages(), selected=Form.Languages) }}

{{ T("language_not_mandatory") }}

{{ yield errors(name="language")}}

- +

{{ yield errors(name="remake")}} {{ if User.ID > 0 }}

- +

{{ yield errors(name="hidden")}} diff --git a/utils/upload/upload.go b/utils/upload/upload.go index 4f9ac1f7..ab8bc175 100644 --- a/utils/upload/upload.go +++ b/utils/upload/upload.go @@ -177,6 +177,8 @@ func UpdateTorrent(r *torrentValidator.UpdateRequest, t *models.Torrent, current } t.Status = status + t.Hidden = r.Update.Hidden + return t }