mirror of
				https://gitlab.crans.org/bde/nk20-scripts
				synced 2025-10-31 07:09:52 +01:00 
			
		
		
		
	Import the creation date of the accounts
This commit is contained in:
		| @@ -19,7 +19,7 @@ from member.models import Club, Profile | |||||||
| from ._import_utils import ImportCommand, BulkCreateManager, timed | from ._import_utils import ImportCommand, BulkCreateManager, timed | ||||||
|  |  | ||||||
| M_DURATION = 396 | M_DURATION = 396 | ||||||
| M_START = datetime.date(2019, 8, 31) | M_START = datetime.date(2019, 8, 1) | ||||||
| M_END = datetime.date(2020, 9, 30) | M_END = datetime.date(2020, 9, 30) | ||||||
|  |  | ||||||
| MAP_IDBDE = { | MAP_IDBDE = { | ||||||
| @@ -60,6 +60,13 @@ class Command(ImportCommand): | |||||||
|         Every Model has to be manually created, and no magic `.save()` |         Every Model has to be manually created, and no magic `.save()` | ||||||
|         function is being called. |         function is being called. | ||||||
|         """ |         """ | ||||||
|  |         # Get promotion and date of creation of the account | ||||||
|  |         cur.execute("SELECT idbde, MIN(date) AS created_at, MIN(annee) AS promo FROM adhesions" | ||||||
|  |                     " GROUP BY idbde ORDER BY promo, created_at;") | ||||||
|  |         MAP_IDBDE_PROMOTION = {} | ||||||
|  |         for row in cur: | ||||||
|  |             MAP_IDBDE_PROMOTION[row["idbde"]] = row | ||||||
|  |  | ||||||
|         cur.execute("SELECT * FROM comptes WHERE idbde > 0 ORDER BY idbde;") |         cur.execute("SELECT * FROM comptes WHERE idbde > 0 ORDER BY idbde;") | ||||||
|         pk_club = 3 |         pk_club = 3 | ||||||
|         pk_user = 1 |         pk_user = 1 | ||||||
| @@ -84,7 +91,6 @@ class Command(ImportCommand): | |||||||
|                 "last_negative": None, |                 "last_negative": None, | ||||||
|                 "is_active": True, |                 "is_active": True, | ||||||
|                 "display_image": "pic/default.png", |                 "display_image": "pic/default.png", | ||||||
|                 "created_at": now() |  | ||||||
|             } |             } | ||||||
|             if row["last_negatif"] is not None: |             if row["last_negatif"] is not None: | ||||||
|                 note_dict["last_negative"] = make_aware(row["last_negatif"]) |                 note_dict["last_negative"] = make_aware(row["last_negatif"]) | ||||||
| @@ -95,6 +101,11 @@ class Command(ImportCommand): | |||||||
|                 else: |                 else: | ||||||
|                     passwd_nk15 = '' |                     passwd_nk15 = '' | ||||||
|  |  | ||||||
|  |                 if row["idbde"] not in MAP_IDBDE_PROMOTION: | ||||||
|  |                     # NK12 bug. Applying default values | ||||||
|  |                     MAP_IDBDE_PROMOTION[row["idbde"]] = {"promo": 2014, | ||||||
|  |                                                          "created_at": datetime.datetime(2014, 9, 1, 0, 0, 0)} | ||||||
|  |  | ||||||
|                 obj_dict = { |                 obj_dict = { | ||||||
|                     "pk": pk_user, |                     "pk": pk_user, | ||||||
|                     "username": row["pseudo"], |                     "username": row["pseudo"], | ||||||
| @@ -112,7 +123,9 @@ class Command(ImportCommand): | |||||||
|                     "paid": row['normalien'], |                     "paid": row['normalien'], | ||||||
|                     "registration_valid": True, |                     "registration_valid": True, | ||||||
|                     "email_confirmed": True, |                     "email_confirmed": True, | ||||||
|  |                     "promotion": MAP_IDBDE_PROMOTION[row["idbde"]]["promo"], | ||||||
|                 } |                 } | ||||||
|  |                 note_dict["created_at"] = make_aware(MAP_IDBDE_PROMOTION[row["idbde"]]["created_at"]) | ||||||
|                 note_dict["polymorphic_ctype"] = note_user_type |                 note_dict["polymorphic_ctype"] = note_user_type | ||||||
|                 note_user_dict = { |                 note_user_dict = { | ||||||
|                     "pk": pk_note, |                     "pk": pk_note, | ||||||
| @@ -138,6 +151,7 @@ class Command(ImportCommand): | |||||||
|                     "pk": pk_club, |                     "pk": pk_club, | ||||||
|                     "name": row["pseudo"], |                     "name": row["pseudo"], | ||||||
|                     "email": row["mail"], |                     "email": row["mail"], | ||||||
|  |                     "parent_club": 1,   # All clubs depends on BDE by default | ||||||
|                     "membership_duration": M_DURATION, |                     "membership_duration": M_DURATION, | ||||||
|                     "membership_start": M_START, |                     "membership_start": M_START, | ||||||
|                     "membership_end": M_END, |                     "membership_end": M_END, | ||||||
| @@ -146,7 +160,7 @@ class Command(ImportCommand): | |||||||
|                 } |                 } | ||||||
|                 note_club_dict = { |                 note_club_dict = { | ||||||
|                     "pk": pk_note, |                     "pk": pk_note, | ||||||
|                     "club_id": pk_club, |                     "club_id": pk_club | ||||||
|                 } |                 } | ||||||
|                 alias_dict = { |                 alias_dict = { | ||||||
|                     "pk": pk_note, |                     "pk": pk_note, | ||||||
| @@ -154,16 +168,18 @@ class Command(ImportCommand): | |||||||
|                     "normalized_name": Alias.normalize(pseudo), |                     "normalized_name": Alias.normalize(pseudo), | ||||||
|                     "note_id": pk_note |                     "note_id": pk_note | ||||||
|                 } |                 } | ||||||
|  |                 note_dict["created_at"] = make_aware(row["previous_report_date"])  # Not perfect, but good approximation | ||||||
|                 note_dict["polymorphic_ctype"] = note_club_type |                 note_dict["polymorphic_ctype"] = note_club_type | ||||||
|                 bulk_mgr.add(Club(**obj_dict), |                 #bulk_mgr.add(Club(**obj_dict), | ||||||
|                              Note(**note_dict), |                 #             Note(**note_dict), | ||||||
|                              NoteClub(**note_club_dict), |                 #             NoteClub(**note_club_dict), | ||||||
|                              Alias(**alias_dict)) |                 #             Alias(**alias_dict)) | ||||||
|                 pk_club += 1 |                 pk_club += 1 | ||||||
|             # row import completed |             # row import completed | ||||||
|             MAP_IDBDE[row["idbde"]] = pk_note |             MAP_IDBDE[row["idbde"]] = pk_note | ||||||
|             pk_note += 1 |             pk_note += 1 | ||||||
|         bulk_mgr.done() |         bulk_mgr.done() | ||||||
|  |         exit(0) | ||||||
|  |  | ||||||
|     @timed |     @timed | ||||||
|     def import_alias(self, cur, chunk_size): |     def import_alias(self, cur, chunk_size): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user