Skip to main content

Django Vingd

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!

Popup version

  1. Add jQuery to your page.

  2. Add popup related javascript to HTML head:

{% load vingd_tt %}
{% vingd_scripts %}

<script type="text/javascript">
    $(document).ready(function(){
        $('form').vingd_popup(function(data){
            alert('Vote added!');
        }, function(data){
            alert('Failed to add vote.');
        });
    });
</script>
  1. Handle ajax requests in your VoteOrders (models.py):

from django_vingd.util import HttpResponseJSON
# ...
def success_response(self):
    request = self.request
    if request.is_ajax():
        return HttpResponseJSON({
            'ok': True,
            'votes': self.candidate.votes,
        })
    return HttpResponseRedirect('/')

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.")

Metadata

Release files for django-vingd 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-vingd 0.1.1
File Size Uploaded Provenance
django-vingd-0.1.1.tar.gz 6.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-vingd 0.1.1
File Interpreter ABI Platform
django-vingd-0.1.1.linux-x86_64.exe Details

Total release size: 79.5 kB

Release files / django-vingd-0.1.1.tar.gz

Download URL django-vingd-0.1.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4675b0ae9b26f876c61241be110f3cbba4f13994db052cd84b7caf76a67e78b9
BLAKE2b-256 checksum
How to use checksums
8a8b8991fde0bdaff4249c36795e431e1d971d266005b117a9781f6210f7b522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-vingd-0.1.1.linux-x86_64.exe

Download URL django-vingd-0.1.1.linux-x86_64.exe
Size 72.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6557bc344dd86061436aa1de0674f258ac5df9999b7a037b6a73f4d48d060b7c
BLAKE2b-256 checksum
How to use checksums
1579332feca411eb9a83ab58d691172db7889f843c3f3a51cf7736e44f2f5ad1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-vingd 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page