|
8 | 8 | from django.views.generic.edit import ModelFormMixin
|
9 | 9 |
|
10 | 10 | from .models import Program, ProgramCategory, Preference, Speaker, Room, Proposal, OpenReview, \
|
11 |
| - TutorialProposal, SprintProposal |
| 11 | + TutorialProposal, SprintProposal, LightningTalk |
12 | 12 | from .forms import SpeakerForm, SprintProposalForm, TutorialProposalForm, ProposalForm, \
|
13 |
| - OpenReviewCategoryForm, OpenReviewCommentForm, ProgramForm |
| 13 | + OpenReviewCategoryForm, OpenReviewCommentForm, ProgramForm, LightningTalkForm |
14 | 14 |
|
15 | 15 | import constance
|
16 | 16 | import datetime
|
@@ -592,3 +592,94 @@ def is_proposal_opened(request):
|
592 | 592 | flag = 1
|
593 | 593 |
|
594 | 594 | return flag
|
| 595 | + |
| 596 | + |
| 597 | +def is_lightning_talk_proposable(request): |
| 598 | + KST = datetime.timezone(datetime.timedelta(hours=9)) |
| 599 | + now = datetime.datetime.now(tz=KST) |
| 600 | + LT_open_at = constance.config.LIGHTNING_TALK_OPEN.replace(tzinfo=KST) |
| 601 | + LT_close_at = constance.config.LIGHTNING_TALK_CLOSE.replace(tzinfo=KST) |
| 602 | + if LT_open_at < now < LT_close_at: |
| 603 | + return True |
| 604 | + else: |
| 605 | + return False |
| 606 | + |
| 607 | + |
| 608 | +class LightningTalkHome(TemplateView): |
| 609 | + template_name = "pyconkr/lightning_talk_home.html" |
| 610 | + |
| 611 | + def get_context_data(self, **kwargs): |
| 612 | + context = super().get_context_data(**kwargs) |
| 613 | + |
| 614 | + KST = datetime.timezone(datetime.timedelta(hours=9)) |
| 615 | + context['LT_open_at'] = constance.config.LIGHTNING_TALK_OPEN.replace(tzinfo=KST) |
| 616 | + context['LT_close_at'] = constance.config.LIGHTNING_TALK_CLOSE.replace(tzinfo=KST) |
| 617 | + context['is_proposable'] = is_lightning_talk_proposable(self.request) |
| 618 | + |
| 619 | + return context |
| 620 | + |
| 621 | + |
| 622 | +class LightningTalkCreate(CreateView): |
| 623 | + form_class = LightningTalkForm |
| 624 | + template_name = "pyconkr/lightning_talk_form.html" |
| 625 | + |
| 626 | + def form_valid(self, form): |
| 627 | + form.instance.owner = self.request.user |
| 628 | + form.save() |
| 629 | + return super(LightningTalkCreate, self).form_valid(form) |
| 630 | + |
| 631 | + def get(self, request, *args, **kwargs): |
| 632 | + return super(LightningTalkCreate, self).get(request, *args, **kwargs) |
| 633 | + |
| 634 | + def dispatch(self, request, *args, **kwargs): |
| 635 | + if request.user.profile.name == '': |
| 636 | + return redirect('profile_edit') |
| 637 | + |
| 638 | + if not is_lightning_talk_proposable(self.request): |
| 639 | + return redirect('lightning-talk') |
| 640 | + |
| 641 | + if LightningTalk.objects.filter(owner=self.request.user).exists(): |
| 642 | + return redirect('lightning-talk-detail') |
| 643 | + |
| 644 | + return super(LightningTalkCreate, self).dispatch(request, *args, **kwargs) |
| 645 | + |
| 646 | + def get_success_url(self): |
| 647 | + return reverse('lightning-talk-detail') |
| 648 | + |
| 649 | + |
| 650 | +class LightningTalkDetail(TemplateView): |
| 651 | + template_name = "pyconkr/lightning_talk_detail.html" |
| 652 | + |
| 653 | + def dispatch(self, request, *args, **kwargs): |
| 654 | + if not LightningTalk.objects.filter(owner=self.request.user).exists(): |
| 655 | + return redirect('lightning-talk') |
| 656 | + return super(LightningTalkDetail, self).dispatch(request, *args, **kwargs) |
| 657 | + |
| 658 | + def get_context_data(self, **kwargs): |
| 659 | + context = super(LightningTalkDetail, self).get_context_data(**kwargs) |
| 660 | + context['title'] = _("Lightning Talk Proposal") |
| 661 | + context['talk'] = LightningTalk.objects.get(owner=self.request.user) |
| 662 | + context['is_editable'] = is_lightning_talk_proposable(self.request) |
| 663 | + return context |
| 664 | + |
| 665 | + |
| 666 | +class LightningTalkUpdate(UpdateView): |
| 667 | + model = LightningTalk |
| 668 | + form_class = LightningTalkForm |
| 669 | + template_name = "pyconkr/lightning_talk_form.html" |
| 670 | + |
| 671 | + def dispatch(self, request, *args, **kwargs): |
| 672 | + if not LightningTalk.objects.filter(owner=self.request.user).exists() or not is_lightning_talk_proposable( |
| 673 | + self.request): |
| 674 | + return redirect('lightning-talk') |
| 675 | + if LightningTalk.objects.get(id=self.kwargs['pk']).owner != self.request.user: |
| 676 | + return redirect('lightning-talk') |
| 677 | + |
| 678 | + return super(LightningTalkUpdate, self).dispatch(request, *args, **kwargs) |
| 679 | + |
| 680 | + def get_context_data(self, **kwargs): |
| 681 | + context = super(LightningTalkUpdate, self).get_context_data(**kwargs) |
| 682 | + return context |
| 683 | + |
| 684 | + def get_success_url(self): |
| 685 | + return reverse('lightning-talk-detail') |
0 commit comments