2017-07-16 17:20:35 +02:00
package templates
2017-06-28 13:42:38 +02:00
import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"net/url"
"path"
"testing"
2017-08-03 03:38:07 +02:00
"github.com/NyaaPantsu/nyaa/utils/validator/announcement"
2017-06-28 13:42:38 +02:00
"strings"
2017-07-13 19:45:09 +02:00
"time"
2017-06-28 13:42:38 +02:00
"github.com/CloudyKit/jet"
"github.com/NyaaPantsu/nyaa/config"
2017-07-03 00:34:18 +02:00
"github.com/NyaaPantsu/nyaa/models"
2017-07-13 19:45:09 +02:00
"github.com/NyaaPantsu/nyaa/utils/filelist"
2017-07-28 05:46:40 +02:00
"github.com/NyaaPantsu/nyaa/utils/oauth2/client"
2017-07-02 16:54:55 +02:00
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
2017-07-28 05:46:40 +02:00
"github.com/NyaaPantsu/nyaa/utils/validator/api"
2017-07-03 00:34:18 +02:00
"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
"github.com/NyaaPantsu/nyaa/utils/validator/user"
2017-06-28 13:42:38 +02:00
"github.com/gin-gonic/gin"
)
// run before router/init.go:init()
var _ = func ( ) ( _ struct { } ) {
gin . SetMode ( gin . TestMode )
2017-07-21 01:36:25 +02:00
config . Configpaths [ 1 ] = path . Join ( ".." , config . Configpaths [ 1 ] )
config . Configpaths [ 0 ] = path . Join ( ".." , config . Configpaths [ 0 ] )
2017-07-10 14:11:05 +02:00
config . Reload ( )
2017-06-28 13:42:38 +02:00
return
} ( )
func TestTemplates ( t * testing . T ) {
//var View = jet.NewHTMLSet(TemplateDir)
fmt . Print ( "JetTest Template started\n" )
walkDirTest ( "/" , t )
}
type ContextTest map [ string ] func ( jet . VarMap ) jet . VarMap
func walkDirTest ( dir string , t * testing . T ) {
2017-07-28 05:46:40 +02:00
fu := "http://nyaa.cat"
em := "cop@cat.fe"
2017-07-28 23:02:37 +02:00
Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor
First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.
Added new behaviour as discussed in #1334
* fix fallback to ES
* Added some comments to explain PG fallback + log err moved
* Refactored search
Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods
* 1rst Refactor of Tags (WTF already?!)
Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.
Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.
This behaviour depends on the callbackOnType function in tag/helpers.go
* fix for modtools :')
* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.
New Helper + New Changelog for translation string.
* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the link to the modal on torrent view.
More comments in the functions for tags
* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors
* Fix compile error + Tests Errors
* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings
TODO: test/fix adding tag on upload/edit
* Mini fix to display video quality
+ tags works/tested on modo edit
* Fix editing tags on modpanel
* Edit tags works
* Add translation string
* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd
* Fix Ajax tag Removal&Add
* Added form for descriptive tags
* Forgot to add the link between database and form for descriptive tags.
* Adding the increase/decrease pantsu for descriptive tags
* Fix #1370
* When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
fakeTag := & models . Tag { 1 , 1 , "12345" , "anidbid" , 1 , 0 , true }
2017-09-08 20:46:45 +02:00
fakeUser := & models . User { 1 , "test" , "test" , "test" , 1 , time . Now ( ) , time . Now ( ) , "test" , time . Now ( ) , "en" , "test" , "test" , "test" , "test" , "test" , 0.0 , [ ] models . User { } , [ ] models . User { } , "test" , [ ] models . Torrent { } , [ ] models . Notification { } , 1 , models . UserSettings { } , [ ] models . Tag { * fakeTag } }
2017-07-13 19:45:09 +02:00
fakeComment := & models . Comment { 1 , 1 , 1 , "test" , time . Now ( ) , time . Now ( ) , nil , & models . Torrent { } , fakeUser }
fakeScrapeData := & models . Scrape { 1 , 0 , 0 , 10 , time . Now ( ) }
fakeFile := & models . File { 1 , 1 , "l12:somefile.mp4e" , 3 }
fakeLanguages := [ ] string { "fr" , "en" }
Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor
First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.
Added new behaviour as discussed in #1334
* fix fallback to ES
* Added some comments to explain PG fallback + log err moved
* Refactored search
Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods
* 1rst Refactor of Tags (WTF already?!)
Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.
Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.
This behaviour depends on the callbackOnType function in tag/helpers.go
* fix for modtools :')
* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.
New Helper + New Changelog for translation string.
* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the link to the modal on torrent view.
More comments in the functions for tags
* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors
* Fix compile error + Tests Errors
* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings
TODO: test/fix adding tag on upload/edit
* Mini fix to display video quality
+ tags works/tested on modo edit
* Fix editing tags on modpanel
* Edit tags works
* Add translation string
* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd
* Fix Ajax tag Removal&Add
* Added form for descriptive tags
* Forgot to add the link between database and form for descriptive tags.
* Adding the increase/decrease pantsu for descriptive tags
* Fix #1370
* When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
fakeTorrent := & models . Torrent { 1 , "test" , "test" , 3 , 12 , 1 , false , time . Now ( ) , 1 , 0 , 3 , "test" , "test" , "test" , 12 , 12 , 12 , 12 , "" , "" , "" , nil , fakeUser , "test" , [ ] models . OldComment { } , [ ] models . Comment { * fakeComment , * fakeComment } , [ ] models . Tag { * fakeTag , * fakeTag } , fakeScrapeData , [ ] models . File { * fakeFile } , fakeLanguages }
2017-07-13 19:45:09 +02:00
fakeActivity := & models . Activity { 1 , "t" , "e" , "s" , 1 , fakeUser }
fakeDB := & models . DatabaseDump { time . Now ( ) , 3 , "test" , "test" }
fakeLanguage := & publicSettings . Language { "English" , "en" , "en-us" }
Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor
First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.
Added new behaviour as discussed in #1334
* fix fallback to ES
* Added some comments to explain PG fallback + log err moved
* Refactored search
Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods
* 1rst Refactor of Tags (WTF already?!)
Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.
Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.
This behaviour depends on the callbackOnType function in tag/helpers.go
* fix for modtools :')
* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.
New Helper + New Changelog for translation string.
* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the link to the modal on torrent view.
More comments in the functions for tags
* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors
* Fix compile error + Tests Errors
* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings
TODO: test/fix adding tag on upload/edit
* Mini fix to display video quality
+ tags works/tested on modo edit
* Fix editing tags on modpanel
* Edit tags works
* Add translation string
* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd
* Fix Ajax tag Removal&Add
* Added form for descriptive tags
* Forgot to add the link between database and form for descriptive tags.
* Adding the increase/decrease pantsu for descriptive tags
* Fix #1370
* When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
fakeTorrentRequest := & torrentValidator . TorrentRequest { Name : "test" , Magnet : "" , Category : "" , Remake : false , Description : "" , Status : 1 , Hidden : false , CaptchaID : "" , WebsiteLink : "" , SubCategory : 0 , Languages : nil , Infohash : "" , SubCategoryID : 0 , CategoryID : 0 , Filesize : 0 , Filepath : "" , FileList : nil , Trackers : nil , Tags : torrentValidator . TagsRequest { } }
2017-08-26 04:57:02 +02:00
fakeLogin := & userValidator . LoginForm { "test" , "test" , "/" , "false" }
2017-07-13 19:45:09 +02:00
fakeRegistration := & userValidator . RegistrationForm { "test" , "" , "test" , "test" , "xxxx" , "1" }
fakeReport := & models . TorrentReport { 1 , "test" , 1 , 1 , time . Now ( ) , fakeTorrent , fakeUser }
2017-07-28 05:46:40 +02:00
fakeOauthForm := apiValidator . CreateForm { "" , "f" , [ ] string { fu } , [ ] string { } , [ ] string { } , "" , "fedr" , fu , fu , fu , fu , [ ] string { em } , "" }
fakeOauthModel := fakeOauthForm . Bind ( & models . OauthClient { } )
fakeClient := client . Client { "" , "" , "" , [ ] string { "" } , [ ] string { "" } , [ ] string { "" } , "" , "" , "" , "" , "" , "" , [ ] string { "" } , false }
2017-08-03 03:38:07 +02:00
fakeAnnouncement := announcementValidator . CreateForm { 1 , "" , 2 }
fakeNotification := & models . Notification { 1 , "test" , true , "test" , "test" , time . Now ( ) , 1 }
2017-07-28 23:02:37 +02:00
2017-07-16 00:38:07 +02:00
contextvariables := ContextTest {
"dumps.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "GPGLink" , "test" )
variables . Set ( "ListDumps" , [ ] models . DatabaseDumpJSON { fakeDB . ToJSON ( ) , fakeDB . ToJSON ( ) } )
return variables
} ,
"activities.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . Activity { * fakeActivity } )
return variables
} ,
"listing.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . TorrentJSON { fakeTorrent . ToJSON ( ) , fakeTorrent . ToJSON ( ) } )
return variables
} ,
"edit.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
2017-07-20 20:21:57 +02:00
variables . Set ( "NbTorrents" , 0 )
2017-07-16 00:38:07 +02:00
variables . Set ( "Form" , fakeTorrentRequest )
variables . Set ( "Languages" , publicSettings . Languages { * fakeLanguage , * fakeLanguage } )
return variables
} ,
2017-07-20 20:21:57 +02:00
"torrents.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "NbTorrents" , 0 )
return variables
} ,
"profile.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "NbTorrents" , 0 )
return variables
} ,
2017-07-16 00:38:07 +02:00
"upload.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , fakeTorrentRequest )
return variables
} ,
"view.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
2017-07-20 20:21:57 +02:00
variables . Set ( "NbTorrents" , 0 )
2017-07-16 00:38:07 +02:00
variables . Set ( "Torrent" , fakeTorrent . ToJSON ( ) )
variables . Set ( "CaptchaID" , "xxxxxx" )
variables . Set ( "RootFolder" , filelist . FileListToFolder ( fakeTorrent . FileList , "root" ) )
return variables
} ,
"settings.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , & LanguagesJSONResponse { "test" , publicSettings . Languages { * fakeLanguage , * fakeLanguage } } )
return variables
} ,
"login.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , fakeLogin )
return variables
} ,
"register.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , fakeRegistration )
return variables
} ,
"index.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Torrents" , [ ] models . Torrent { * fakeTorrent , * fakeTorrent } )
variables . Set ( "Users" , [ ] models . User { * fakeUser , * fakeUser } )
variables . Set ( "Comments" , [ ] models . Comment { * fakeComment , * fakeComment } )
variables . Set ( "TorrentReports" , [ ] models . TorrentReportJSON { fakeReport . ToJSON ( ) , fakeReport . ToJSON ( ) } )
return variables
} ,
"paneltorrentedit.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , * fakeTorrent )
return variables
} ,
"reassign.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
2017-07-16 17:20:35 +02:00
variables . Set ( "Form" , torrentValidator . ReassignForm { 1 , "" , "" , [ ] uint { 1 , 1 } } )
2017-07-16 00:38:07 +02:00
return variables
} ,
"torrentlist.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . Torrent { * fakeTorrent , * fakeTorrent } )
return variables
} ,
"userlist.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . User { * fakeUser , * fakeUser } )
return variables
} ,
"commentlist.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . Comment { * fakeComment , * fakeComment } )
return variables
} ,
"torrent_report.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . TorrentReportJSON { fakeReport . ToJSON ( ) , fakeReport . ToJSON ( ) } )
return variables
} ,
2017-07-20 20:21:57 +02:00
"notifications.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "NbTorrents" , 0 )
return variables
} ,
2017-07-16 00:38:07 +02:00
"report.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
2017-07-04 01:22:12 +02:00
type form struct {
2017-07-04 01:23:17 +02:00
ID int
CaptchaID string
2017-07-04 01:22:12 +02:00
}
2017-07-16 00:38:07 +02:00
variables . Set ( "Form" , form { 1 , "test" } )
return variables
2017-07-04 01:22:12 +02:00
} ,
2017-07-28 05:46:40 +02:00
"callback.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Callback" , true )
variables . Set ( "AccessToken" , "" )
variables . Set ( "RefreshToken" , "" )
variables . Set ( "Code" , "" )
return variables
} ,
"grant.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Client" , fakeClient )
variables . Set ( "Scopes" , [ ] string { } )
return variables
} ,
"refresh.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Refresh" , true )
variables . Set ( "Response" , "" )
return variables
} ,
"revoke.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Revoke" , true )
variables . Set ( "ResponseCode" , "" )
variables . Set ( "Response" , "" )
return variables
} ,
"clientlist.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . OauthClient { * fakeOauthModel , * fakeOauthModel , * fakeOauthModel } )
return variables
} ,
"oauth_client_form.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , fakeOauthForm )
return variables
} ,
2017-08-03 03:38:07 +02:00
"announcement_form.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Form" , fakeAnnouncement )
return variables
} ,
"announcements.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
variables . Set ( "Models" , [ ] models . Notification { * fakeNotification , * fakeNotification } )
return variables
} ,
2017-07-28 23:02:37 +02:00
"tag.jet.html" : func ( variables jet . VarMap ) jet . VarMap {
2017-09-03 02:30:30 +02:00
variables . Set ( "Form" , models . Tags { * fakeTag , * fakeTag , * fakeTag } )
2017-07-28 23:02:37 +02:00
return variables
} ,
2017-06-28 13:42:38 +02:00
}
fmt . Printf ( "\nTesting Folder: %s\n" , dir )
view := jet . NewHTMLSet ( path . Join ( ".." , TemplateDir ) )
files , err := ioutil . ReadDir ( path . Join ( ".." , TemplateDir ) + dir )
if err != nil {
t . Errorf ( "Couldn't find the folder %s" , path . Join ( ".." , TemplateDir ) + dir )
}
if len ( files ) == 0 {
t . Errorf ( "Couldn't find any files in folder %s" , path . Join ( ".." , TemplateDir ) + dir )
}
for _ , f := range files {
2017-07-16 00:38:07 +02:00
variables := mockupCommonvariables ( t )
2017-09-04 00:11:16 +02:00
if f . Name ( ) == "menu" {
continue
}
2017-06-28 13:42:38 +02:00
if f . IsDir ( ) {
walkDirTest ( dir + f . Name ( ) + "/" , t )
continue
}
if strings . Contains ( f . Name ( ) , ".jet.html" ) {
template , err := view . GetTemplate ( dir + f . Name ( ) )
fmt . Printf ( "\tJetTest Template of: %s" , dir + f . Name ( ) )
if err != nil {
t . Errorf ( "\nParsing error: %s %s" , err . Error ( ) , dir + f . Name ( ) )
Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor
First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.
Added new behaviour as discussed in #1334
* fix fallback to ES
* Added some comments to explain PG fallback + log err moved
* Refactored search
Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods
* 1rst Refactor of Tags (WTF already?!)
Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.
Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.
This behaviour depends on the callbackOnType function in tag/helpers.go
* fix for modtools :')
* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.
New Helper + New Changelog for translation string.
* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the link to the modal on torrent view.
More comments in the functions for tags
* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors
* Fix compile error + Tests Errors
* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings
TODO: test/fix adding tag on upload/edit
* Mini fix to display video quality
+ tags works/tested on modo edit
* Fix editing tags on modpanel
* Edit tags works
* Add translation string
* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd
* Fix Ajax tag Removal&Add
* Added form for descriptive tags
* Forgot to add the link between database and form for descriptive tags.
* Adding the increase/decrease pantsu for descriptive tags
* Fix #1370
* When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
fmt . Print ( "\tFAIL\n" )
continue
2017-06-28 13:42:38 +02:00
}
buff := bytes . NewBuffer ( nil )
2017-07-16 00:38:07 +02:00
if contextvariables [ f . Name ( ) ] != nil {
variables = contextvariables [ f . Name ( ) ] ( variables )
2017-06-28 13:42:38 +02:00
}
2017-07-16 00:38:07 +02:00
if err = template . Execute ( buff , variables , nil ) ; err != nil {
2017-06-28 13:42:38 +02:00
t . Errorf ( "\nEval error: %q executing %s" , err . Error ( ) , template . Name )
Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor
First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.
Added new behaviour as discussed in #1334
* fix fallback to ES
* Added some comments to explain PG fallback + log err moved
* Refactored search
Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods
* 1rst Refactor of Tags (WTF already?!)
Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.
Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.
This behaviour depends on the callbackOnType function in tag/helpers.go
* fix for modtools :')
* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.
New Helper + New Changelog for translation string.
* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the link to the modal on torrent view.
More comments in the functions for tags
* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors
* Fix compile error + Tests Errors
* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings
TODO: test/fix adding tag on upload/edit
* Mini fix to display video quality
+ tags works/tested on modo edit
* Fix editing tags on modpanel
* Edit tags works
* Add translation string
* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd
* Fix Ajax tag Removal&Add
* Added form for descriptive tags
* Forgot to add the link between database and form for descriptive tags.
* Adding the increase/decrease pantsu for descriptive tags
* Fix #1370
* When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
fmt . Print ( "\tFAIL\n" )
continue
2017-06-28 13:42:38 +02:00
}
fmt . Print ( "\tOK\n" )
}
}
}
2017-07-16 00:38:07 +02:00
func mockupCommonvariables ( t * testing . T ) jet . VarMap {
variables := jet . VarMap { }
2017-07-16 17:20:35 +02:00
variables . Set ( "Navigation" , NewNavigation ( ) )
variables . Set ( "Search" , SearchForm {
2017-06-28 13:42:38 +02:00
Category : "_" ,
ShowItemsPerPage : true ,
SizeType : "b" ,
2017-07-13 19:45:09 +02:00
DateType : "test" ,
MinSize : "test" ,
MaxSize : "test" ,
FromDate : "test" ,
ToDate : "test" ,
2017-06-28 13:42:38 +02:00
} )
2017-07-10 14:11:05 +02:00
conf := config . Get ( ) . I18n
2017-06-28 13:42:38 +02:00
conf . Directory = path . Join ( ".." , conf . Directory )
var retriever publicSettings . UserRetriever // not required during initialization
err := publicSettings . InitI18n ( conf , retriever )
if err != nil {
t . Errorf ( "failed to initialize language translations: %v" , err )
}
2017-07-13 19:45:09 +02:00
Ts , _ , err := publicSettings . TfuncAndLanguageWithFallback ( "en-us" , "test" , "test" )
2017-06-28 13:42:38 +02:00
if err != nil {
t . Error ( "Couldn't load language files!" )
}
var T publicSettings . TemplateTfunc
T = func ( id string , args ... interface { } ) template . HTML {
return template . HTML ( fmt . Sprintf ( Ts ( id ) , args ... ) )
}
2017-07-16 00:38:07 +02:00
variables . Set ( "T" , T )
variables . Set ( "Theme" , "test" )
2017-08-30 07:21:45 +02:00
variables . Set ( "AltColors" , "test" )
2017-07-16 00:38:07 +02:00
variables . Set ( "Mascot" , "test" )
variables . Set ( "MascotURL" , "test" )
variables . Set ( "User" , & models . User { } )
variables . Set ( "URL" , & url . URL { } )
variables . Set ( "CsrfToken" , "xxxxxx" )
2017-09-06 07:55:00 +02:00
variables . Set ( "EUCookieLaw" , false )
2017-07-16 00:38:07 +02:00
variables . Set ( "Config" , config . Get ( ) )
variables . Set ( "Infos" , make ( map [ string ] [ ] string ) )
variables . Set ( "Errors" , make ( map [ string ] [ ] string ) )
variables . Set ( "UserProfile" , & models . User { } )
variables = templateFunctions ( variables )
return variables
2017-06-28 13:42:38 +02:00
}