def speaker_create_staff(request, pk): user = get_object_or_404(User, pk=pk) if not request.user.is_staff: raise Http404 try: return redirect(user.speaker_profile) except ObjectDoesNotExist: pass if request.method == "POST": form = SpeakerForm(request.POST, request.FILES) if form.is_valid(): speaker = form.save(commit=False) speaker.user = user speaker.save() messages.success(request, _("Speaker profile created.")) return redirect("user_list") else: form = SpeakerForm(initial={"name": user.get_full_name()}) return render( request, "symposion/speakers/speaker_create.html", {"speaker_form": form}, )
def speaker_create(request): try: return redirect(request.user.speaker_profile) except ObjectDoesNotExist: pass if request.method == "POST": try: speaker = Speaker.objects.get(invite_email=request.user.email) found = True except Speaker.DoesNotExist: speaker = None found = False form = SpeakerForm(request.POST, request.FILES, instance=speaker) if form.is_valid(): speaker = form.save(commit=False) speaker.user = request.user if not found: speaker.invite_email = None speaker.save() messages.success(request, "Speaker profile created.") return redirect("speaker_dashboard") else: form = SpeakerForm() ctx = { "form": form, } ctx = RequestContext(request, ctx) return render_to_response("speakers/speaker_create.html", ctx)
def speaker_create(request): try: return redirect(request.user.speaker_profile) except ObjectDoesNotExist: pass if request.method == "POST": try: speaker = Speaker.objects.get(invite_email=request.user.email) found = True except Speaker.DoesNotExist: speaker = None found = False form = SpeakerForm(request.POST, request.FILES, instance=speaker) if form.is_valid(): speaker = form.save(commit=False) speaker.user = request.user if not found: speaker.invite_email = "" speaker.save() messages.success(request, _("Speaker profile created.")) return redirect("dashboard") else: form = SpeakerForm(initial={"name": request.user.get_full_name()}) return render( request, "symposion/speakers/speaker_create.html", {"speaker_form": form}, )
def speaker_edit(request, pk=None): if pk is None: try: speaker = request.user.speaker_profile except Speaker.DoesNotExist: return redirect("speaker_create") else: if request.user.groups.filter(name="organizer").exists(): speaker = get_object_or_404(Speaker, pk=pk) else: raise Http404() if request.method == "POST": form = SpeakerForm(request.POST, request.FILES, instance=speaker) if form.is_valid(): form.save() speaker_admin_url = 'http://%s/2012/admin/speakers/speaker/%d/' % (request.get_host(), speaker.pk) content = "%s updated his profile.\n\n %s" % (speaker.name, speaker_admin_url) send_mail('[PyCon] Speaker profile updated', content, settings.DEFAULT_FROM_EMAIL, [settings.CONTACT_EMAIL]) messages.success(request, "Speaker profile updated.") return redirect("speaker_dashboard") else: form = SpeakerForm(instance=speaker) ctx = { "form": form, } ctx = RequestContext(request, ctx) return render_to_response("speakers/speaker_edit.html", ctx)
def speaker_edit(request, pk=None): if pk is None: try: speaker = request.user.speaker_profile except Speaker.DoesNotExist: return redirect("speaker_create") else: if request.user.is_staff: speaker = get_object_or_404(Speaker, pk=pk) else: raise Http404() if request.method == "POST": form = SpeakerForm(request.POST, request.FILES, instance=speaker) if form.is_valid(): form.save() messages.success(request, "Speaker profile updated.") return redirect("dashboard") else: form = SpeakerForm(instance=speaker) return render(request, "symposion/speakers/speaker_edit.html", {"speaker_form": form})
def speaker_edit(request, pk=None): if pk is None: try: speaker = request.user.speaker_profile except Speaker.DoesNotExist: return redirect("speaker_create") else: if request.user.groups.filter(name="organizer").exists(): speaker = get_object_or_404(Speaker, pk=pk) else: raise Http404() if request.method == "POST": form = SpeakerForm(request.POST, request.FILES, instance=speaker) if form.is_valid(): form.save() messages.success(request, "Speaker profile updated.") return redirect("speaker_dashboard") else: form = SpeakerForm(instance=speaker) ctx = { "form": form, } ctx = RequestContext(request, ctx) return render_to_response("speakers/speaker_edit.html", ctx)
def test_nonascii_name(self): name = '\u0141ukasz Langa' png_file = StringIO.StringIO() # Use PIL Image to create new png and pdf files Image.new('RGB', size=(50, 50), color=(256, 0, 0)).save(png_file, 'png') png_file.seek(0) # Django-friendly ContentFiles file = SimpleUploadedFile(name + '.png', png_file.read()) form = SpeakerForm( data={ 'name': name, 'biography': name, '': None, 'twitter_username': '', }, files={'photo': file}, ) self.assertTrue(form.is_valid(), msg=form.errors) form.save()
def speaker_create_token(request, token): speaker = get_object_or_404(Speaker, invite_token=token) if request.user.is_authenticated(): # check for speaker profile try: existing_speaker = request.user.speaker_profile except ObjectDoesNotExist: pass else: additional_speakers = Proposal.additional_speakers.through additional_speakers._default_manager.filter( speaker=speaker).update(speaker=existing_speaker) messages.info( request, "You have been associated with all pending " "talk proposals") return redirect("speaker_dashboard") if request.method == "POST": if "login" in request.POST: login_form = LoginForm(request.POST) if login_form.is_valid(): login_form.login(request) return redirect("speaker_create_token", token) else: signup_form = SignupForm( initial={"email": speaker.invite_email}, prefix="signup") speaker_form = None elif "signup" in request.POST: login_form = None forms = [] if not request.user.is_authenticated(): login_form = None signup_form = SignupForm(request.POST, prefix="signup") forms.append(signup_form) speaker_form = SpeakerForm(request.POST, request.FILES, prefix="speaker", instance=speaker) forms.append(speaker_form) if all([f.is_valid() for f in forms]): if not request.user.is_authenticated(): user = signup_form.save(speaker, request=request) else: user = request.user speaker = speaker_form.save(commit=False) speaker.user = user speaker.save() if not request.user.is_authenticated(): if user.email != speaker.invite_email: ctx = { "email": user.email, "success_url": "/", } ctx = RequestContext(request, ctx) return render_to_response( "account/verification_sent.html", ctx) else: signup_form.login(request, user) return redirect("speaker_dashboard") else: raise Exception("wtf?") else: if not request.user.is_authenticated(): login_form = LoginForm() signup_form = SignupForm(initial={"email": speaker.invite_email}, prefix="signup") else: login_form, signup_form = None, None speaker_form = SpeakerForm(prefix="speaker") ctx = { "login_form": login_form, "signup_form": signup_form, "speaker_form": speaker_form, } ctx = RequestContext(request, ctx) return render_to_response("speakers/speaker_create_token.html", ctx)