def topic(request, topic_id, group_slug=None, edit=False, template_name="topics/topic.html", bridge=None): topic = get_object_or_404(GroupTopic, id=topic_id) parent_group = topic.parent_group # XXX PERMISSIONS CHECK if not parent_group.is_visible( request.user) and not topic.creator == request.user: return render_to_response("topics/disallowed.html", { "topic": None, "group": parent_group, "member": None, "grpadmin": None, }, context_instance=RequestContext(request)) # XXX PERMISSIONS CHECK # only the owner of a topic or a group admin can edit a topic (??) if (request.method == "POST" and edit == True and \ topic.is_editable(request.user)): updated_body = request.POST.get('body', None) if updated_body is not None: topic.body = updated_body topic.save() return HttpResponseRedirect(topic.get_absolute_url()) # retrieve whiteboard (create if needed) if topic.whiteboard == None: # group_slug should always be valid - group never null! wb = Whiteboard(title="Post%d" % (topic.id), content="") if topic.group: topic.group.associate(wb, commit=False) wb.save() topic.whiteboard = wb topic.save() # update "featured posts" score topic.update_score(settings.FEATURED_VIEW_SCORE) # find membership status member = False if request.user.is_authenticated() and topic.group and ( topic.group.user_is_member(request.user) or topic.group.slug == "ewb"): member = True grpadmin = topic.group.user_is_admin(request.user) return render_to_response(template_name, { "topic": topic, "group": topic.group, "member": member, "grpadmin": grpadmin, }, context_instance=RequestContext(request))
def group_detail(request, group_slug, model=None, member_model=None, form_class=None, template_name=None, edit_template_name=None, options=None): """ View details of a group """ # how would we ever get here...??? (is this check redundant?) if model is None: # find group type and redirect group = get_object_or_404(BaseGroup, slug=group_slug) return HttpResponseRedirect(reverse("%s_detail" % group.model.lower(), kwargs={'group_slug': group_slug})) # keep this here to be RESTful (allow POST to object for editing) if request.method == 'POST': return edit_group(request, group_slug, model=model, member_model=member_model, form_class=form_class, template_name=edit_template_name, detail_template_name=template_name, options=options) # get group group = get_object_or_404(model, slug=group_slug) # membership status if group.user_is_member(request.user): member = group.members.get(user=request.user) elif group.user_is_pending_member(request.user): member = group.pending_members.get(user=request.user) else: member = None # retrieve whiteboard (create if needed) if group.whiteboard == None: wb = Whiteboard(title="Whiteboard", content="") group.associate(wb, commit=False) wb.save() group.whiteboard = wb group.save() # see if any admin tasks are outstanding # (should this only trigger for oustanding requets, instead of requests & invitations?) requests_outstanding = False if group.user_is_admin(request.user): if group.num_pending_members() > 0: requests_outstanding = True # render return render_to_response( template_name, { 'group': group, 'member': member, 'children': group.get_visible_children(request.user), 'is_admin': group.user_is_admin(request.user), 'requests_outstanding': requests_outstanding, 'joinform': GroupAddEmailForm(), 'limited_visibility': not group.is_visible(request.user) }, context_instance=RequestContext(request) )
def topic(request, topic_id, group_slug=None, edit=False, template_name="topics/topic.html", bridge=None): topic = get_object_or_404(GroupTopic, id=topic_id) parent_group = topic.parent_group # XXX PERMISSIONS CHECK if not parent_group.is_visible(request.user) and not topic.creator == request.user: return render_to_response("topics/disallowed.html", { "topic": None, "group": parent_group, "member": None, "grpadmin": None, }, context_instance=RequestContext(request)) # XXX PERMISSIONS CHECK # only the owner of a topic or a group admin can edit a topic (??) if (request.method == "POST" and edit == True and \ topic.is_editable(request.user)): updated_body = request.POST.get('body', None) if updated_body is not None: topic.body = updated_body topic.save() return HttpResponseRedirect(topic.get_absolute_url()) # retrieve whiteboard (create if needed) if topic.whiteboard == None: # group_slug should always be valid - group never null! wb = Whiteboard(title="Post%d" % (topic.id), content="") if topic.group: topic.group.associate(wb, commit=False) wb.save() topic.whiteboard = wb topic.save() # update "featured posts" score topic.update_score(settings.FEATURED_VIEW_SCORE) topic.view(request.user, request.META['REMOTE_ADDR']) # find membership status member = False if request.user.is_authenticated() and topic.group and (topic.group.user_is_member(request.user) or topic.group.slug == "ewb"): member = True grpadmin = topic.group.user_is_admin(request.user) return render_to_response(template_name, { "topic": topic, "group": topic.group, "member": member, "grpadmin": grpadmin, }, context_instance=RequestContext(request))
def detail(request, id, slug): event = get_object_or_404(Event, pk=id) parent = helpers.get_obj(ct=event.content_type, id=event.object_id) if not helpers.is_visible(request.user, parent): return render_to_response('denied.html', context_instance=RequestContext(request)) can_edit = False can_send = False member = False # see if the parent object is a descendant of BaseGroup if BaseGroup in parent.__class__.__bases__: can_edit = parent.user_is_admin(request.user) can_send = True # create whiteboard if needed if event.whiteboard == None: wb = Whiteboard(title="Event%d" % (event.id), content="") event.content_object.associate(wb, commit=False) wb.save() event.whiteboard = wb event.save() # we assume if you can see the event, you can edit it. Is this intentional? member = True elif parent.__class__ == User: if parent == request.user: can_edit = True #afk edit #TODO: confirm this #see if can find an champ info for this event, if so pass to template champ_info = ChampInfo.objects.get_by_event(event) or None return render_to_response("events/event_detail.html", { 'object': event, 'member': member, 'can_edit': can_edit, 'can_send': can_send, 'champ_info':champ_info, }, context_instance=RequestContext(request), )
def detail(request, id, slug): event = get_object_or_404(Event, pk=id) parent = helpers.get_obj(ct=event.content_type, id=event.object_id) if not helpers.is_visible(request.user, parent): return render_to_response('denied.html', context_instance=RequestContext(request)) can_edit = False can_send = False member = False # see if the parent object is a descendant of BaseGroup if BaseGroup in parent.__class__.__bases__: can_edit = parent.user_is_admin(request.user) can_send = True # create whiteboard if needed if event.whiteboard == None: wb = Whiteboard(title="Event%d" % (event.id), content="") event.content_object.associate(wb, commit=False) wb.save() event.whiteboard = wb event.save() # we assume if you can see the event, you can edit it. Is this intentional? member = True elif parent.__class__ == User: if parent == request.user: can_edit = True return render_to_response( "events/event_detail.html", { 'object': event, 'member': member, 'can_edit': can_edit, 'can_send': can_send }, context_instance=RequestContext(request), )
def group_detail(request, group_slug, model=None, member_model=None, form_class=None, template_name=None, edit_template_name=None, options=None): """ View details of a group """ # how would we ever get here...??? (is this check redundant?) if model is None: # find group type and redirect group = get_object_or_404(BaseGroup, slug=group_slug) return HttpResponseRedirect( reverse("%s_detail" % group.model.lower(), kwargs={'group_slug': group_slug})) # keep this here to be RESTful (allow POST to object for editing) if request.method == 'POST': return edit_group(request, group_slug, model=model, member_model=member_model, form_class=form_class, template_name=edit_template_name, detail_template_name=template_name, options=options) # get group group = get_object_or_404(model, slug=group_slug) # membership status if group.user_is_member(request.user): member = group.members.get(user=request.user) elif group.user_is_pending_member(request.user): member = group.pending_members.get(user=request.user) else: member = None # retrieve whiteboard (create if needed) if group.whiteboard == None: wb = Whiteboard(title="Whiteboard", content="") group.associate(wb, commit=False) wb.save() group.whiteboard = wb group.save() # see if any admin tasks are outstanding # (should this only trigger for oustanding requets, instead of requests & invitations?) requests_outstanding = False if group.user_is_admin(request.user): if group.num_pending_members() > 0: requests_outstanding = True # render return render_to_response( template_name, { 'group': group, 'member': member, 'children': group.get_visible_children(request.user), 'is_admin': group.user_is_admin(request.user), 'requests_outstanding': requests_outstanding, 'joinform': GroupAddEmailForm(), 'limited_visibility': not group.is_visible(request.user) }, context_instance=RequestContext(request))