From 8328e668bdd5c4045e15ab221874e17645613fd4 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Fri, 2 Sep 2016 21:24:10 +0200 Subject: [PATCH 1/3] Fixed old database bug in dev env --- core/models.py | 2 +- sith/settings_sample.py | 9 ++++- subscription/models.py | 83 +++++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/core/models.py b/core/models.py index 8e979f14..c0eee7e5 100644 --- a/core/models.py +++ b/core/models.py @@ -240,7 +240,7 @@ class User(AbstractBaseUser): else: create = True super(User, self).save(*args, **kwargs) - if create: # Create user on the old site: TODO remove me! + if create and settings.IS_OLD_MYSQL_PRESENT: # Create user on the old site: TODO remove me! import MySQLdb try: db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS) diff --git a/sith/settings_sample.py b/sith/settings_sample.py index ebe15cdd..d6923cef 100644 --- a/sith/settings_sample.py +++ b/sith/settings_sample.py @@ -17,7 +17,13 @@ from django.utils.translation import ugettext_lazy as _ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -os.environ['HTTPS'] = "on" +DEV_ENV = True + +if (DEV_ENV): + os.environ['HTTPS'] = "off" + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +else: + os.environ['HTTPS'] = "on" # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ @@ -408,6 +414,7 @@ SITH_LAUNDERETTE_PRICES = { 'DRYING': 0.75, } +IS_OLD_MYSQL_PRESENT = False OLD_MYSQL_INFOS = { 'host': 'ae-db', 'user': "my_user", diff --git a/subscription/models.py b/subscription/models.py index e6145ec7..aafc5167 100644 --- a/subscription/models.py +++ b/subscription/models.py @@ -33,7 +33,7 @@ class Subscriber(User): if not self.id: create = True super(Subscriber, self).save() - if create: + if create and settings.IS_OLD_MYSQL_PRESENT: try: # Create user on the old site: TODO remove me! db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS) c = db.cursor() @@ -82,47 +82,48 @@ class Subscription(models.Model): form.save(use_https=True, email_template_name='core/new_user_email.jinja', subject_template_name='core/new_user_email_subject.jinja', from_email="ae@utbm.fr") self.member.make_home() - try: # Create subscription on the old site: TODO remove me! - LOCATION = { - "SEVENANS": 5, - "BELFORT": 6, - "MONTBELIARD": 9, - "EBOUTIC": 5, - } - TYPE = { - 'un-semestre' : 0, - 'deux-semestres' : 1, - 'cursus-tronc-commun' : 2, - 'cursus-branche' : 3, - 'membre-honoraire' : 4, - 'assidu' : 5, - 'amicale/doceo' : 6, - 'reseau-ut' : 7, - 'crous' : 8, - 'sbarro/esta' : 9, - 'cursus-alternant' : 10, - } - PAYMENT = { - "CHECK" : 1, - "CARD" : 2, - "CASH" : 3, - "OTHER" : 4, - "EBOUTIC" : 5, - "OTHER" : 0, - } + if settings.IS_OLD_MYSQL_PRESENT: + try: # Create subscription on the old site: TODO remove me! + LOCATION = { + "SEVENANS": 5, + "BELFORT": 6, + "MONTBELIARD": 9, + "EBOUTIC": 5, + } + TYPE = { + 'un-semestre' : 0, + 'deux-semestres' : 1, + 'cursus-tronc-commun' : 2, + 'cursus-branche' : 3, + 'membre-honoraire' : 4, + 'assidu' : 5, + 'amicale/doceo' : 6, + 'reseau-ut' : 7, + 'crous' : 8, + 'sbarro/esta' : 9, + 'cursus-alternant' : 10, + } + PAYMENT = { + "CHECK" : 1, + "CARD" : 2, + "CASH" : 3, + "OTHER" : 4, + "EBOUTIC" : 5, + "OTHER" : 0, + } - db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS) - c = db.cursor() - c.execute("""INSERT INTO ae_cotisations (id_utilisateur, date_cotis, date_fin_cotis, mode_paiement_cotis, - type_cotis, id_comptoir) VALUES (%s, %s, %s, %s, %s, %s)""", (self.member.id, self.subscription_start, - self.subscription_end, PAYMENT[self.payment_method], TYPE[self.subscription_type], - LOCATION[self.location])) - db.commit() - except Exception as e: - with open(settings.BASE_DIR+"/subscription_fail.log", "a") as f: - print("FAIL to add subscription to %s to old site" % (self.member), file=f) - print("Reason: %s" % (repr(e)), file=f) - db.rollback() + db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS) + c = db.cursor() + c.execute("""INSERT INTO ae_cotisations (id_utilisateur, date_cotis, date_fin_cotis, mode_paiement_cotis, + type_cotis, id_comptoir) VALUES (%s, %s, %s, %s, %s, %s)""", (self.member.id, self.subscription_start, + self.subscription_end, PAYMENT[self.payment_method], TYPE[self.subscription_type], + LOCATION[self.location])) + db.commit() + except Exception as e: + with open(settings.BASE_DIR+"/subscription_fail.log", "a") as f: + print("FAIL to add subscription to %s to old site" % (self.member), file=f) + print("Reason: %s" % (repr(e)), file=f) + db.rollback() def get_absolute_url(self): return reverse('core:user_edit', kwargs={'user_id': self.member.pk}) From 5ca8a22123c21823b40e793dc0cbbd9672260d40 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sun, 4 Sep 2016 14:19:56 +0200 Subject: [PATCH 2/3] Fixed Settings --- sith/settings_sample.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sith/settings_sample.py b/sith/settings_sample.py index d6923cef..3b39a796 100644 --- a/sith/settings_sample.py +++ b/sith/settings_sample.py @@ -17,13 +17,8 @@ from django.utils.translation import ugettext_lazy as _ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -DEV_ENV = True - -if (DEV_ENV): - os.environ['HTTPS'] = "off" - EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' -else: - os.environ['HTTPS'] = "on" +os.environ['HTTPS'] = "off" +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ From b0215e74455f267767241c974be92ec9968fe015 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sun, 4 Sep 2016 14:56:47 +0200 Subject: [PATCH 3/3] Organized settings --- sith/settings_sample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sith/settings_sample.py b/sith/settings_sample.py index 3b39a796..3b41ea0b 100644 --- a/sith/settings_sample.py +++ b/sith/settings_sample.py @@ -18,7 +18,6 @@ from django.utils.translation import ugettext_lazy as _ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.environ['HTTPS'] = "off" -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ @@ -195,6 +194,7 @@ LOGIN_REDIRECT_URL = '/' DEFAULT_FROM_EMAIL="bibou@git.an" # Email +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_HOST="localhost" EMAIL_PORT=25