Remove piston, keep just the models.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 14 Feb 2019 21:12:54 +0000 (22:12 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 14 Feb 2019 21:12:54 +0000 (22:12 +0100)
14 files changed:
requirements/requirements-dev.txt
requirements/requirements.txt
src/api/piston/__init__.py [new file with mode: 0644]
src/api/piston/admin.py [new file with mode: 0644]
src/api/piston/migrations/0001_initial.py [new file with mode: 0644]
src/api/piston/migrations/__init__.py [new file with mode: 0644]
src/api/piston/models.py [new file with mode: 0644]
src/api/request_validator.py
src/api/tests/tests.py
src/api/views.py
src/wolnelektury/migrations/piston/0001_initial.py [deleted file]
src/wolnelektury/migrations/piston/__init__.py [deleted file]
src/wolnelektury/settings/apps.py
src/wolnelektury/settings/contrib.py

index 2be42f8..d689371 100644 (file)
@@ -2,7 +2,5 @@
 
 django-debug-toolbar<1.10
 django-debug-toolbar-template-timings
-Fabric
 sphinx
 pyinotify
-fnpdeploy>=0.2.3
index 34f4d9a..7122431 100644 (file)
@@ -7,7 +7,6 @@ django-pipeline>=1.6,<1.7
 jsmin
 fnp-django-pagination
 django-maintenancemode==0.10
-django-piston==0.2.2.1.2
 jsonfield>=1.0.3,<1.1
 django-picklefield>=1.0,<1.1
 django-modeltranslation>=0.10,<0.11
diff --git a/src/api/piston/__init__.py b/src/api/piston/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/api/piston/admin.py b/src/api/piston/admin.py
new file mode 100644 (file)
index 0000000..792f196
--- /dev/null
@@ -0,0 +1,7 @@
+from django.contrib import admin
+from . import models
+
+
+admin.site.register(models.Nonce)
+admin.site.register(models.Consumer)
+admin.site.register(models.Token)
diff --git a/src/api/piston/migrations/0001_initial.py b/src/api/piston/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..c2939b1
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Consumer',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('name', models.CharField(max_length=255)),
+                ('description', models.TextField()),
+                ('key', models.CharField(max_length=18)),
+                ('secret', models.CharField(max_length=32)),
+                ('status', models.CharField(default=b'pending', max_length=16, choices=[(b'pending', b'Pending approval'), (b'accepted', b'Accepted'), (b'canceled', b'Canceled')])),
+                ('user', models.ForeignKey(related_name='consumers', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Nonce',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('token_key', models.CharField(max_length=18)),
+                ('consumer_key', models.CharField(max_length=18)),
+                ('key', models.CharField(max_length=255)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Resource',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('name', models.CharField(max_length=255)),
+                ('url', models.TextField(max_length=2047)),
+                ('is_readonly', models.BooleanField(default=True)),
+            ],
+        ),
+        migrations.CreateModel(
+            name='Token',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('key', models.CharField(max_length=18)),
+                ('secret', models.CharField(max_length=32)),
+                ('token_type', models.IntegerField(choices=[(1, 'Request'), (2, 'Access')])),
+                ('timestamp', models.IntegerField()),
+                ('is_approved', models.BooleanField(default=False)),
+                ('consumer', models.ForeignKey(to='piston.Consumer')),
+                ('user', models.ForeignKey(related_name='tokens', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
+            ],
+        ),
+    ]
diff --git a/src/api/piston/migrations/__init__.py b/src/api/piston/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/api/piston/models.py b/src/api/piston/models.py
new file mode 100644 (file)
index 0000000..7bb106c
--- /dev/null
@@ -0,0 +1,56 @@
+from django.conf import settings
+from django.db import models
+
+
+KEY_SIZE = 18
+SECRET_SIZE = 32
+
+CONSUMER_STATES = (
+    ('pending', 'Pending approval'),
+    ('accepted', 'Accepted'),
+    ('canceled', 'Canceled'),
+)
+
+
+class Nonce(models.Model):
+    token_key = models.CharField(max_length=KEY_SIZE)
+    consumer_key = models.CharField(max_length=KEY_SIZE)
+    key = models.CharField(max_length=255)
+
+    def __unicode__(self):
+        return u"Nonce %s for %s" % (self.key, self.consumer_key)
+
+
+class Resource(models.Model):
+    name = models.CharField(max_length=255)
+    url = models.TextField(max_length=2047)
+    is_readonly = models.BooleanField(default=True)
+
+
+class Consumer(models.Model):
+    name = models.CharField(max_length=255)
+    description = models.TextField()
+    key = models.CharField(max_length=KEY_SIZE)
+    secret = models.CharField(max_length=SECRET_SIZE)
+    status = models.CharField(max_length=16, choices=CONSUMER_STATES, default='pending')
+    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='consumers')
+
+    def __unicode__(self):
+        return u"Consumer %s with key %s" % (self.name, self.key)
+
+
+class Token(models.Model):
+    REQUEST = 1
+    ACCESS = 2
+    TOKEN_TYPES = ((REQUEST, u'Request'), (ACCESS, u'Access'))
+
+    key = models.CharField(max_length=KEY_SIZE)
+    secret = models.CharField(max_length=SECRET_SIZE)
+    token_type = models.IntegerField(choices=TOKEN_TYPES)
+    timestamp = models.IntegerField()
+    is_approved = models.BooleanField(default=False)
+    user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='tokens')
+    consumer = models.ForeignKey(Consumer)
+
+    def __unicode__(self):
+        return u"%s Token %s for %s" % (self.get_token_type_display(), self.key, self.consumer)
index 916636b..55bd6fb 100644 (file)
@@ -4,7 +4,7 @@
 #
 import time
 from oauthlib.oauth1 import RequestValidator
-from piston.models import Consumer, Nonce, Token
+from api.piston.models import Consumer, Nonce, Token
 
 
 class PistonRequestValidator(RequestValidator):
index 298a794..3b4d4c5 100644 (file)
@@ -17,7 +17,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
 from django.test import TestCase
 from django.test.utils import override_settings
 from mock import patch
-from piston.models import Consumer, Token
+from api.piston.models import Consumer, Token
 
 from catalogue.models import Book, Tag
 from picture.forms import PictureImportForm
index 518445d..66c9258 100644 (file)
@@ -6,7 +6,7 @@ from django.http import Http404
 from django.views.generic.base import View
 from oauthlib.common import urlencode
 from oauthlib.oauth1 import RequestTokenEndpoint, AccessTokenEndpoint
-from piston.models import KEY_SIZE, SECRET_SIZE
+from api.piston.models import KEY_SIZE, SECRET_SIZE
 from rest_framework.permissions import IsAuthenticated
 from rest_framework.response import Response
 from rest_framework.views import APIView
diff --git a/src/wolnelektury/migrations/piston/0001_initial.py b/src/wolnelektury/migrations/piston/0001_initial.py
deleted file mode 100644 (file)
index c2939b1..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-from django.conf import settings
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='Consumer',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('name', models.CharField(max_length=255)),
-                ('description', models.TextField()),
-                ('key', models.CharField(max_length=18)),
-                ('secret', models.CharField(max_length=32)),
-                ('status', models.CharField(default=b'pending', max_length=16, choices=[(b'pending', b'Pending approval'), (b'accepted', b'Accepted'), (b'canceled', b'Canceled')])),
-                ('user', models.ForeignKey(related_name='consumers', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-            ],
-        ),
-        migrations.CreateModel(
-            name='Nonce',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('token_key', models.CharField(max_length=18)),
-                ('consumer_key', models.CharField(max_length=18)),
-                ('key', models.CharField(max_length=255)),
-            ],
-        ),
-        migrations.CreateModel(
-            name='Resource',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('name', models.CharField(max_length=255)),
-                ('url', models.TextField(max_length=2047)),
-                ('is_readonly', models.BooleanField(default=True)),
-            ],
-        ),
-        migrations.CreateModel(
-            name='Token',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('key', models.CharField(max_length=18)),
-                ('secret', models.CharField(max_length=32)),
-                ('token_type', models.IntegerField(choices=[(1, 'Request'), (2, 'Access')])),
-                ('timestamp', models.IntegerField()),
-                ('is_approved', models.BooleanField(default=False)),
-                ('consumer', models.ForeignKey(to='piston.Consumer')),
-                ('user', models.ForeignKey(related_name='tokens', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-            ],
-        ),
-    ]
diff --git a/src/wolnelektury/migrations/piston/__init__.py b/src/wolnelektury/migrations/piston/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
index c3be29b..2c76f67 100644 (file)
@@ -50,7 +50,7 @@ INSTALLED_APPS_CONTRIB = [
     'rest_framework',
     'fnp_django_pagination',
     'pipeline',
-    'piston',
+    'api.piston',
     'piwik',
     'sorl.thumbnail',
     'kombu.transport.django',
index a25ef72..f3e7b6b 100644 (file)
@@ -15,7 +15,6 @@ MODELTRANSLATION_PREPOPULATE_LANGUAGE = 'pl'
 
 MIGRATION_MODULES = {
     'getpaid': 'wolnelektury.migrations.getpaid',
-    'piston': 'wolnelektury.migrations.piston',
 }
 
 GETPAID_ORDER_DESCRIPTION = "{% load funding_tags %}{{ order|sanitize_payment_title }}"