Beispiel #1
0
    def post(self, request, *args, **kwargs):
        try:
            participant = request.user.participant
        except Participant.DoesNotExist:
            participant = Participant(user=request.user)
            participant.save()

        session_id = kwargs.get('id', None)
        unconf = kwargs.get('unconf', None)
        value = request.POST.get('value', None)

        if session_id and value:
            vote, created = Vote.objects.get_or_create(
                participant=participant,
                session_id=session_id
            )
            vote.value = value
            vote.save()

        session = Session.objects.get(unconference__slug=unconf, pk=session_id)
        response_data = dict(
            vote_width=session.vote_width(),
            session_id=session.pk
        )

        # no response data is necessary
        return HttpResponse(json.dumps(response_data), content_type="application/json")
Beispiel #2
0
class UpdateParticipantView(UpdateView):
    form_class = CreateParticipantForm
    # user_form_class = UserChangeForm
    template_name = "participant/form.html"

    @method_decorator(login_required(login_url='/users/login'))
    def get(self, request, *args, **kwargs):
        return super(UpdateParticipantView, self).get(request, *args, **kwargs)

    @method_decorator(login_required(login_url='/users/login'))
    def post(self, request, *args, **kwargs):
        form = self.form_class(request.POST, instance=self.get_object())
        # user_form = self.user_form_class(request.POST)

        if form.is_valid():  # and user_form.is_valid():
            form.save()
            # user_form.save()
            messages.info(request, 'User information updated successfully.')
            return HttpResponseRedirect(self.get_success_url())
        else:
            context = self.get_context_data(*args, **kwargs)
            context['form'] = form
            return self.render_to_response(context)

    def get_success_url(self):
        success_url = self.request.POST.get(
            'next', '/'
        )
        return success_url

    def get_object(self, queryset=None):
        try:
            self.object = self.request.user.participant
        except Participant.DoesNotExist:
            self.object = Participant(user=self.request.user)
            self.object.save()

        return self.object

    def get_context_data(self, *args, **kwargs):
        context = super(UpdateParticipantView, self).get_context_data(
            *args, **kwargs
        )
        context['unconf'] = kwargs.get('unconf', None)
        context['next'] = self.request.GET.get(
            'next', '/'
        )
        # if 'user_form' not in context:
        #    context['user_form'] = UserChangeForm(instance=self.request.user)
        return context
Beispiel #3
0
    def get_object(self, queryset=None):
        try:
            self.object = self.request.user.participant
        except Participant.DoesNotExist:
            self.object = Participant(user=self.request.user)
            self.object.save()

        return self.object