Ejemplo n.º 1
0
def register(request, slug):
    logger = logging.getLogger(__name__)

#    # create a file handler
    logger.info('views::register() - start')
    event = get_object_or_404(Event, slug=slug)
    now = datetime.datetime.now()
    if event.start_registration > now or event.end_registration < now:
        return HttpResponse(_("Inschrijving gesloten."))
    #SubscribeForm = SubscribeFormBuilder(event)
    if request.method == "POST":
        logger.info('views::register() - form POST')
        form = SubscribeForm(event, request.POST)
        if form.is_valid():
            # Store the data
            subscription = fill_subscription(form, event)
            if not subscription:
                # Error Filling subscription
                error_str = "Error in saving form."
                logger.error(error_str)
                return HttpResponse(_(error_str))
            if subscription.event_option.price <= 0:
                subscription.payed = True
                subscription.send_confirmation_email()
                subscription.save()
                logger.info('views::register() - registered for a free event.')
                return HttpResponse(_("Dank voor uw inschrijving"))
            
            # You need to pay
            response = mollie.fetch(
                settings.MOLLIE['partner_id'],          # Partner id
                subscription.event_option.price,        # Amount
                form.cleaned_data["issuer"].safe_id(),  # Bank ID
                subscription.event_option.name,         # Description
                settings.MOLLIE['report_url'],          # Report url
                settings.MOLLIE['return_url'],          # Return url
                settings.MOLLIE['profile_key'],         # Return url
            )
            
            err = mollie.get_error(response)
            if err:
                error_str = "views::register() - Technische fout, probeer later opnieuw." + "\n\n%d: %s" % (err[0], err[1])
                logger.error(error_str)
                return HttpResponse(_(error_str))
            
            subscription.trxid = response.order.transaction_id
            subscription.save()
            
            logger.info(response.order.URL)            
            return HttpResponseRedirect(str(response.order.URL))

    else:
        form = SubscribeForm(event)
    c = {
        "event": event,
        "request": request,
        "form": form,
    }
    c.update(csrf(request))
    return render_to_response("form.html", c)
Ejemplo n.º 2
0
def subscribe(request):
    if request.method == 'POST':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            print('form is valid')
            Subscribe.objects.create(email=form.cleaned_data['email'])
            return redirect('home:home')

    return redirect('home:home')
Ejemplo n.º 3
0
Archivo: views.py Proyecto: kpx13/avg
def subscribe(request):
    if request.POST and request.POST['action'] == 'subscribe':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            form.save()
            form = SubscribeForm()
            messages.success(request, u'Вы успешно подписались на рассылку.')
            return HttpResponseRedirect('/')
        else:
            messages.error(request, u'Необходимо ввести адрес.')
            return HttpResponseRedirect('/')
    raise Http404() 
Ejemplo n.º 4
0
def register(request, slug):
    event = get_object_or_404(Event, slug=slug)
    now = datetime.datetime.now()
    if event.start_registration > now or event.end_registration < now:
        return HttpResponse(_("Inschrijving gesloten."))
    #SubscribeForm = SubscribeFormBuilder(event)
    if request.method == "POST":
        form = SubscribeForm(event, request.POST)
        if form.is_valid():
            # Store the data
            subscription = fill_subscription(form, event)
            if not subscription:
                # Error Filling subscription
                return HttpResponse(_("Error in saving form."))
            if subscription.event_option.price <= 0:
                subscription.payed = True
                subscription.send_confirmation_email()
                subscription.save()
                return HttpResponse(_("Dank voor uw inschrijving"))
            
            # You need to pay
            oIDC = iDEALConnector()

            req = oIDC.RequestTransaction(
                issuerId=form.cleaned_data["issuer"].safe_id(),
                purchaseId=subscription.gen_subscription_id(),
                amount=subscription.event_option.price,
                description=_safe_string(subscription.event_option.__unicode__()),
                entranceCode=subscription.gen_subscription_id() )
            
            if type(req) != AcquirerTransactionResponse:
                return HttpResponse(_("Technische fout, probeer later opnieuw."))
            
            sUrl = req.getIssuerAuthenticationURL()
            
            # store the transaction ID, can later be used to check the status of the transaction
            transactionId = req.getTransactionID()
            subscription.trxid = transactionId
            subscription.save()
            
            return HttpResponseRedirect(sUrl)
    else:
        form = SubscribeForm(event)
    c = {
        "event": event,
        "request": request,
        "form": form,
    }
    c.update(csrf(request))
    return render_to_response("form.html", c)
Ejemplo n.º 5
0
def subscribe_add(request):
    """
    Add new subscriber
    :param request: request
    :return: json
    """
    if request.method == 'POST':
        form = SubscribeForm(request.POST)
        if form.is_valid():
            email_list = Subscriber.objects.filter(
                email=form.cleaned_data['email'])
            if len(email_list) == 0:
                Subscriber.objects.create(email=form.cleaned_data['email'])
            return JsonResponse({"result": "ok"})
        else:
            return JsonResponse({"result": "error"})
Ejemplo n.º 6
0
Archivo: views.py Proyecto: kpx13/vv
def get_common_context(request):
    c = {}
    #if not request.user.is_superuser:
    #	raise RuntimeError
    c['request_url'] = request.path
    c['is_debug'] = settings.DEBUG
    c['recent_reviews'] = Review.objects.filter(at_right=True).order_by('?')[:RIGHT_REVIEWS_COUNT]
    c['header'] = Page.get_by_slug('header').content
    c.update(csrf(request))
    
    form = SubscribeForm()
    if request.method == 'POST':
        if request.POST['action'] == 'subscribe':
            form = SubscribeForm(request.POST)
            if form.is_valid():
                if form.save():
                    c['form_subscribe_send'] = '1'
                else:
                    c['form_subscribe_send'] = '0'      
    c['sform'] = form
    
    return c
Ejemplo n.º 7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        user = READ_User.objects.get(user_id=self.request.session.get('user'))
        subs = Subscribe.objects.filter(user=user)
        context['visible'] = 1

        for sub in subs:
            if sub.video == context['video']:
                context['visible'] = 0
                break

        context['form'] = SubscribeForm(self.request)
        return context
Ejemplo n.º 8
0
def detail(request, slug):

    subscribed = False

    if request.method == 'POST':

        subscribe_form = SubscribeForm(data=request.POST)

        if subscribe_form.is_valid():
            subscribe = subscribe_form.save(commit=False)

            subscribe.save()

            subscribed = True
    else:
        subscribe_form = SubscribeForm()

    context_dict = {}

    try:

        title = Title.objects.get(slug=slug)

        details = Detail.objects.filter(title=title)

        context_dict['details'] = details
        context_dict['title'] = title
        context_dict['subscribed'] = subscribed

        context_dict['subscribe_form'] = subscribe_form

        #tagforblog = TagForBlog.objects.get(title=title)

        related_titles = Title.objects.exclude(slug=slug).filter(
            blog_type=title.blog_type).order_by('pub_date')[:6]

        related_titles_by_author = Title.objects.exclude(slug=slug).filter(
            publisher=title.publisher).order_by('-pub_date')[:3]

        context_dict['related_titles'] = related_titles

        context_dict['related_titles_by_author'] = related_titles_by_author

        nav_tips = Title.objects.filter(blog_type='tips')[:4]
        nav_tales = Title.objects.filter(blog_type='stories')[:4]
        nav_inspireds = Title.objects.filter(blog_type='inspired')[:4]
        nav_photoblogs = Title.objects.filter(blog_type='photoblog')[:4]

        context_dict['nav_tips'] = nav_tips
        context_dict['nav_tales'] = nav_tales
        context_dict['nav_inspireds'] = nav_inspireds
        context_dict['nav_photoblogs'] = nav_photoblogs

    except Title.DoesNotExist:
        raise Http404("Page does not exist")

    return render(request, 'blogs/blog_detail.html', context_dict)
Ejemplo n.º 9
0
def subsribe_form():
    return {'subscribe_form': SubscribeForm()}
Ejemplo n.º 10
0
def register(request, slug):
    logger = logging.getLogger(__name__)

    # Get the event
    event = get_object_or_404(Event, slug=slug)

    # If not staff, check if allowed
    if not request.user.is_staff:
        now = datetime.datetime.now()
        if event.start_registration > now or event.end_registration < now:
            return event_message(request, event, _("Inschrijving gesloten."))
        if event.is_full():
            return event_message(request, event, _("Helaas is het maximum aantal inschrijvingen bereikt."))

    # If this is not a POST request
    if request.method != "POST":
        # then just create the form...
        form = SubscribeForm(event)
        c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff}
        c.update(csrf(request))
        return render_to_response("subscribe/form.html", c)

    # It is a POST request, check if the form is valid...
    form = SubscribeForm(event, request.POST)
    if not form.is_valid():
        c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff}
        c.update(csrf(request))
        return render_to_response("subscribe/form.html", c)

    # It is a POST request, and the form is valid, check if this is the confirmation page
    if 'registration_preview' not in request.POST and not form.is_free_event:
        form.confirm_page()
        c = {"event": event, "request": request, "form": form, "user_is_staff": request.user.is_staff}
        c.update(csrf(request))
        return render_to_response("subscribe/form.html", c)

    # Maybe this is just a test of the confirmation email?
    if 'testsubmit' in request.POST:
        subscription = fill_subscription(form, event)
        msg = subscription.send_confirmation_email()
        subscription.delete()
        msg = '<br/>'.join(escape(msg).split('\n'))
        return event_message(request, event, mark_safe("De volgende email is verstuurd:<br/><br/>{}".format(msg)))

    # We confirmed. Create the subscription in the database...
    subscription = fill_subscription(form, event)

    # Check if the subscription form could be saved
    if not subscription:
        # Error Filling subscription
        error_str = "Error in saving form."
        return HttpResponse(_(error_str))

    # Check (again) if maybe the number of registrations is over the limit...
    if subscription in event.get_registrations_over_limit():
        subscription.delete()
        if event.is_full():
            error_str = "De inschrijving kan niet worden voltooid, omdat het maximum aantal inschrijvingen is bereikt."
        else:
            error_str = "De inschrijving kan niet worden voltooid, omdat een van de gekozen opties het maximum aantal inschrijvingen heeft bereikt."
        return event_message(request, event, _(error_str))

    # Check if we need to pay or not...
    if subscription.price <= 0:
        subscription.paid = True
        subscription.send_confirmation_email()
        subscription.save()
        return event_message(request, event, _("Inschrijving geslaagd. Ter bevestiging is een e-mail verstuurd."))

    # Payment required...
    try:
        mollie = Mollie.API.Client()
        mollie.setApiKey(settings.MOLLIE_KEY)

        # METADATA TOEVOEGEN
        webhookUrl = request.build_absolute_uri(reverse("webhook", args=[subscription.id]))
        redirectUrl = request.build_absolute_uri(reverse("return_page", args=[subscription.id]))

        payment = mollie.payments.create({
            'amount': float(subscription.price) / 100.0,
            'description': subscription.event.name,
            'webhookUrl': webhookUrl,
            'redirectUrl': redirectUrl,
        })

        subscription.trxid = payment["id"]
        subscription.save()

        return HttpResponseRedirect(payment.getPaymentUrl())
    except Mollie.API.Error as e:
        error_str = "register: Technische fout, probeer later opnieuw.\n\n" + str(e)
        logger.error(error_str)
        return event_message(request, event, _(error_str))