A Django app to require user acceptance of terms of service.
Project description
This Django app adds support for versioned terms of service.
Installation
Install with pip:
$ pip install django-legal
Add legal to your INSTALLED_APPS setting.
(Optional) Add a new setting: LEGAL_TOS_NAME = 'terms_of_service'
Update urls.py with the following:
url(r'^legal/', include('legal.urls')),
Create a new Agreement and AgreementVersion (ideally via data migration):
# -*- coding: utf-8 -*- import os from south.v2 import DataMigration # This should be the same value as LEGAL_TOS_NAME (if you overrode it) AGREEMENT_NAME = 'tos' class Migration(DataMigration): def forwards(self, orm): agreement, created = orm['legal.Agreement'].objects.get_or_create(name=AGREEMENT_NAME) # This file should live in the same directory as the migration f = open('%s/tos_content_2013_08_01.html' % os.path.dirname(__file__), 'r') orm['legal.AgreementVersion'].objects.create(agreement=agreement, date='2013-08-01', content=f.read()) def backwards(self, orm): agreement = orm['legal.Agreement'].objects.get(name=AGREEMENT_NAME) agreement.delete() models = { 'legal.agreement': { 'Meta': {'object_name': 'Agreement'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ( 'django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}) }, 'legal.agreementversion': { 'Meta': {'ordering': "['-date']", 'unique_together': "(('agreement', 'date'),)", 'object_name': 'AgreementVersion'}, 'agreement': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['legal.Agreement']"}), 'content': ('django.db.models.fields.TextField', [], {}), 'date': ('django.db.models.fields.DateTimeField', [], {}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) } } # Change this to be the name of the app where the migration lives complete_apps = ['my-app'] symmetrical = True
Testing This App
A modified manage.py and Django settings file are included to test this app:
$ python manage.py test
Testing Your App
You may find the middleware a bit excessive for your tests as it requires you to create an agreement and version, and accept the agreement on behalf of your tests users. If you want to disable the middleware, add the following to your settings:
if 'test' in sys.argv: MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES.remove('legal.middleware.TermsOfServiceAcceptanceMiddleware')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-legal-0.1.tar.gz
.
File metadata
- Download URL: django-legal-0.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca3b7e11a482a31bfb06bd4d9eaf0a7174cc30bcd6cd3ed3a6a89806b0517647 |
|
MD5 | 88c0b73e3fcc783aa67dd8c6c9c718a8 |
|
BLAKE2b-256 | 57e47e75aedbb113f1bebd5b819ec68538b6944c65322188cca993e14d8e8954 |