Commit 11006465 by Dudás Ádám

school: refactored group_show view

parent 93f6d382
from datetime import datetime from datetime import datetime
from itertools import chain
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -153,27 +154,24 @@ def language(request, lang): ...@@ -153,27 +154,24 @@ def language(request, lang):
def group_show(request, gid): def group_show(request, gid):
user = request.user user = request.user
group = get_object_or_404(Group, id=gid) group = get_object_or_404(Group, id=gid)
mytemplates = [
t for t in Template.objects.filter(owner=request.user).all()] mytemplates = Template.objects.filter(owner=request.user, state='READY')
noshare = True for t in mytemplates:
for i, t in enumerate(mytemplates):
t.myshares = t.share_set.filter(group=group) t.myshares = t.share_set.filter(group=group)
if t.myshares.exists():
noshare = False publictemplates = Template.objects.filter(public=True, state='READY')
mytemplates[i] = t for t in publictemplates:
publictemplates = [
t for t in Template.objects.filter(public=True, state='READY').all()]
for i, t in enumerate(publictemplates):
t.myshares = t.share_set.filter(group=group) t.myshares = t.share_set.filter(group=group)
if t.myshares.exists():
noshare = False all_templates = chain(mytemplates, publictemplates)
publictemplates[i] = t has_share = any([t.myshares.exists() for t in all_templates])
return render_to_response("show-group.html", RequestContext(request, { return render_to_response("show-group.html", RequestContext(request, {
'group': group, 'group': group,
'members': group.members.all(), 'members': group.members.all(),
'mytemplates': mytemplates, 'mytemplates': mytemplates,
'publictemplates': publictemplates, 'publictemplates': publictemplates,
'noshare': noshare, 'noshare': not has_share,
'userdetails': UserCloudDetails.objects.get(user=request.user), 'userdetails': UserCloudDetails.objects.get(user=request.user),
'owners': group.owners.all(), 'owners': group.owners.all(),
})) }))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment