From 11a6248b1e0c2b473f6cc6dc5cafe2f57376e588 Mon Sep 17 00:00:00 2001 From: Okhin Date: Mon, 18 Mar 2019 18:49:06 +0100 Subject: [PATCH 1/5] Let's sync db on migrate, in case some apps (such as django_und_vote) don't have migrations, but needs tables to be created --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6af22f..77888c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ unit tests: - pip install -r requirements-tests.txt - echo "DEBUG = True" > ./project/settings/env.py - echo "SECRET_KEY = '$(pwgen 20 1)'" >> ./project/settings/env.py - - ./manage.py migrate + - ./manage.py migrate --run-syncdb - pytest apps/ --cov=apps/ tags: [preprod] @@ -57,7 +57,7 @@ deploy preprod: - echo "DEBUG = True" > ${BASE_PATH}/project/settings/env.py - echo "SECRET_KEY = '$(pwgen 20 1)'" >> ${BASE_PATH}/project/settings/env.py - echo "SITE_ID = 2" >> ${BASE_PATH}/project/settings/env.py - - ${BASE_PATH}/manage.py migrate + - ${BASE_PATH}/manage.py migrate --run-syncdb - touch ${BASE_PATH}/ready only: - rp2 -- GitLab From 526de1871c78cea4d79c6310fe3f27b348ea4f80 Mon Sep 17 00:00:00 2001 From: Okhin Date: Tue, 19 Mar 2019 14:34:05 +0100 Subject: [PATCH 2/5] Adding internal IP to get DDT to work --- project/settings/hosts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project/settings/hosts.py b/project/settings/hosts.py index 7d1b7ed..e7b630a 100644 --- a/project/settings/hosts.py +++ b/project/settings/hosts.py @@ -10,5 +10,6 @@ from .env import DEBUG if DEBUG: ALLOWED_HOSTS = ['*'] + INTERNAL_IPS = ('127.0.0.1',) elif 'DJANGO_ALLOWED_HOSTS' in os.environ: ALLOWED_HOSTS = [os.environ['DJANGO_ALLOWED_HOSTS']] -- GitLab From 198b237d27360634b2d37db898e7c0ce0a27f8dd Mon Sep 17 00:00:00 2001 From: Okhin Date: Tue, 19 Mar 2019 15:23:10 +0100 Subject: [PATCH 3/5] Working on stuff --- apps/userprofile/apps.py | 3 +++ apps/userprofile/signals.py | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 apps/userprofile/signals.py diff --git a/apps/userprofile/apps.py b/apps/userprofile/apps.py index 0252f18..c848ed9 100644 --- a/apps/userprofile/apps.py +++ b/apps/userprofile/apps.py @@ -3,3 +3,6 @@ from django.apps import AppConfig class UserprofileConfig(AppConfig): name = 'userprofile' + + def ready(self): + import userprofile.signals diff --git a/apps/userprofile/signals.py b/apps/userprofile/signals.py new file mode 100644 index 0000000..3bd48c7 --- /dev/null +++ b/apps/userprofile/signals.py @@ -0,0 +1,10 @@ +from django.core.signals import post_save +from django.dispatch import receiver +from rest_framework.authtoken.models import Token +from django.conf import settings + + +@receiver(post_save, sender=settings.AUTH_USER_MODEL) +def create_user_token(sender, instance=None, created=False, *args, **wkargs): + if created: + Token.objects.create(user=instance) -- GitLab From d2dc9a8d8c73660e1c069572d9a4a6bdb06abf0d Mon Sep 17 00:00:00 2001 From: Okhin Date: Tue, 19 Mar 2019 15:38:57 +0100 Subject: [PATCH 4/5] Need to overload the app classes --- apps/userprofile/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/userprofile/__init__.py b/apps/userprofile/__init__.py index e69de29..3e844af 100644 --- a/apps/userprofile/__init__.py +++ b/apps/userprofile/__init__.py @@ -0,0 +1 @@ +default_app_config = 'userprofile.apps.UserprofileConfig' -- GitLab From 55650dc0211289b3d0d7cfe3825087ebb3cf4e6e Mon Sep 17 00:00:00 2001 From: Okhin Date: Tue, 19 Mar 2019 15:39:18 +0100 Subject: [PATCH 5/5] Fixing the path for the post_save signal --- apps/userprofile/signals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/userprofile/signals.py b/apps/userprofile/signals.py index 3bd48c7..1436ff1 100644 --- a/apps/userprofile/signals.py +++ b/apps/userprofile/signals.py @@ -1,4 +1,4 @@ -from django.core.signals import post_save +from django.db.models.signals import post_save from django.dispatch import receiver from rest_framework.authtoken.models import Token from django.conf import settings -- GitLab