25
25
"""
26
26
27
27
# Flask
28
- from werkzeug import LocalProxy
29
- from flask import render_template , request , flash , redirect , url_for , \
30
- jsonify , Blueprint
31
- from invenio . base . i18n import _
32
- from invenio . base . decorators import wash_arguments , templated
28
+ from flask import Blueprint , flash , jsonify , redirect , \
29
+ render_template , request , url_for
30
+
31
+ from flask_breadcrumbs import default_breadcrumb_root , register_breadcrumb
32
+
33
33
from flask_login import current_user , login_required
34
- from invenio .base .globals import cfg
35
34
36
- # External imports
35
+ from flask_menu import register_menu
36
+
37
+ from invenio .base .decorators import templated , wash_arguments
38
+ from invenio .base .globals import cfg
39
+ from invenio .base .i18n import _
40
+ from invenio .ext .sqlalchemy import db
37
41
from invenio .modules .accounts .models import User
38
42
from invenio .modules .records .models import Record as Bibrec
39
43
from invenio .modules .search .models import Collection
40
44
from invenio .modules .search .views .search import response_formated_records
41
- from flask_menu import register_menu
42
- from flask_breadcrumbs import default_breadcrumb_root , register_breadcrumb
43
- from invenio .ext .sqlalchemy import db
44
45
45
- # Internal imports
46
- from .models import \
47
- WtgTAG , \
48
- WtgTAGRecord , \
49
- wash_tag
46
+ from werkzeug import LocalProxy
50
47
48
+ # Internal imports
51
49
# Forms
52
50
from .forms import \
53
- CreateTagForm , \
54
51
AttachTagForm , \
52
+ CreateTagForm , \
55
53
DetachTagForm , \
56
54
EditTagForm , \
57
55
TagAnnotationForm , \
58
56
validate_tag_exists , \
59
57
validate_user_owns_tag , \
60
58
validators
61
59
60
+ from .models import \
61
+ WtgTAG , \
62
+ WtgTAGRecord , \
63
+ wash_tag
64
+
62
65
# Uset settings
63
- user_settings = LocalProxy (lambda :
64
- current_user ['settings' ].get ('webtag' , cfg ['CFG_WEBTAG_DEFAULT_USER_SETTINGS' ]))
66
+ user_settings = LocalProxy (
67
+
68
+ lambda : current_user ['settings' ].get ('webtag' , cfg ['CFG_WEBTAG_DEFAULT_USER_SETTINGS' ]))
65
69
66
70
blueprint = Blueprint ('webtag' , __name__ , url_prefix = '/yourtags' ,
67
71
template_folder = 'templates' , static_folder = 'static' )
@@ -100,8 +104,8 @@ def display_cloud():
100
104
101
105
for tag in tags :
102
106
size = min_size + \
103
- float (max_size - min_size ) * \
104
- float (tag .record_count - min_count ) / difference
107
+ float (max_size - min_size ) * \
108
+ float (tag .record_count - min_count ) / difference
105
109
106
110
tag .css_size = str (size * 100 )
107
111
@@ -113,7 +117,7 @@ def display_cloud():
113
117
@login_required
114
118
@templated ('tags/display_list.html' )
115
119
@wash_arguments ({'sort_by' : (unicode , 'name' ),
116
- 'order' : (unicode , '' )})
120
+ 'order' : (unicode , '' )})
117
121
@register_breadcrumb (blueprint , '.list' , _ ('Display as List' ))
118
122
def display_list (sort_by , order ):
119
123
""" List of user's private/group/public tags """
@@ -161,8 +165,8 @@ def tag_details(id_tag):
161
165
return redirect (url_for ('.display_cloud' ))
162
166
163
167
return response_formated_records ([bibrec .id for bibrec in tag .records ],
164
- Collection .query .get (1 ),
165
- 'hb' )
168
+ Collection .query .get (1 ),
169
+ 'hb' )
166
170
167
171
168
172
@blueprint .route ('/tag/<int:id_tag>/edit' , methods = ['GET' , 'POST' ])
@@ -241,10 +245,8 @@ def record_tags(id_bibrec):
241
245
from .template_context_functions .tfn_webtag_record_tags \
242
246
import template_context_function
243
247
244
- from invenio .ext .template import render_template_to_string
245
-
246
248
return dict (
247
- tag_list = template_context_function (id_bibrec , current_user .get_id ()))
249
+ tag_list = template_context_function (id_bibrec , current_user .get_id ()))
248
250
249
251
250
252
@blueprint .route ('/tokenize/<int:id_bibrec>' , methods = ['GET' , 'POST' ])
@@ -315,7 +317,7 @@ def editor(id_bibrec):
315
317
# invenio_templated cannot be used,
316
318
# because this view is requested using AJAX
317
319
return render_template ('tags/record_editor.html' , id_bibrec = id_bibrec ,
318
- record_tags = tags_json )
320
+ record_tags = tags_json )
319
321
320
322
321
323
#Temporary solution to call validators, we need a better one
@@ -460,8 +462,8 @@ def detach():
460
462
461
463
if form .validate ():
462
464
association = db .session .query (WtgTAGRecord )\
463
- .filter_by (id_tag = form .data ['id_tag' ],
464
- id_bibrec = form .data ['id_bibrec' ]).first ()
465
+ .filter_by (id_tag = form .data ['id_tag' ],
466
+ id_bibrec = form .data ['id_bibrec' ]).first ()
465
467
if association :
466
468
db .session .delete (association )
467
469
db .session .commit ()
0 commit comments