2012-07-12 04:38:24 +00:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2012-10-12 04:48:48 +00:00
|
|
|
from django.http import Http404
|
2012-07-12 04:38:24 +00:00
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
|
|
|
|
|
|
|
from django.contrib import messages
|
2017-03-26 00:50:10 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2012-10-12 04:48:48 +00:00
|
|
|
from django.contrib.auth.models import User
|
2015-06-26 03:46:09 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2012-07-12 04:38:24 +00:00
|
|
|
|
|
|
|
from symposion.proposals.models import ProposalBase
|
2012-10-12 04:48:48 +00:00
|
|
|
from symposion.speakers.forms import SpeakerForm
|
2012-07-12 04:38:24 +00:00
|
|
|
from symposion.speakers.models import Speaker
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def speaker_create(request):
|
|
|
|
try:
|
|
|
|
return redirect(request.user.speaker_profile)
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-07-12 04:38:24 +00:00
|
|
|
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)
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-07-12 04:38:24 +00:00
|
|
|
if form.is_valid():
|
|
|
|
speaker = form.save(commit=False)
|
|
|
|
speaker.user = request.user
|
|
|
|
if not found:
|
|
|
|
speaker.invite_email = None
|
|
|
|
speaker.save()
|
2015-06-26 03:46:09 +00:00
|
|
|
messages.success(request, _("Speaker profile created."))
|
2012-07-12 04:38:24 +00:00
|
|
|
return redirect("dashboard")
|
|
|
|
else:
|
2012-10-12 04:48:48 +00:00
|
|
|
form = SpeakerForm(initial={"name": request.user.get_full_name()})
|
2015-10-16 17:36:58 +00:00
|
|
|
return render(request, "symposion/speakers/speaker_create.html", {
|
|
|
|
"speaker_form": form,
|
2012-10-12 04:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2012-10-25 03:59:30 +00:00
|
|
|
def speaker_create_staff(request, pk):
|
|
|
|
user = get_object_or_404(User, pk=pk)
|
2012-10-12 04:48:48 +00:00
|
|
|
if not request.user.is_staff:
|
|
|
|
raise Http404
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-10-12 04:48:48 +00:00
|
|
|
try:
|
|
|
|
return redirect(user.speaker_profile)
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-10-12 04:48:48 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
form = SpeakerForm(request.POST, request.FILES)
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-10-12 04:48:48 +00:00
|
|
|
if form.is_valid():
|
|
|
|
speaker = form.save(commit=False)
|
|
|
|
speaker.user = user
|
|
|
|
speaker.save()
|
2015-06-26 03:46:09 +00:00
|
|
|
messages.success(request, _("Speaker profile created."))
|
2012-10-12 04:48:48 +00:00
|
|
|
return redirect("user_list")
|
|
|
|
else:
|
|
|
|
form = SpeakerForm(initial={"name": user.get_full_name()})
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2015-10-16 17:36:58 +00:00
|
|
|
return render(request, "symposion/speakers/speaker_create.html", {
|
|
|
|
"speaker_form": form,
|
2012-07-12 04:38:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def speaker_create_token(request, token):
|
|
|
|
speaker = get_object_or_404(Speaker, invite_token=token)
|
|
|
|
request.session["pending-token"] = token
|
|
|
|
if request.user.is_authenticated():
|
|
|
|
# check for speaker profile
|
|
|
|
try:
|
|
|
|
existing_speaker = request.user.speaker_profile
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
del request.session["pending-token"]
|
|
|
|
additional_speakers = ProposalBase.additional_speakers.through
|
|
|
|
additional_speakers._default_manager.filter(
|
2012-10-12 04:48:48 +00:00
|
|
|
speaker=speaker
|
2012-07-12 04:38:24 +00:00
|
|
|
).update(
|
2012-10-12 04:48:48 +00:00
|
|
|
speaker=existing_speaker
|
2012-07-12 04:38:24 +00:00
|
|
|
)
|
2015-06-26 03:46:09 +00:00
|
|
|
messages.info(request, _("You have been associated with all pending "
|
|
|
|
"talk proposals"))
|
2012-07-12 04:38:24 +00:00
|
|
|
return redirect("dashboard")
|
|
|
|
else:
|
|
|
|
if not request.user.is_authenticated():
|
|
|
|
return redirect("account_login")
|
|
|
|
return redirect("speaker_create")
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def speaker_edit(request, pk=None):
|
|
|
|
if pk is None:
|
|
|
|
try:
|
|
|
|
speaker = request.user.speaker_profile
|
|
|
|
except Speaker.DoesNotExist:
|
|
|
|
return redirect("speaker_create")
|
|
|
|
else:
|
2012-10-12 02:41:45 +00:00
|
|
|
if request.user.is_staff:
|
2012-07-12 04:38:24 +00:00
|
|
|
speaker = get_object_or_404(Speaker, pk=pk)
|
|
|
|
else:
|
|
|
|
raise Http404()
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2012-07-12 04:38:24 +00:00
|
|
|
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)
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2015-10-16 17:36:58 +00:00
|
|
|
return render(request, "symposion/speakers/speaker_edit.html", {
|
|
|
|
"speaker_form": form,
|
2012-07-12 04:38:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2012-10-12 03:55:49 +00:00
|
|
|
def speaker_profile(request, pk):
|
2012-07-12 04:38:24 +00:00
|
|
|
speaker = get_object_or_404(Speaker, pk=pk)
|
2012-12-20 06:51:52 +00:00
|
|
|
presentations = speaker.all_presentations
|
|
|
|
if not presentations and not request.user.is_staff:
|
2012-07-12 04:38:24 +00:00
|
|
|
raise Http404()
|
2014-07-30 18:19:26 +00:00
|
|
|
|
2015-10-16 17:36:58 +00:00
|
|
|
return render(request, "symposion/speakers/speaker_profile.html", {
|
2012-07-12 04:38:24 +00:00
|
|
|
"speaker": speaker,
|
2012-12-20 06:51:52 +00:00
|
|
|
"presentations": presentations,
|
2012-10-12 03:55:49 +00:00
|
|
|
})
|