Fix double user creation

This commit is contained in:
Skia 2016-09-02 09:47:33 +02:00
parent 29f565f514
commit bae34c4b1c

View File

@ -29,19 +29,23 @@ class Subscriber(User):
return s.is_valid_now() if s is not None else False return s.is_valid_now() if s is not None else False
def save(self): def save(self):
create = False
if not self.id:
create = True
super(Subscriber, self).save() super(Subscriber, self).save()
try: # Create user on the old site: TODO remove me! if create:
db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS) try: # Create user on the old site: TODO remove me!
c = db.cursor() db = MySQLdb.connect(**settings.OLD_MYSQL_INFOS)
c.execute("""INSERT INTO utilisateurs (id_utilisateur, nom_utl, prenom_utl, email_utl, hash_utl, ae_utl) VALUES c = db.cursor()
(%s, %s, %s, %s, %s, %s)""", (self.id, self.last_name, self.first_name, self.email, "valid", "1")) c.execute("""INSERT INTO utilisateurs (id_utilisateur, nom_utl, prenom_utl, email_utl, hash_utl, ae_utl) VALUES
db.commit() (%s, %s, %s, %s, %s, %s)""", (self.id, self.last_name, self.first_name, self.email, "valid", "1"))
except Exception as e: db.commit()
with open(settings.BASE_DIR+"/user_fail.log", "a") as f: except Exception as e:
print("FAIL to add user %s (%s %s - %s) to old site" % (self.id, self.first_name.encode('utf-8'), with open(settings.BASE_DIR+"/user_fail.log", "a") as f:
self.last_name.encode('utf-8'), self.email), file=f) print("FAIL to add user %s (%s %s - %s) to old site" % (self.id, self.first_name.encode('utf-8'),
print("Reason: %s" % (repr(e)), file=f) self.last_name.encode('utf-8'), self.email), file=f)
db.rollback() print("Reason: %s" % (repr(e)), file=f)
db.rollback()
class Subscription(models.Model): class Subscription(models.Model):
member = models.ForeignKey(Subscriber, related_name='subscriptions') member = models.ForeignKey(Subscriber, related_name='subscriptions')