def proposals_state(): slug = settings.CONFERENCE_DEFAULT_SLUG state = ProposalsState( proposals_creatable=reg.get(f'{slug}.proposals.creatable', False), proposals_editable=reg.get(f'{slug}.proposals.editable', False), proposals_withdrawable=reg.get(f'{slug}.proposals.withdrawable', False), ) # proposals.disable.after has a high priority if it is set disable_after = None try: disable_after_raw = reg.get(f'{slug}.proposals.disable.after', None) disable_after = datetime.strptime(disable_after_raw, '%Y-%m-%d %H:%M:%S%z') if timezone.now() >= disable_after: state = ProposalsState( proposals_creatable=False, proposals_editable=False, proposals_withdrawable=False, ) except (ValueError, TypeError): pass return state
def reviews_state(): slug = settings.CONFERENCE_DEFAULT_SLUG # return { # 'reviews_stage': reg.get(f'{slug}.reviews.stage', 0), # 'reviews_public': reg.get(f'{slug}.reviews.visible.to.submitters', False), # } return ReviewsState( reviews_stage=reg.get(f'{slug}.reviews.stage', 0), reviews_public=reg.get(f'{slug}.reviews.visible.to.submitters', False), reviews_enough=reg.get(f'{slug}.reviews.enough', 10), )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) rooms = OrderedDict() rooms['R1'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r1', '') rooms['R2'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r2', '') rooms['R3'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r3', '') context['rooms'] = rooms context['token'] = self.token return context
def filter_current_reviews( self, proposal, exclude_user=None, filter_user=None): qs = self.filter(proposal=proposal) stage = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.reviews.stage', 0) if stage: qs = qs.filter(stage__lte=stage) if exclude_user: qs = qs.exclude(reviewer=exclude_user) if filter_user: qs = qs.filter(reviewer=filter_user) return qs
def make_snapshots(self, dataset_iter): current_stage = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.reviews.stage', 0) for dataset in dataset_iter: pk = dataset['pk'] field_data = { k: v for k, v in dataset['fields'].items() if k != 'submitter' } dumped_json = json.dumps(field_data, cls=DjangoJSONEncoder) TalkProposalSnapshot.objects.update_or_create( proposal_id=pk, stage=current_stage, defaults={'dumped_json': dumped_json}, )
def live(request): token = request.GET.get('token', '') if not token_re.match(token): raise Http404 attendee = None try: attendee = Attendee.objects.get(token=token) except Attendee.DoesNotExist: attendee = Attendee.objects.create(token=token) rooms = OrderedDict() rooms['R1'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r1', '') rooms['R2'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r2', '') rooms['R3'] = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.live.r3', '') return render(request, 'ext/live.html', { 'attendee': attendee, 'rooms': rooms, 'token': token, })
def post(self, request): self.token = request.data['token'] try: Attendee.objects.get(token=self.token) slug = settings.CONFERENCE_DEFAULT_SLUG key_prefix = f"{slug}.live" reg_room_keys = [ key for key in reg if str(key).startswith(key_prefix) ] response_data = {"youtube_infos": []} for idx, room in enumerate(reg_room_keys): response_data["youtube_infos"].append({ "room": f"R{idx+1}", "video_id": reg.get(f'{room}', '') }) return Response(response_data, status=status.HTTP_200_OK) except Attendee.DoesNotExist: response_data = {"status": "Attendee Dose Not Exist"} return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): self.token = request.data.get('token') try: Attendee.objects.get(token=self.token) key_prefix = f"{settings.CONFERENCE_DEFAULT_SLUG}.live." reg_live_infos = [] for key in reg: if not str(key).startswith(key_prefix): continue room_name = str(key)[len(key_prefix):] video_id = reg.get(key, '') reg_live_infos.append({ "room": room_name, "video_id": video_id, }) response_data = {"youtube_infos": sorted(reg_live_infos, key=lambda x: x.get("room"))} return Response(response_data, status=status.HTTP_200_OK) except Attendee.DoesNotExist: response_data = {"status": "Attendee Dose Not Exist"} return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
def can_edit(self): return reg.get( f'{settings.CONFERENCE_DEFAULT_SLUG}.proposals.withdrawable', False)
def dispatch(self, request, *args, **kwargs): if not reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.proposals.creatable', False): raise Http404 return super().dispatch(request, *args, **kwargs)
def save(self, *args, **kwargs): if self.stage is None: self.stage = reg.get(f'{settings.CONFERENCE_DEFAULT_SLUG}.reviews.stage', 0) return super().save(*args, **kwargs)