コード例 #1
0
ファイル: mixins.py プロジェクト: AliLordLoss/WSS-site
 def get_context_data(self, **kwargs):
     context = super().get_context_data()
     context['past_years'] = [
         q[0] for q in WSS.objects.exclude(
             pk=WSS.active_wss().pk).values_list('year')
     ]
     context['external_links'] = ExternalLink.objects.all()
     return context
コード例 #2
0
ファイル: views.py プロジェクト: AliLordLoss/WSS-site
def verify(request, year, email, payment_id):
    logger.info("participant with email:" + email + "and payment_id: " + payment_id + " starting to verify.")

    footer = {
        'past_years': [q[0] for q in
                       WSS.objects.exclude(pk=WSS.active_wss().pk).values_list('year')],
        'external_links': ExternalLink.objects.all()
    }
    try:
        exh = Participant.objects.all().get(email=email, payment_id=payment_id)
    except Participant.DoesNotExist:
        return render(request, 'info.html',
                      {'past_years': footer['past_years'], 'external_links': footer['external_links'],
                       'wss': get_object_or_404(WSS, year=year), 'status': 'danger',
                       'info': 'Payment was not successful. Please contact support.'})  # todo  move to error page

    price = compute_cost(exh)

    if request.GET.get('Status') == 'OK':
        result = client.service.PaymentVerification(MERCHANT, request.GET['Authority'], price)
        if result.Status == 100:

            exh.payment_status = 'OK'
            exh.save()

            if exh.participate_in_wss:
                gr = Grade.objects.all().get(level=exh.grade)
                gr.capacity -= 1
                gr.save()

            for i in exh.workshops.all():
                exh.paid_workshops.add(i.id)
                i.capacity -= 1
                i.save()

            exh.paid_amount += price
            exh.save()
            logger.info("participant with email:" + email + " verified successfully.")
            return render(request, 'info.html',
                          {'past_years': footer['past_years'], 'external_links': footer['external_links'],
                           'wss': get_object_or_404(WSS, year=year),
                           'status': 'success',
                           'info': 'You have registered successfully. Your tracking code is:' + str(
                               result.RefID)})  # todo  move to error page
        elif result.Status == 101:
            logger.info(
                "participant with email:" + email + " verified again. perhaps he attacking us.")  # todo redirect to tekrari

            return HttpResponse('Transaction submitted : ' + str(result.Status))
        else:
            logger.info("participant with email:" + email + " don't verified")
            return HttpResponse('Transaction failed.\nStatus: ' + str(result.Status))  # todo redirect to error page
    else:
        logger.info("participant with email:" + email + " don't verified")
        return render(request, 'info.html',
                      {'past_years': footer['past_years'], 'external_links': footer['external_links'],
                       'wss': get_object_or_404(WSS, year=year), 'status': 'danger',
                       'info': 'Payment was not successful.'})  # todo  move to error page
コード例 #3
0
ファイル: views.py プロジェクト: AliLordLoss/WSS-site
 def get_object(self, queryset=None):
     return get_object_or_404(WSS, year=WSS.active_wss().year)
コード例 #4
0
ファイル: views.py プロジェクト: AliLordLoss/WSS-site
def send_request(request, year):
    if not get_object_or_404(WSS, year=int(year)).registration_open:
        footer = {
            'past_years': [q[0] for q in
                           WSS.objects.exclude(pk=WSS.active_wss().pk).values_list('year')],
            'external_links': ExternalLink.objects.all()
        }
        return render(request, 'info.html',
                      {'past_years': footer['past_years'], 'external_links': footer['external_links'],
                       'wss': get_object_or_404(WSS, year=year), 'status': 'danger',
                       'info': 'Sorry, the registration has been ended.'})

    form = ParticipantForm(request.POST, initial={'year': year})
    if not form.is_valid():
        return render(request, 'WSS/register.html', {'wss': get_object_or_404(WSS, year=year), 'form': form,
                                                     'error': "Please correct the following errors."})

    # Captcha validation
    recaptcha_response = request.POST.get('g-recaptcha-response')
    data = {
        'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
        'response': recaptcha_response
    }
    r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data)
    result = r.json()
    if not result['success']:
        return render(request, 'WSS/register.html', {'wss': get_object_or_404(WSS, year=year), 'form': form,
                                                     'error': "Captcha is invalid; Please try again."})

    CallbackURL = 'https://wss.ce.sharif.edu/' + str(
        year) + '/verify/'  # todo Important: need to edit for realy server.

    current_wss = get_object_or_404(WSS, year=year)
    name = form.cleaned_data['name']
    family = form.cleaned_data['family']
    name_eng = form.cleaned_data['name_english']
    family_eng = form.cleaned_data['family_english']

    email = form.cleaned_data['email']
    age = form.cleaned_data['age']
    grade = form.cleaned_data['grade']
    phone_number = form.cleaned_data['phone_number']
    job = form.cleaned_data['job']
    national_id = form.cleaned_data['national_id']
    university = form.cleaned_data['university']
    introduction_method = form.cleaned_data['introduction_method']
    gender = form.cleaned_data['gender']
    city = form.cleaned_data['city']
    country = form.cleaned_data['country']
    question = form.cleaned_data['question']
    participate_in_wss = form.cleaned_data['participate_in_wss']
    workshops = []
    full_workshops = []
    for i in form.cleaned_data['workshops']:
        workshops.append(i.id)
        if i.capacity <= 0:
            full_workshops.append(i.title)

    if len(full_workshops) > 0:
        ret_error = ""
        for cnt, i in enumerate(full_workshops):
            ret_error += ("Workshop \"" + i.title() + "\" is booked up.")
            if (cnt < len(full_workshops) - 1):
                ret_error += "\n"

        return render(request, 'WSS/register.html', {'wss': get_object_or_404(WSS, year=year), 'form': form,
                                                     'error': ret_error})
    field_of_interest = ""
    for i in form.cleaned_data['interests']:
        field_of_interest += ", " + i
    is_student = form.cleaned_data['is_student']
    logger.info("participant with email:" + email + " created.")

    try:
        exh = Participant.objects.all().get(email=email)
    except:
        exh = None
    if participate_in_wss and exh is not None and exh.payment_status == 'OK':
        return render(request, 'WSS/register.html', {'wss': get_object_or_404(WSS, year=year), 'form': form,
                                                     'error': "You have been registered successfully with this email."})

    try:
        gr = Grade.objects.all().get(level=grade)
    except Grade.DoesNotExist:
        return render(request, 'WSS/register.html', {'wss': get_object_or_404(WSS, year=year), 'form': form,
                                                     'error': "The entered grade is incorrect."})

    cap = gr.capacity
    exh = Participant(current_wss=current_wss, name=name, family=family, email=email, grade=grade,
                      phone_number=phone_number, job=job,
                      university=university, introduction_method=introduction_method, gender=gender,
                      name_english=name_eng, family_english=family_eng,
                      city=city, participate_in_wss=participate_in_wss, age=age,
                      country=country, field_of_interest=field_of_interest, is_student=is_student,
                      national_id=national_id, question=question)
    if participate_in_wss and cap <= 0:
        return reserve(request, form, year)
        pass

    payment_id = Random().randint(0, 1000000000)
    exh.payment_id = payment_id
    exh.save()
    exh.workshops = workshops
    exh.save()
    price = compute_cost(exh)
    result = client.service.PaymentRequest(MERCHANT, price, description, '*****@*****.**', "09123456789",
                                           CallbackURL + email + "/" + str(payment_id))
    if result.Status == 100:
        logger.info("user with email:" + email + " connected to payment")
        return redirect('https://www.zarinpal.com/pg/StartPay/' + str(result.Authority))
    else:
        return HttpResponse('Error code: ' + str(result.Status))  # todo move to error page
コード例 #5
0
def register_success(request):
    return render(request,
                  template_name='register_success.html',
                  context={'wss': WSS.active_wss()})
コード例 #6
0
 def get_context_data(self, **kwargs):
     context = super(RegistrationView, self).get_context_data(**kwargs)
     context['wss'] = WSS.active_wss()
     return context
コード例 #7
0
 def get_context_data(self, **kwargs):
     context = super(CreatorsListView, self).get_context_data(**kwargs)
     context['wss'] = WSS.active_wss()
     return context
コード例 #8
0
def expire_registration(request):
    return render(request,
                  'register_end_time.html',
                  context={'wss': WSS.active_wss()})