def post(self, request, *args, **kwargs): form = InvitationForm(request.POST) if not form.is_valid(): return HttpResponseForbidden( _("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 HttpResponseForbidden( _("This user already a member of this community.")) if Invitation.objects.filter(community=self.community, email=form.instance.email).exists(): return HttpResponseForbidden( _("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})
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})
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})
def post(self, request, *args, **kwargs): form = InvitationForm(request.POST) #TODO: check if user or invitation already exists if not form.is_valid(): assert False form.instance.community = self.community form.instance.created_by = request.user i = form.save() # TODO: send mail return render(request, 'users/_invitation.html', {'object': i})
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})
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})