def profile(request, group_slug, member_form=None, leader_form=None): prof = get_object_or_404(GroupProfile, slug=group_slug) leaders = prof.leaders.all().select_related('profile') members_list = prof.group.user_set.all().select_related('profile') paginator = Paginator(members_list, 30) page = request.GET.get('page') try: members = paginator.page(page) except PageNotAnInteger: members = paginator.page(1) except EmptyPage: members = paginator.page(paginator.num_pages) is_paginated = paginator.num_pages > 1 user_can_edit = _user_can_edit(request.user, prof) user_can_manage_leaders = _user_can_manage_leaders(request.user, prof) return render( request, 'groups/profile.html', { 'profile': prof, 'leaders': leaders, 'members': members, 'user_can_edit': user_can_edit, 'user_can_manage_leaders': user_can_manage_leaders, 'is_paginated': is_paginated, 'member_form': member_form or AddUserForm(), 'leader_form': leader_form or AddUserForm() })
def profile(request, group_slug, member_form=None, leader_form=None): prof = get_object_or_404(GroupProfile, slug=group_slug) leaders = prof.leaders.all().select_related("profile") members_list = prof.group.user_set.all().select_related("profile") paginator = Paginator(members_list, 30) page = request.GET.get("page") try: members = paginator.page(page) except PageNotAnInteger: members = paginator.page(1) except EmptyPage: members = paginator.page(paginator.num_pages) is_paginated = paginator.num_pages > 1 user_can_edit = _user_can_edit(request.user, prof) user_can_manage_leaders = _user_can_manage_leaders(request.user, prof) return render( request, "groups/profile.html", { "profile": prof, "leaders": leaders, "members": members, "user_can_edit": user_can_edit, "user_can_manage_leaders": user_can_manage_leaders, "is_paginated": is_paginated, "member_form": member_form or AddUserForm(), "leader_form": leader_form or AddUserForm(), }, )
def locale_details(request, locale_code, leader_form=None, reviewer_form=None, editor_form=None): """Show the locale details page.""" locale = get_object_or_404(Locale, locale=locale_code) leaders = locale.leaders.all().select_related('profile') reviewers = locale.reviewers.all().select_related('profile') editors = locale.editors.all().select_related('profile') active = active_contributors(from_date=date.today() - timedelta(days=90), locale=locale_code) user_can_edit = _user_can_edit(request.user, locale) return render( request, 'wiki/locale_details.html', { 'locale': locale, 'leaders': leaders, 'reviewers': reviewers, 'editors': editors, 'active': active, 'user_can_edit': user_can_edit, 'leader_form': leader_form or AddUserForm(), 'reviewer_form': reviewer_form or AddUserForm(), 'editor_form': editor_form or AddUserForm() })
def locale_details(request, locale_code, leader_form=None, reviewer_form=None, editor_form=None): """Show the locale details page.""" locale = get_object_or_404(Locale, locale=locale_code) leaders = locale.leaders.all().select_related("profile") reviewers = locale.reviewers.all().select_related("profile") editors = locale.editors.all().select_related("profile") active = active_contributors(from_date=date.today() - timedelta(days=90), locale=locale_code) user_can_edit = _user_can_edit(request.user, locale) return render( request, "wiki/locale_details.html", { "locale": locale, "leaders": leaders, "reviewers": reviewers, "editors": editors, "active": active, "user_can_edit": user_can_edit, "leader_form": leader_form or AddUserForm(), "reviewer_form": reviewer_form or AddUserForm(), "editor_form": editor_form or AddUserForm(), }, )
def add_member(request, group_slug): """Add a member to the group.""" prof = get_object_or_404(GroupProfile, slug=group_slug) if not _user_can_edit(request.user, prof): raise PermissionDenied form = AddUserForm(request.POST) if form.is_valid(): for user in form.cleaned_data['users']: user.groups.add(prof.group) msg = _('{users} added to the group successfully!').format( users=request.POST.get('users')) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(prof.get_absolute_url()) msg = _('There were errors adding members to the group, see below.') messages.add_message(request, messages.ERROR, msg) return profile(request, group_slug, member_form=form)
def add_member(request, group_slug): """Add a member to the group.""" prof = get_object_or_404(GroupProfile, slug=group_slug) if not _user_can_edit(request.user, prof): raise PermissionDenied form = AddUserForm(request.POST) if form.is_valid(): for user in form.cleaned_data['users']: user.groups.add(prof.group) msg = _('{users} added to the group successfully!').format( users=request.POST.get('users')) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(prof.get_absolute_url()) msg = _('There were errors adding members to the group, see below.') messages.add_message(request, messages.ERROR, msg) return profile(request, group_slug, member_form=form)
def add_to_locale(request, locale_code, role): """Add a user to the locale role.""" locale = get_object_or_404(Locale, locale=locale_code) if not _user_can_edit(request.user, locale): raise PermissionDenied form = AddUserForm(request.POST) if form.is_valid(): for user in form.cleaned_data['users']: getattr(locale, ROLE_ATTRS[role]).add(user) msg = _('{users} added successfully!').format( users=request.POST.get('users')) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(locale.get_absolute_url()) msg = _('There were errors adding users, see below.') messages.add_message(request, messages.ERROR, msg) return locale_details(request, locale_code, **{role + '_form': form})
def add_to_locale(request, locale_code, role): """Add a user to the locale role.""" locale = get_object_or_404(Locale, locale=locale_code) if not _user_can_edit(request.user, locale): raise PermissionDenied form = AddUserForm(request.POST) if form.is_valid(): for user in form.cleaned_data['users']: getattr(locale, ROLE_ATTRS[role]).add(user) msg = _('{users} added successfully!').format( users=request.POST.get('users')) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(locale.get_absolute_url()) msg = _('There were errors adding users, see below.') messages.add_message(request, messages.ERROR, msg) return locale_details(request, locale_code, **{role + '_form': form})
def add_leader(request, group_slug): """Add a leader to the group.""" prof = get_object_or_404(GroupProfile, slug=group_slug) if not _user_can_manage_leaders(request.user, prof): raise PermissionDenied form = AddUserForm(request.POST) if form.is_valid(): for user in form.cleaned_data["users"]: if prof.group not in user.groups.all(): # If user isn't a member of group, add to members user.groups.add(prof.group) prof.leaders.add(user) msg = _("{users} added to the group leaders successfully!").format( users=request.POST.get("users")) messages.add_message(request, messages.SUCCESS, msg) return HttpResponseRedirect(prof.get_absolute_url()) msg = _("There were errors adding leaders to the group, see below.") messages.add_message(request, messages.ERROR, msg) return profile(request, group_slug, leader_form=form)