示例#1
0
def register_invitee(request, group_slug, key):
    object = get_object_or_404(CTGroup, slug=group_slug)
    invitation = get_object_or_404(Invitation, accept_key=key)
    if invitation.is_accepted or invitation.group != object:
        raise Http404

    if request.method == "POST":

        if request.POST["result"] == _("Cancel"):
            return HttpResponseRedirect("/")
        #     redirect to group

        form = RegistrationWithName(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data["username"], form.cleaned_data["email"], form.cleaned_data["password1"]
            )
            user.first_name = form.cleaned_data["first_name"]
            user.last_name = form.cleaned_data["last_name"]
            user.save()
            memb = GroupMembership(user=user, group=object)
            memb.save()
            invitation.accept(user)
            user = authenticate(username=user.username, password=form.cleaned_data["password1"])
            login(request, user)

            return HttpResponseRedirect(reverse("group", kwargs={"group_slug": group_slug}))

    else:
        # a GET, so make form
        form = RegistrationWithName(initial={"email": invitation.email})

    return render_to_response("ct_groups/register_invitee.html", RequestContext(request, {"form": form}))
示例#2
0
 def _make_membership(self, user, group, is_active=True, is_editor=False, updates='single'):
     """docstring for _make_membership"""
     member = GroupMembership(user=user, group=group)
     member.is_active = is_active
     member.is_editor = is_editor
     member.post_updates = updates
     member.tool_updates = updates
     member.save()
     return member
示例#3
0
def join(request, object_id):
    group = get_object_or_404(CTGroup, pk=object_id)
    u = request.user
    form = memb = None

    try:
        memb = GroupMembership.objects.get(user=u, group=group)
    except GroupMembership.DoesNotExist:

        # moderate_membership = 'open', 'mod', 'closed'
        if not group.is_closed:
            mod = None
            if group.moderate_membership == "mod":

                if request.method == "POST":
                    if request.POST["result"] == _("Cancel"):
                        return HttpResponseRedirect(reverse("group", kwargs={"group_slug": group.slug}))
                    form = GroupJoinForm(request.POST)
                    if form.is_valid():
                        mod = Moderation(status="pending", applicants_text=form.cleaned_data["reason_for_joining"])
                        mod.save()
                        memb = GroupMembership(user=u, group=group, moderation=mod)
                        memb.save()
                        group_notify(mod, True)
                        return HttpResponseRedirect(reverse("join-group", kwargs={"object_id": group.id}))

                    # else, reshow form
                    else:
                        mod = None
                else:
                    # a GET, so make form
                    form = GroupJoinForm()
            else:
                memb = GroupMembership(user=u, group=group, moderation=mod)
                memb.save()

    return render_to_response(
        "ct_groups/ct_groups_confirm_join.html", RequestContext(request, {"group": group, "memb": memb, "form": form})
    )