From c1f43eadc9e36ab176181ab2d825392971d06b6e Mon Sep 17 00:00:00 2001 From: Python3pkg Date: Wed, 17 May 2017 21:53:58 -0700 Subject: [PATCH] Convert to python3 --- threebot_hook/migrations/0001_initial.py | 2 +- threebot_hook/migrations/0001_initial.py.bak | 37 +++++++++++++++ .../migrations/0002_remove_hook_owner.py | 2 +- .../migrations/0002_remove_hook_owner.py.bak | 18 ++++++++ threebot_hook/models.py | 4 +- threebot_hook/models.py.bak | 45 +++++++++++++++++++ 6 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 threebot_hook/migrations/0001_initial.py.bak create mode 100644 threebot_hook/migrations/0002_remove_hook_owner.py.bak create mode 100644 threebot_hook/models.py.bak diff --git a/threebot_hook/migrations/0001_initial.py b/threebot_hook/migrations/0001_initial.py index 547d229..ecb6d2b 100644 --- a/threebot_hook/migrations/0001_initial.py +++ b/threebot_hook/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from django.db import models, migrations diff --git a/threebot_hook/migrations/0001_initial.py.bak b/threebot_hook/migrations/0001_initial.py.bak new file mode 100644 index 0000000..547d229 --- /dev/null +++ b/threebot_hook/migrations/0001_initial.py.bak @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Hook', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('slug', models.SlugField(max_length=255)), + ('user', models.CharField(max_length=255, null=True, blank=True)), + ('repo', models.CharField(max_length=255, null=True, blank=True)), + ('secret', models.CharField(max_length=255, null=True, blank=True)), + ('owner', models.ForeignKey(blank=True, to='organizations.Organization', null=True)), + ('param_list', models.ForeignKey(to='threebot.ParameterList')), + ('worker', models.ForeignKey(to='threebot.Worker')), + ('workflow', models.ForeignKey(to='threebot.Workflow')), + ], + options={ + 'db_table': 'threebot_hook', + 'verbose_name': 'Hook', + 'verbose_name_plural': 'Hooks', + }, + bases=(models.Model,), + ), + migrations.AlterUniqueTogether( + name='hook', + unique_together=set([('workflow', 'worker', 'param_list')]), + ), + ] diff --git a/threebot_hook/migrations/0002_remove_hook_owner.py b/threebot_hook/migrations/0002_remove_hook_owner.py index 6855ebe..7358078 100644 --- a/threebot_hook/migrations/0002_remove_hook_owner.py +++ b/threebot_hook/migrations/0002_remove_hook_owner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals + from django.db import models, migrations diff --git a/threebot_hook/migrations/0002_remove_hook_owner.py.bak b/threebot_hook/migrations/0002_remove_hook_owner.py.bak new file mode 100644 index 0000000..6855ebe --- /dev/null +++ b/threebot_hook/migrations/0002_remove_hook_owner.py.bak @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('threebot_hook', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='hook', + name='owner', + ), + ] diff --git a/threebot_hook/models.py b/threebot_hook/models.py index c0d11fe..50c0592 100644 --- a/threebot_hook/models.py +++ b/threebot_hook/models.py @@ -15,8 +15,8 @@ class Hook(models.Model): slug = models.SlugField(max_length=255) user = models.CharField(max_length=255, blank=True, null=True) - repo = models.CharField(max_length=255, blank=True, null=True, help_text=u'Leave blank. Field is not used in the current version.') - secret = models.CharField(max_length=255, blank=True, null=True, help_text=u'Leave blank. Field is not used in the current version.') + repo = models.CharField(max_length=255, blank=True, null=True, help_text='Leave blank. Field is not used in the current version.') + secret = models.CharField(max_length=255, blank=True, null=True, help_text='Leave blank. Field is not used in the current version.') workflow = models.ForeignKey(Workflow) worker = models.ForeignKey(Worker) param_list = models.ForeignKey(ParameterList) diff --git a/threebot_hook/models.py.bak b/threebot_hook/models.py.bak new file mode 100644 index 0000000..c0d11fe --- /dev/null +++ b/threebot_hook/models.py.bak @@ -0,0 +1,45 @@ +from django.db import models +from django.utils.encoding import python_2_unicode_compatible +from django.utils.translation import ugettext_lazy as _ +from django import dispatch +from django.contrib.sites.models import Site + +from rest_framework.authtoken.models import Token + +from threebot.models import Workflow +from threebot.models import Worker +from threebot.models import ParameterList + + +@python_2_unicode_compatible +class Hook(models.Model): + slug = models.SlugField(max_length=255) + user = models.CharField(max_length=255, blank=True, null=True) + repo = models.CharField(max_length=255, blank=True, null=True, help_text=u'Leave blank. Field is not used in the current version.') + secret = models.CharField(max_length=255, blank=True, null=True, help_text=u'Leave blank. Field is not used in the current version.') + workflow = models.ForeignKey(Workflow) + worker = models.ForeignKey(Worker) + param_list = models.ForeignKey(ParameterList) + + def get_hook_url(self): + return "%d-%d-%d-%s" % (self.workflow.id, self.worker.id, self.param_list.id, self.slug) + + def __str__(self): + return "%s (%d)" % (self.get_hook_url(), self.pk) + + def make_full_url(self, user): + token, created = Token.objects.get_or_create(user=user) + return "https://%s/hooks/%s/%s-%s-%s/" % (Site.objects.get_current().domain, token, self.workflow.id, self.worker.id, self.param_list.id) + + class Meta(): + verbose_name = _("Hook") + verbose_name_plural = _("Hooks") + db_table = 'threebot_hook' + unique_together = ("workflow", "worker", "param_list") + + +class HookSignal(dispatch.Signal): + pass + +pre_hook_signal = HookSignal() +post_hook_signal = HookSignal()