mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Fixed old database bug in dev env
This commit is contained in:
parent
c5fd9d0076
commit
8328e668bd
@ -240,7 +240,7 @@ class User(AbstractBaseUser):
|
|||||||
else:
|
else:
|
||||||
create = True
|
create = True
|
||||||
super(User, self).save(*args, **kwargs)
|
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
|
import MySQLdb
|
||||||
try:
|
try:
|
||||||
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
||||||
|
@ -17,7 +17,13 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
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
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
|
||||||
@ -408,6 +414,7 @@ SITH_LAUNDERETTE_PRICES = {
|
|||||||
'DRYING': 0.75,
|
'DRYING': 0.75,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IS_OLD_MYSQL_PRESENT = False
|
||||||
OLD_MYSQL_INFOS = {
|
OLD_MYSQL_INFOS = {
|
||||||
'host': 'ae-db',
|
'host': 'ae-db',
|
||||||
'user': "my_user",
|
'user': "my_user",
|
||||||
|
@ -33,7 +33,7 @@ class Subscriber(User):
|
|||||||
if not self.id:
|
if not self.id:
|
||||||
create = True
|
create = True
|
||||||
super(Subscriber, self).save()
|
super(Subscriber, self).save()
|
||||||
if create:
|
if create and settings.IS_OLD_MYSQL_PRESENT:
|
||||||
try: # Create user on the old site: TODO remove me!
|
try: # Create user on the old site: TODO remove me!
|
||||||
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
@ -82,47 +82,48 @@ class Subscription(models.Model):
|
|||||||
form.save(use_https=True, email_template_name='core/new_user_email.jinja',
|
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")
|
subject_template_name='core/new_user_email_subject.jinja', from_email="ae@utbm.fr")
|
||||||
self.member.make_home()
|
self.member.make_home()
|
||||||
try: # Create subscription on the old site: TODO remove me!
|
if settings.IS_OLD_MYSQL_PRESENT:
|
||||||
LOCATION = {
|
try: # Create subscription on the old site: TODO remove me!
|
||||||
"SEVENANS": 5,
|
LOCATION = {
|
||||||
"BELFORT": 6,
|
"SEVENANS": 5,
|
||||||
"MONTBELIARD": 9,
|
"BELFORT": 6,
|
||||||
"EBOUTIC": 5,
|
"MONTBELIARD": 9,
|
||||||
}
|
"EBOUTIC": 5,
|
||||||
TYPE = {
|
}
|
||||||
'un-semestre' : 0,
|
TYPE = {
|
||||||
'deux-semestres' : 1,
|
'un-semestre' : 0,
|
||||||
'cursus-tronc-commun' : 2,
|
'deux-semestres' : 1,
|
||||||
'cursus-branche' : 3,
|
'cursus-tronc-commun' : 2,
|
||||||
'membre-honoraire' : 4,
|
'cursus-branche' : 3,
|
||||||
'assidu' : 5,
|
'membre-honoraire' : 4,
|
||||||
'amicale/doceo' : 6,
|
'assidu' : 5,
|
||||||
'reseau-ut' : 7,
|
'amicale/doceo' : 6,
|
||||||
'crous' : 8,
|
'reseau-ut' : 7,
|
||||||
'sbarro/esta' : 9,
|
'crous' : 8,
|
||||||
'cursus-alternant' : 10,
|
'sbarro/esta' : 9,
|
||||||
}
|
'cursus-alternant' : 10,
|
||||||
PAYMENT = {
|
}
|
||||||
"CHECK" : 1,
|
PAYMENT = {
|
||||||
"CARD" : 2,
|
"CHECK" : 1,
|
||||||
"CASH" : 3,
|
"CARD" : 2,
|
||||||
"OTHER" : 4,
|
"CASH" : 3,
|
||||||
"EBOUTIC" : 5,
|
"OTHER" : 4,
|
||||||
"OTHER" : 0,
|
"EBOUTIC" : 5,
|
||||||
}
|
"OTHER" : 0,
|
||||||
|
}
|
||||||
|
|
||||||
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
c.execute("""INSERT INTO ae_cotisations (id_utilisateur, date_cotis, date_fin_cotis, mode_paiement_cotis,
|
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,
|
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],
|
self.subscription_end, PAYMENT[self.payment_method], TYPE[self.subscription_type],
|
||||||
LOCATION[self.location]))
|
LOCATION[self.location]))
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
with open(settings.BASE_DIR+"/subscription_fail.log", "a") as f:
|
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("FAIL to add subscription to %s to old site" % (self.member), file=f)
|
||||||
print("Reason: %s" % (repr(e)), file=f)
|
print("Reason: %s" % (repr(e)), file=f)
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('core:user_edit', kwargs={'user_id': self.member.pk})
|
return reverse('core:user_edit', kwargs={'user_id': self.member.pk})
|
||||||
|
Loading…
Reference in New Issue
Block a user