Skip to main content

Django App for Vingd integration

Project description

Django Vingd enables integrating Vingd into django project.

Basic setup

  1. Add “django_vingd” to INSTALLED_APPS.

  2. Configure django settings:

VINGD_SETTINGS = {
    'sandbox': {
        'VINGD_USR': 'test@knopso.com',
        'VINGD_PWD': '123',
    }
}
VINGD_MODE = 'sandbox'
  1. In any django app that uses vingd define Vingd Orders details (models.py):

# Imaginary scenario where users are voting for candidates via vingd.

from django.db import models
from django.http import HttpResponseRedirect
from django_vingd.models import VingdOrder

class Candidate(models.Model):
    name = models.CharField(max_length=128)
    votes = models.IntegerField(default=0)

    def add_vote(self):
        Candidate.objects.filter(id=self.id).update(votes=models.F('votes')+1)
        self.votes += 1

class VoteOrder(VingdOrder):
    candidate = models.ForeignKey(Candidate)

    # Short object description
    def get_display_name(self):
        return 'Vote for candidate'

    # Handle form submission (before sending user to vingd)
    def take_order(self):
        self.candidate_id = self.request.POST.get('candidate_id')

    # Determine vingd price
    def get_vingd_amount(self):
        return 75   # 0.75 vingd

    # Access is confirmed (user has returned back from vingd)
    def accept_order(self):
        self.candidate.add_vote()

    # Serve requested content to user
    def success_response(self):
        return HttpResponseRedirect('/')
  1. Register order classes in your urls (urls.py):

from django_vingd.models import VingdMeta
from base.models import VoteOrder

VingdMeta.register([VoteOrder, ])

urlpatterns = patterns('',
    (r'^vgd/', include('django_vingd.urls')),
)
  1. In HTML template place vingd order forms:

{% for candidate in candidates %}
    <form action="{% url vingd_order "VoteOrder" %}" method="POST">
        {% csrf_token %}
        {{ candidate.name }}: {{ candidate.votes }}
        <input type="hidden" name="candidate_id" value="{{ candidate.id }}">
        <input type="submit" value="vote">
    </form>
{% endfor %}

Sync database and start your engines!

Deny access to content

In some situations user should not be allowed to access content. Such cases should be handled both for:

  • denying access at vingd ordering time (before sending user to vingd)

  • denying access at vingd verification time (after user has returned from vingd).

In those cases one should raise exception within take_order and accept_order respectively.

Handling exceptions

To gracefully handle any kind of exception one should use VingdOrder handle_exception function:

def handle_exception(self, e):
    # log exception
    # inform user
    return HttpResponse("Inform user that something has gone wrong.")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-vingd-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django-vingd-0.1.1.linux-x86_64.exe (72.8 kB view details)

Uploaded Source

File details

Details for the file django-vingd-0.1.1.tar.gz.

File metadata

  • Download URL: django-vingd-0.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-vingd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4675b0ae9b26f876c61241be110f3cbba4f13994db052cd84b7caf76a67e78b9
MD5 ddd5cfb5b215b4b8da6f0989b27f4b1b
BLAKE2b-256 8a8b8991fde0bdaff4249c36795e431e1d971d266005b117a9781f6210f7b522

See more details on using hashes here.

File details

Details for the file django-vingd-0.1.1.linux-x86_64.exe.

File metadata

File hashes

Hashes for django-vingd-0.1.1.linux-x86_64.exe
Algorithm Hash digest
SHA256 6557bc344dd86061436aa1de0674f258ac5df9999b7a037b6a73f4d48d060b7c
MD5 fafe4dd02f824539fd634e73c29c745d
BLAKE2b-256 1579332feca411eb9a83ab58d691172db7889f843c3f3a51cf7736e44f2f5ad1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page