src/cm/views/texts.py
changeset 42 82f6e2879e0a
parent 38 be1807d390d4
child 56 bd8a4ffc7dad
equal deleted inserted replaced
41:7d258f14cd7b 42:82f6e2879e0a
   801     return render_to_response('site/wysiwyg_preview.html', {'content':html_content} , context_instance=RequestContext(request))
   801     return render_to_response('site/wysiwyg_preview.html', {'content':html_content} , context_instance=RequestContext(request))
   802         #return HttpResponse(pandoc_convert(content, format, "html", full=False))
   802         #return HttpResponse(pandoc_convert(content, format, "html", full=False))
   803 
   803 
   804 @has_perm_on_text('can_manage_text')
   804 @has_perm_on_text('can_manage_text')
   805 def text_share(request, key):
   805 def text_share(request, key):
       
   806     display_suspended_users = get_int(request.GET, 'display', 0)
       
   807     tag_selected = request.GET.get('tag_selected', 0)
       
   808     
   806     text = get_text_by_keys_or_404(key)
   809     text = get_text_by_keys_or_404(key)
   807     order_by = get_among(request.GET,'order',('user__username',
   810     order_by = get_among(request.GET,'order',('user__username',
   808                                               'user__email',
   811                                               'user__email',
   809                                               '-user__username',
   812                                               '-user__username',
   810                                               '-user__email',
   813                                               '-user__email',
   843                'anon_role' : anon_role,
   846                'anon_role' : anon_role,
   844                'global_anon_role' : global_anon_role,
   847                'global_anon_role' : global_anon_role,
   845                'all_roles' : Role.objects.all(),
   848                'all_roles' : Role.objects.all(),
   846                'anon_roles' : Role.objects.filter(anon = True),
   849                'anon_roles' : Role.objects.filter(anon = True),
   847                'text' : text,
   850                'text' : text,
       
   851                'display_suspended_users' : display_suspended_users,
       
   852                'tag_list' : Tag.objects.usage_for_model(UserProfile),
       
   853                'tag_selected': tag_selected,               
   848                }
   854                }
   849 
   855 
   850     return object_list(request, UserRole.objects.filter(text=text).filter(~Q(user=None)).order_by(order_by),
   856     query = UserRole.objects.filter(text=text).filter(~Q(user=None)).order_by(order_by)
       
   857     if not display_suspended_users:
       
   858         query = query.exclude(Q(user__userprofile__is_suspended=True) & Q(user__is_active=True))
       
   859     else:
       
   860         # trick to include userprofile table anyway (to filter by tags)
       
   861         query = query.filter(Q(user__userprofile__is_suspended=True) | Q(user__userprofile__is_suspended=False))
       
   862 
       
   863     if tag_selected:     
       
   864         tag_ids = Tag.objects.filter(name=tag_selected)
       
   865         if tag_ids:   
       
   866             content_type_id = ContentType.objects.get_for_model(UserProfile).pk
       
   867             query = query.extra(where=['tagging_taggeditem.object_id = cm_userprofile.id', 
       
   868                                        'tagging_taggeditem.content_type_id = %i' %content_type_id,
       
   869                                        'tagging_taggeditem.tag_id = %i' %tag_ids[0].id],
       
   870                                 tables=['tagging_taggeditem'],
       
   871                                 )
       
   872 
       
   873     return object_list(request, query,
   851                        template_name = 'site/text_share.html',
   874                        template_name = 'site/text_share.html',
   852                        paginate_by = paginate_by,
   875                        paginate_by = paginate_by,
   853                        extra_context = context,
   876                        extra_context = context,
   854                        )
   877                        )
   855     
   878