From: Jan Szejko Date: Tue, 22 May 2018 13:29:02 +0000 (+0200) Subject: more fixes for publishing on beta X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/dae8c833746bf716c05aaccba59a5fc049918163?ds=inline more fixes for publishing on beta --- diff --git a/apps/apiclient/__init__.py b/apps/apiclient/__init__.py index 2709ca06..56ecb96d 100644 --- a/apps/apiclient/__init__.py +++ b/apps/apiclient/__init__.py @@ -23,7 +23,7 @@ class NotAuthorizedError(BaseException): def api_call(user, path, data=None, beta=False): from .models import OAuthConnection api_url = BETA_API_URL if beta else WL_API_URL - conn = OAuthConnection.get(user) + conn = OAuthConnection.get(user=user, beta=beta) if not conn.access: raise NotAuthorizedError("No WL authorization for user %s." % user) token = oauth2.Token(conn.token, conn.token_secret) diff --git a/apps/apiclient/migrations/0002_auto__add_field_oauthconnection_beta.py b/apps/apiclient/migrations/0002_auto__add_field_oauthconnection_beta.py new file mode 100644 index 00000000..094606fe --- /dev/null +++ b/apps/apiclient/migrations/0002_auto__add_field_oauthconnection_beta.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'OAuthConnection.beta' + db.add_column(u'apiclient_oauthconnection', 'beta', + self.gf('django.db.models.fields.BooleanField')(default=False), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'OAuthConnection.beta' + db.delete_column(u'apiclient_oauthconnection', 'beta') + + + models = { + u'apiclient.oauthconnection': { + 'Meta': {'object_name': 'OAuthConnection'}, + 'access': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'beta': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'token': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}), + 'token_secret': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.User']", 'unique': 'True'}) + }, + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + } + } + + complete_apps = ['apiclient'] \ No newline at end of file diff --git a/apps/apiclient/models.py b/apps/apiclient/models.py index d3c8f620..9cce9a8e 100644 --- a/apps/apiclient/models.py +++ b/apps/apiclient/models.py @@ -7,13 +7,14 @@ class OAuthConnection(models.Model): access = models.BooleanField(default=False) token = models.CharField(max_length=64, null=True, blank=True) token_secret = models.CharField(max_length=64, null=True, blank=True) + beta = models.BooleanField(default=False) @classmethod - def get(cls, user): + def get(cls, user, beta=False): try: - return cls.objects.get(user=user) + return cls.objects.get(user=user, beta=beta) except cls.DoesNotExist: - o = cls(user=user) + o = cls(user=user, beta=beta) o.save() return o diff --git a/apps/apiclient/urls.py b/apps/apiclient/urls.py index 55cc4669..214b983d 100755 --- a/apps/apiclient/urls.py +++ b/apps/apiclient/urls.py @@ -1,6 +1,9 @@ +# -*- coding: utf-8 -*- from django.conf.urls import patterns, url urlpatterns = patterns('apiclient.views', url(r'^oauth/$', 'oauth', name='apiclient_oauth'), url(r'^oauth_callback/$', 'oauth_callback', name='apiclient_oauth_callback'), + url(r'^oauth/$', 'oauth', kwargs={'beta': True}, name='apiclient_beta_oauth'), + url(r'^oauth_callback/$', 'oauth_callback', kwargs={'beta': True}, name='apiclient_beta_callback'), ) diff --git a/apps/apiclient/views.py b/apps/apiclient/views.py index fb3f5077..239682a5 100644 --- a/apps/apiclient/views.py +++ b/apps/apiclient/views.py @@ -23,7 +23,7 @@ def oauth(request, beta=False): request_token = dict(cgi.parse_qsl(content)) - conn = OAuthConnection.get(request.user) + conn = OAuthConnection.get(request.user, beta) # this might reset existing auth! conn.access = False conn.token = request_token['oauth_token'] @@ -45,7 +45,7 @@ def oauth_callback(request, beta=False): return HttpResponse("OAuth consumer not configured.") oauth_verifier = request.GET.get('oauth_verifier') - conn = OAuthConnection.get(request.user) + conn = OAuthConnection.get(request.user, beta) token = oauth2.Token(conn.token, conn.token_secret) token.set_verifier(oauth_verifier) client = oauth2.Client(wl_consumer, token)