Exemplo n.º 1
0
 def dispatch(self, request, *args, **kwargs):
     if not OperationScheme.can_new_register():
         return render(request, 'accounts/cannot_register.html',
                       context={'user': request.user})
     elif request.user.is_authenticated:
         return HttpResponse('왜 이미 로그인까지 하신분이 또 신입가입을 시도하십니까? 개발자를 괴롭히기 위함인가요?')
     else:
         # https://stackoverflow.com/questions/5433172/how-to-redirect-on-conditions-with-class-based-views-in-django-1-3
         return super(UserCreateView, self).dispatch(request, *args, **kwargs)
Exemplo n.º 2
0
def survey_fill_new(request, user_id):
    if request.method == 'GET':
        try:
            # 가장 최근의 신입양식을 보여줌
            form = Form.objects.filter(purpose='join_new', opened=True)[0]
            questions = Question.objects.filter(form=form).order_by('id')
            choices = Choice.objects.filter(
                question__in=questions).order_by('id')
        # 신입 가입을 위한 양식이 없는 경우 예외처리
        except (ObjectDoesNotExist, IndexError):
            form = None
            questions = ''
            choices = ''
        context = {
            'user_id': user_id,
            'form': form,
            'questions': questions,
            'choices': choices,
            'can_old_register': OperationScheme.can_old_register(),
            'can_new_register': OperationScheme.can_new_register()
        }
        return render(request, 'surveys/survey_fill_new.html', context)
    elif request.method == 'POST':
        # 설문 완료 표시
        user = User.objects.get(id=user_id)
        user.survey_done = True
        user.save()
        form = Form.objects.filter(purpose='join_new', opened=True)[0]
        form.users.add(user)
        form.save()
        questions = Question.objects.filter(form=form)
        # choice_many의 경우 여러 응답을 표시
        for question in questions:
            if question.question_type == 'choice_many':
                all_answer = request.POST.getlist(question.question_text)
                answer = ''
                for text in all_answer:
                    answer += text + ','
                answer = answer[:-1]
            else:
                answer = request.POST.get(question.question_text)
            UserAnswer.objects.create(question=question,
                                      answer=answer,
                                      form=form,
                                      user=user)
        info = OperationScheme.latest()
        context = {
            'purpose': form.purpose,
            'bank': info.get_bank_display(),
            'account': info.bank_account,
            'boss_name': info.boss.name,
            'new_pay': info.new_pay,
            'old_pay': info.old_pay
        }
        return render(request, 'surveys/survey_fill_submit.html', context)
Exemplo n.º 3
0
def survey_fill(request, user_id, pk):
    if request.method == 'GET':
        form = Form.objects.get(id=pk)
        questions = Question.objects.filter(form=form).order_by('id')
        choices = Choice.objects.filter(question__in=questions).order_by('id')
        context = {
            'form': form,
            'questions': questions,
            'choices': choices,
            'can_old_register': OperationScheme.can_old_register(),
            'can_new_register': OperationScheme.can_new_register()
        }
        return render(request, 'surveys/survey_fill.html', context)
    elif request.method == 'POST':
        user = User.objects.get(id=user_id)
        form = Form.objects.get(id=pk)
        questions = Question.objects.filter(form=form)
        for question in questions:
            if question.question_type == 'choice_many':
                all_answer = request.POST.getlist(question.question_text)
                answer = ''
                for text in all_answer:
                    answer += text + ','
                answer = answer[:-1]
            else:
                answer = request.POST.get(question.question_text)
            UserAnswer.objects.create(question=question,
                                      answer=answer,
                                      form=form,
                                      user=user)
        form.users.add(user)
        form.save()
        info = OperationScheme.latest()
        context = {
            'purpose': form.purpose,
            'bank': info.get_bank_display(),
            'account': info.bank_account,
            'boss_name': info.boss.name,
            'new_pay': info.new_pay,
            'old_pay': info.old_pay
        }
        return render(request, 'surveys/survey_fill_submit.html', context)