Ejemplo n.º 1
0
    def get_participant_urls(self, request):
        participant_urls = []
        room_base_url = request.url_for('AssignVisitorToRoom',
                                        room_name=self.name)

        for label in self.get_participant_labels():
            params = {'participant_label': label}
            if self.use_secure_urls:
                params['hash'] = make_hash(label)
            participant_url = add_params_to_url(room_base_url, params)
            participant_urls.append(participant_url)

        return participant_urls
Ejemplo n.º 2
0
    def get_participant_urls(self, request):
        participant_urls = []
        room_base_url = reverse('AssignVisitorToRoom', args=(self.name, ))
        room_base_url = request.build_absolute_uri(room_base_url)

        if self.has_participant_labels():
            for label in self.get_participant_labels():
                params = {'participant_label': label}
                if self.use_secure_urls:
                    params['hash'] = make_hash(label)
                participant_url = add_params_to_url(room_base_url, params)
                participant_urls.append(participant_url)

        return participant_urls
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
    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())