コード例 #1
0
    def post(self, request, *args, **kwargs):

        form = InvitationForm(request.POST)

        if not form.is_valid():
            return HttpResponseBadRequest(
                _("Form error. Please supply a valid email."))

        # somewhat of a privacy problem next line. should probably fail silently
        if Membership.objects.filter(community=self.community,
                                     user__email=form.instance.email).exists():
            return HttpResponseBadRequest(
                _("This user already a member of this community."))

        if Invitation.objects.filter(community=self.community,
                                     email=form.instance.email).exists():
            return HttpResponseBadRequest(
                _("This user is already invited to this community."))

        form.instance.community = self.community
        form.instance.created_by = request.user

        i = form.save()

        i.send()

        return render(request, 'users/_invitation.html', {'object': i})
コード例 #2
0
def view_invite(request, invite_template):
    if request.method == 'GET':
        return response(request, invite_template, {'form':InvitationForm()})
    userprofile = loggedin_userprofile(request)
    form = InvitationForm(post_data(request))
    if form.is_valid():
        try:
            invitation_emailer(from_email=userprofile.user.email,
                               to_emails=form.cleaned_data.get('to_emails'),
                               from_name=userprofile.name)
            from users.messages import CONTACTED_SUCCESSFULLY
            messages.success(request, CONTACTED_SUCCESSFULLY)
            return HttpResponseRedirect(redirect_to='/')
        except Exception:
            from users.messages import CONTACTING_FAILED
            messages.error(request, CONTACTING_FAILED)
    return response(request, invite_template, {'form':form})
コード例 #3
0
    def get_context_data(self, **kwargs):
        d = super(MembershipList, self).get_context_data(**kwargs)

        d['invites'] = Invitation.objects.filter(community=self.community)
        d['form'] = InvitationForm(
            initial={
                'message':
                Invitation.DEFAULT_MESSAGE % self.community.get_board_name()
            })

        return d
コード例 #4
0
    def get_context_data(self, **kwargs):
        d = super(MembershipList, self).get_context_data(**kwargs)

        d['invites'] = Invitation.objects.filter(community=self.community)
        d['form'] = InvitationForm(
            initial={'message': Invitation.DEFAULT_MESSAGE % _('The board')})
        d['members_list'] = Membership.objects.filter(community=self.community)
        # d['board_list'] = Membership.objects.board().filter(community=self.community)
        # d['member_list'] = Membership.objects.none_board().filter(community=self.community)
        # d['board_name'] = self.community.board_name

        return d
コード例 #5
0
    def post(self, request, *args, **kwargs):

        form = InvitationForm(request.POST)

        if not form.is_valid():
            return HttpResponseBadRequest(
                _("Form error. Please supply a valid email."))

        v_err = self.validate_invitation(form.instance.email)
        if v_err:
            return v_err

        form.instance.community = self.community
        form.instance.created_by = request.user

        i = form.save()
        i.send(sender=request.user, recipient_name=form.cleaned_data['name'])

        return render(request, 'users/_invitation.html', {'object': i})