Skip to content

Commit

Permalink
Partial pipeline DB storage implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed Jan 2, 2017
1 parent 996fa31 commit 1bbc42d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/python-social-auth/social-app-django/commits/master)

### Added
- Partial pipeline DB storage implementation

### Changed
- Monkey patch BaseAuth to load the current strategy to workaround django load_backend() call
- Remove usage of set/get current strategy methods
Expand Down
31 changes: 31 additions & 0 deletions social_django/migrations/0006_partial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-01-02 11:54
from __future__ import unicode_literals

from django.db import migrations, models
import social_django.fields
import social_django.storage


class Migration(migrations.Migration):

dependencies = [
('social_django', '0005_auto_20160727_2333'),
]

operations = [
migrations.CreateModel(
name='Partial',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('token', models.CharField(db_index=True, max_length=32)),
('next_step', models.PositiveSmallIntegerField(default=0)),
('backend', models.CharField(max_length=32)),
('data', social_django.fields.JSONField(default={})),
],
options={
'db_table': 'social_auth_partial',
},
bases=(models.Model, social_django.storage.DjangoPartialMixin),
),
]
13 changes: 12 additions & 1 deletion social_django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .storage import DjangoUserMixin, DjangoAssociationMixin, \
DjangoNonceMixin, DjangoCodeMixin, \
BaseDjangoStorage
DjangoPartialMixin, BaseDjangoStorage
from .fields import JSONField
from .managers import UserSocialAuthManager

Expand Down Expand Up @@ -111,11 +111,22 @@ class Meta:
unique_together = ('email', 'code')


class Partial(models.Model, DjangoPartialMixin):
token = models.CharField(max_length=32, db_index=True)
next_step = models.PositiveSmallIntegerField(default=0)
backend = models.CharField(max_length=32)
data = JSONField()

class Meta:
db_table = 'social_auth_partial'


class DjangoStorage(BaseDjangoStorage):
user = UserSocialAuth
nonce = Nonce
association = Association
code = Code
partial = Partial

@classmethod
def is_integrity_error(cls, exception):
Expand Down
17 changes: 16 additions & 1 deletion social_django/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.utils import IntegrityError

from social_core.storage import UserMixin, AssociationMixin, NonceMixin, \
CodeMixin, BaseStorage
CodeMixin, PartialMixin, BaseStorage


class DjangoUserMixin(UserMixin):
Expand Down Expand Up @@ -168,6 +168,21 @@ def get_code(cls, code):
return None


class DjangoPartialMixin(PartialMixin):
@classmethod
def load(cls, token):
try:
return cls.objects.get(token=token)
except cls.DoesNotExist:
return None

@classmethod
def destroy(cls, token):
partial = cls.load(token)
if partial:
partial.delete()


class BaseDjangoStorage(BaseStorage):
user = DjangoUserMixin
nonce = DjangoNonceMixin
Expand Down

0 comments on commit 1bbc42d

Please sign in to comment.