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
13
OpenReviewCategoryForm , OpenReviewCommentForm , ProgramForm , LightningTalkForm
14
14
@@ -594,12 +594,37 @@ def is_proposal_opened(request):
594
594
return flag
595
595
596
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
+
597
622
class LightningTalkCreate (CreateView ):
598
623
form_class = LightningTalkForm
599
624
template_name = "pyconkr/lightning_talk_form.html"
600
625
601
626
def form_valid (self , form ):
602
- form .instance .user = self .request .user
627
+ form .instance .owner = self .request .user
603
628
form .save ()
604
629
return super (LightningTalkCreate , self ).form_valid (form )
605
630
@@ -610,14 +635,51 @@ def dispatch(self, request, *args, **kwargs):
610
635
if request .user .profile .name == '' :
611
636
return redirect ('profile_edit' )
612
637
613
- # 라톡이 열리지 않았을 때 redirect
614
- # if CFP_OPENED == -1:
615
- # return redirect("/2020/error/unopened")
616
- # elif CFP_OPENED == 1 and EDIT_AVAILABLE is False :
617
- # return redirect("/2020/error/closed/" )
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' )
618
643
619
644
return super (LightningTalkCreate , self ).dispatch (request , * args , ** kwargs )
620
645
621
646
def get_success_url (self ):
622
- new_cfp_registered (self .request .META ['HTTP_ORIGIN' ], self .object .id , self .object .title )
623
- return reverse ('proposal-list' )
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