11 from django.shortcuts import get_object_or_404, render_to_response |
11 from django.shortcuts import get_object_or_404, render_to_response |
12 from django.template import RequestContext |
12 from django.template import RequestContext |
13 from django.template.loader import render_to_string |
13 from django.template.loader import render_to_string |
14 from django.utils import feedgenerator |
14 from django.utils import feedgenerator |
15 from django.utils.translation import ugettext as _ |
15 from django.utils.translation import ugettext as _ |
16 from cm.security import user_has_perm # import here! |
|
17 |
16 |
18 import re |
17 import re |
19 import time |
18 import time |
20 |
19 |
21 @login_required |
20 @login_required |
70 |
69 |
71 def text_notifications(request, key): |
70 def text_notifications(request, key): |
72 text = get_text_by_keys_or_404(key) |
71 text = get_text_by_keys_or_404(key) |
73 user = request.user if request.user.is_authenticated() else None |
72 user = request.user if request.user.is_authenticated() else None |
74 |
73 |
75 anonymous_can_view_text = False |
74 from cm.security import user_has_perm # import here! |
76 anonymous_user_role = UserRole.objects.get(user=None, text=text) |
75 anonymous_can_view_text = user_has_perm(None, 'can_view_text', text=text) |
77 if anonymous_user_role : |
|
78 anonymous_can_view_text = user_has_perm(anonymous_user_role.user, 'can_view_text', text=text) |
|
79 own_check = Notification.objects.filter(text=text,type='own',user=user).count() |
76 own_check = Notification.objects.filter(text=text,type='own',user=user).count() |
80 all_check = Notification.objects.filter(text=text,type=None,user=user).count() |
77 all_check = Notification.objects.filter(text=text,type=None,user=user).count() |
|
78 |
|
79 |
|
80 embed_code = '<iframe frameborder="0" src="%s%s" style="height: 166px; width: 99.9%%; position: relative; top: 0px;">'%(settings.SITE_URL, reverse('text-view-comments-frame', args=[text.key])) |
|
81 |
81 if request.method == 'POST': |
82 if request.method == 'POST': |
82 if 'activate' in request.POST: |
83 if 'activate' in request.POST: |
83 text.private_feed_key = generate_key() |
84 text.private_feed_key = generate_key() |
84 text.save() |
85 text.save() |
85 display_message(request, _(u"Private feed activated.")) |
86 display_message(request, _(u"Private feed activated.")) |
96 notification = Notification.objects.filter(text=text, type=None, user=user).delete() |
97 notification = Notification.objects.filter(text=text, type=None, user=user).delete() |
97 |
98 |
98 template_dict = { |
99 template_dict = { |
99 'text' : text, |
100 'text' : text, |
100 'all_check' : all_check, |
101 'all_check' : all_check, |
101 'anonymous_can_view_text' : anonymous_can_view_text |
102 'anonymous_can_view_text' : anonymous_can_view_text, |
|
103 'embed_code': embed_code |
102 } |
104 } |
103 return render_to_response('site/text_notifications.html', template_dict , context_instance=RequestContext(request)) |
105 return render_to_response('site/text_notifications.html', template_dict , context_instance=RequestContext(request)) |