def dispatch(self, request, *args, **kwargs): self.room_name = kwargs['room'] try: room = ROOM_DICT[self.room_name] except KeyError: return HttpResponseNotFound('Invalid room specified in url') label = self.request.GET.get('participant_label', '') if room.has_participant_labels(): if label: missing_label = False invalid_label = label not in room.get_participant_labels() else: missing_label = True invalid_label = False # needs to be easy to re-enter label, in case we are in kiosk # mode if missing_label or invalid_label and not room.use_secure_urls: return render_to_response("otree/RoomInputLabel.html", {'invalid_label': invalid_label}) if room.use_secure_urls: hash = self.request.GET.get('hash') if hash != make_hash(label): return HttpResponseNotFound( 'Invalid hash parameter. use_secure_urls is True, ' 'so you must use the participant-specific URL.') session = room.get_session() if session is None: self.tab_unique_id = otree.common_internal.random_chars_10() self._socket_url = channel_utils.room_participant_path( self.room_name, label, # random chars in case the participant has multiple tabs open self.tab_unique_id) return render_to_response( "otree/WaitPageRoom.html", { 'view': self, 'title_text': _('Please wait'), 'body_text': _('Waiting for your session to begin') }) if label: cookies = None else: cookies = request.session # 2017-08-02: changing the behavior so that even in a room without # participant_label_file, 2 requests for the same start URL with same label # will return the same participant. Not sure if the previous behavior # (assigning to 2 different participants) was intentional or bug. return participant_start_page_or_404(session, label=label, cookies=cookies)
def setUp(self): self.participant_label = LABEL_REAL room_name = settings.ROOM_WITH_LABELS_NAME self.room_name = room_name self.tab_unique_id = '12123123' self.path = channel_utils.room_participant_path( room_name, self.participant_label, self.tab_unique_id) self.admin_path = channel_utils.room_admin_path(room_name) self.participant_client = ConnectingWSClient(self.path) self.admin_client = ConnectingWSClient(self.admin_path)
def setUp(self): self.participant_label = LABEL_REAL room_name = settings.ROOM_WITH_LABELS_NAME self.room_name = room_name self.tab_unique_id = '12123123' self.path = channel_utils.room_participant_path( room_name, self.participant_label, self.tab_unique_id) self.admin_path = channel_utils.room_admin_path(room_name) self.participant_client = ConnectingWSClient(self.path) self.admin_client = ConnectingWSClient(self.admin_path)
def dispatch(self, request, *args, **kwargs): self.room_name = kwargs['room'] try: room = ROOM_DICT[self.room_name] except KeyError: return HttpResponseNotFound('Invalid room specified in url') label = self.request.GET.get( 'participant_label', '' ) if room.has_participant_labels(): if not label: if not room.use_secure_urls: return render_to_response("otree/RoomInputLabel.html") if not label in room.get_participant_labels(): return HttpResponseNotFound( _('Invalid participant label.') ) if room.use_secure_urls: hash = self.request.GET.get('hash') if hash != make_hash(label): return HttpResponseNotFound('Invalid hash parameter.') session = room.session if session is None: self.tab_unique_id = otree.common_internal.random_chars_10() self._socket_url = channel_utils.room_participant_path( self.room_name, label, # random chars in case the participant has multiple tabs open self.tab_unique_id ) return render_to_response( "otree/WaitPageRoom.html", { 'view': self, 'title_text': _('Please wait'), 'body_text': _('Waiting for your session to begin') } ) if label: cookies = None else: cookies = request.session # 2017-08-02: changing the behavior so that even in a room without # participant_label_file, 2 requests for the same start URL with same label # will return the same participant. Not sure if the previous behavior # (assigning to 2 different participants) was intentional or bug. return participant_start_page_or_404(session, label=label, cookies=cookies)
def dispatch(self, request, room): self.room_name = room try: room = ROOM_DICT[self.room_name] except KeyError: return HttpResponseNotFound('Invalid room specified in url') label = self.request.GET.get('participant_label', '') if room.has_participant_labels(): if label: missing_label = False invalid_label = label not in room.get_participant_labels() else: missing_label = True invalid_label = False # needs to be easy to re-enter label, in case we are in kiosk # mode if missing_label or invalid_label and not room.use_secure_urls: return render( request, "otree/RoomInputLabel.html", {'invalid_label': invalid_label}, ) if room.use_secure_urls: hash = self.request.GET.get('hash') if hash != make_hash(label): return HttpResponseNotFound( 'Invalid hash parameter. use_secure_urls is True, ' 'so you must use the participant-specific URL.') session = room.get_session() if session is None: self.tab_unique_id = otree.common.random_chars_10() self._socket_url = channel_utils.room_participant_path( room_name=self.room_name, participant_label=label, # random chars in case the participant has multiple tabs open tab_unique_id=self.tab_unique_id, ) return render( request, "otree/WaitPageRoom.html", { 'view': self, 'title_text': _('Please wait'), 'body_text': _('Waiting for your session to begin'), }, ) if label: cookies = None else: cookies = request.session # 2017-08-02: changing the behavior so that even in a room without # participant_label_file, 2 requests for the same start URL with same label # will return the same participant. Not sure if the previous behavior # (assigning to 2 different participants) was intentional or bug. participant = participant_start_page_or_404(session, label=label, cookies=cookies) if label: # whether the room has participant labels or not passed_vars = ParticipantVarsFromREST.objects.filter( room_name=self.room_name, participant_label=label).first() if passed_vars: participant.vars.update(passed_vars.vars) participant.save() passed_vars.delete() return HttpResponseRedirect(participant._start_url())
def get(self, request: Request): room_name = request.path_params['room_name'] self.room_name = room_name try: room = ROOM_DICT[self.room_name] except KeyError: return Response('Invalid room specified in url', status_code=404) label = request.query_params.get('participant_label', '') if room.has_participant_labels: if label: missing_label = False invalid_label = label not in room.get_participant_labels() else: missing_label = True invalid_label = False # needs to be easy to re-enter label, in case we are in kiosk # mode if missing_label or invalid_label and not room.use_secure_urls: return render( "otree/RoomInputLabel.html", {'invalid_label': invalid_label}, ) if room.use_secure_urls: hash = request.query_params.get('hash') if hash != make_hash(label): return Response( 'Invalid hash parameter. use_secure_urls is True, ' 'so you must use the participant-specific URL.', status_code=404, ) session = room.get_session() if session is None: self.tab_unique_id = otree.common.random_chars_10() self._socket_url = channel_utils.room_participant_path( room_name=self.room_name, participant_label=label, # random chars in case the participant has multiple tabs open tab_unique_id=self.tab_unique_id, ) return render( "otree/WaitPageRoom.html", dict( view=self, title_text=_('Please wait'), body_text=_('Waiting for your session to begin'), http_request=request, ), ) if label: cookies = None else: cookies = request.session # 2017-08-02: changing the behavior so that even in a room without # participant_label_file, 2 requests for the same start URL with same label # will return the same participant. Not sure if the previous behavior # (assigning to 2 different participants) was intentional or bug. participant = participant_or_none_if_exceeded(session, label=label, cookies=cookies) if not participant: return no_participants_left_http_response() if label: # whether the room has participant labels or not passed_vars = ParticipantVarsFromREST.objects_filter( room_name=self.room_name, participant_label=label).first() if passed_vars: participant.vars.update(passed_vars.vars) db.delete(passed_vars) return RedirectResponse(participant._start_url())