def my(request,is_host): is_host = is_host == 'hosted' paginator = ExPaginator(Activity.objects.filter(members=request.user,memberhostship__is_host=is_host).annotate(Count('members')),8) try: page = int(request.GET.get('page')) except (ValueError, TypeError): page = 1 try: activities = paginator.page(page) except (EmptyPage, InvalidPage): activities = paginator.page(paginator.num_pages) return render_to_response('activities/my.html',locals(),context_instance=RequestContext(request))
def my(request): paginator = ExPaginator([membership.group for membership in MemberShip.objects.filter(user=request.user)], 10) try: page = int(request.GET.get("page", "1")) except ValueError: page = 1 try: groups = paginator.page(page) except (EmptyPage, InvalidPage): groups = paginator.page(paginator.num_pages) for group in groups.object_list: group.members_count = MemberShip.objects.filter(group=group).count() return render_to_response("groups/my.html", locals(), context_instance=RequestContext(request))
def admin(request, group_slug): group = get_object_or_404(Group, slug=group_slug) current_filter = request.GET.get("filter", "all") filters = {"unapproved": u"未审核", "single": u"组织活动", "multiple": u"合作活动", "all": u"全部活动"} if current_filter not in filters: current_filter = "all" current_filter_name = filters[current_filter] current_filter_query = u"&filter=" + current_filter if current_filter == "unapproved": hostships = HostShip.objects.filter(group=group, accepted=False) elif current_filter == "single": hostships = [ hostship for hostship in HostShip.objects.filter(group=group, accepted=True).annotate(Count("activity__host_groups")) if hostship.activity__host_groups__count == 1 ] elif current_filter == "multiple": hostships = [ hostship for hostship in HostShip.objects.filter(group=group, accepted=True).annotate(Count("activity__host_groups")) if hostship.activity__host_groups__count > 1 ] else: hostships = HostShip.objects.filter(group=group) friend_groups = group.friend_groups.all() friend_groups_pk = [friend_group.pk for friend_group in friend_groups] friend_groups_pk_str = ",".join([str(pk) for pk in friend_groups_pk]) + "," admins = [membership.user for membership in MemberShip.objects.filter(group=group, is_admin=1)] memberships = MemberShip.objects.filter(group=group).exclude(user=request.user).order_by("-joined_date")[0:4] is_founder = group.founder.pk == request.user.pk paginator = ExPaginator(hostships, 5) try: page = int(request.GET.get("page", "1")) except ValueError: page = 1 try: hostships = paginator.page(page) except (EmptyPage, InvalidPage): hostships = paginator.page(paginator.num_pages) if request.POST: form = AdminGroupForm(request.POST, instance=group) if form.is_valid(): form.save() new_friends = set(form.cleaned_data["friend_groups"]) for to_remove in set(friend_groups_pk) - new_friends: group.friend_groups.remove(Group.objects.get(id=to_remove)) for to_add in new_friends - set(friend_groups_pk): group.friend_groups.add(Group.objects.get(id=to_add)) else: form = AdminGroupForm(instance=group) return render_to_response("groups/admin.html", locals(), context_instance=RequestContext(request))
def members(request, group_slug): group = get_object_or_404(Group, slug=group_slug) friend_groups = group.friend_groups.all().order_by("?")[:8] paginator = ExPaginator( [membership.user for membership in MemberShip.objects.filter(group=group, is_admin=0, is_approved=True)], 10 ) admins = [membership.user for membership in MemberShip.objects.filter(group=group, is_admin=1)] try: page = int(request.GET.get("page", "1")) except ValueError: page = 1 try: members = paginator.page(page) except (EmptyPage, InvalidPage): members = paginator.page(paginator.num_pages) is_admin = request.user in admins return render_to_response("groups/members.html", locals(), context_instance=RequestContext(request))
def sort(request,by,token): hot_activities = Activity.objects.annotate(members_count=Count('members')).order_by('-members_count')[:4] if by == "type": activities = Activity.objects.filter(activity_type__id=token).annotate(Count('members')) activity_type = ActivityType.objects.get(id=token) elif by == "location": activities = Activity.objects.filter(location__id=token).annotate(Count('members')) location = Location.objects.get(id=token) else: return HttpResponseNotFound() paginator = ExPaginator(activities,8) try: page = int(request.GET.get('page')) except (ValueError, TypeError): page = 1 try: activities = paginator.page(page) except (EmptyPage, InvalidPage): activities = paginator.page(paginator.num_pages) return render_to_response('activities/sort.html',locals(),context_instance=RequestContext(request))
def frontpage(request): """docstring for group""" managed_groups = [membership.group for membership in MemberShip.objects.filter(user=request.user, is_admin=True)] managed_counter = len(managed_groups) joined_groups = [ membership.group for membership in MemberShip.objects.filter(user=request.user, is_admin=False, is_approved=True) ] joined_counter = len(joined_groups) paginator = ExPaginator(Group.objects.all().order_by("-create_date"), 5) try: page = int(request.GET.get("page")) except (ValueError, TypeError): page = 1 top_group, top_group_members, top_group_display = get_top_group() try: groups = paginator.page(page) except (EmptyPage, InvalidPage): groups = paginator.page(paginator.num_pages) for group in groups.object_list: group.members_count = MemberShip.objects.filter(group=group).count() return render_to_response("groups/frontpage.html", locals(), context_instance=RequestContext(request))