pretty code and f-strings
This commit is contained in:
parent
2a8dc40aeb
commit
f9bac69aad
|
@ -19,8 +19,14 @@ from django.contrib.auth.models import User
|
||||||
from activity.models import ActivityType, Activity, Guest, Entry, GuestTransaction
|
from activity.models import ActivityType, Activity, Guest, Entry, GuestTransaction
|
||||||
from note.models import Note
|
from note.models import Note
|
||||||
from note.models import Alias
|
from note.models import Alias
|
||||||
from note.models import TemplateCategory, TransactionTemplate, \
|
from note.models import (
|
||||||
Transaction, RecurrentTransaction, SpecialTransaction
|
TemplateCategory,
|
||||||
|
TransactionTemplate,
|
||||||
|
Transaction,
|
||||||
|
RecurrentTransaction,
|
||||||
|
MembershipTransaction,
|
||||||
|
SpecialTransaction,
|
||||||
|
)
|
||||||
from member.models import Club, Membership
|
from member.models import Club, Membership
|
||||||
from treasury.models import RemittanceType, Remittance, SpecialTransactionProxy
|
from treasury.models import RemittanceType, Remittance, SpecialTransactionProxy
|
||||||
|
|
||||||
|
@ -152,7 +158,7 @@ def import_boutons(cur):
|
||||||
qs = Club.objects.filter(note__note_ptr=MAP_IDBDE[row["destinataire"]]).values('name')
|
qs = Club.objects.filter(note__note_ptr=MAP_IDBDE[row["destinataire"]]).values('name')
|
||||||
note_name = qs[0]["name"]
|
note_name = qs[0]["name"]
|
||||||
# rename button name
|
# rename button name
|
||||||
obj_dict["name"] = "{} {}".format(obj_dict["name"], note_name)
|
obj_dict["name"] = f"{obj_dict_name['name']} {note_name}"
|
||||||
button = TransactionTemplate.objects.create(**obj_dict)
|
button = TransactionTemplate.objects.create(**obj_dict)
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
@ -164,20 +170,25 @@ def import_transaction(cur):
|
||||||
idmin = 58770
|
idmin = 58770
|
||||||
bde = Club.objects.get(name="BDE")
|
bde = Club.objects.get(name="BDE")
|
||||||
kfet = Club.objects.get(name="Kfet")
|
kfet = Club.objects.get(name="Kfet")
|
||||||
cur.execute("SELECT t.date AS transac_date, t.type, t.emetteur, t.destinataire, t.quantite, t.montant, t.description, t.valide, t.cantinvalidate, t.categorie\
|
cur.execute(
|
||||||
a.idbde,a.annee, a.wei, a.date AS adh_date, a.section
|
"SELECT t.date AS transac_date, t.type, t.emetteur,\
|
||||||
|
t.destinataire,t.quantite, t.montant, t.description,\
|
||||||
|
t.valide, t.cantinvalidate, t.categorie \
|
||||||
|
a.idbde, a.annee, a.wei, a.date AS adh_date, a.section\
|
||||||
FROM transactions AS t \
|
FROM transactions AS t \
|
||||||
LEFT JOIN adhesions AS a ON t.id = a.idtransaction \
|
LEFT JOIN adhesions AS a ON t.id = a.idtransaction \
|
||||||
WHERE transactions.id> {} \
|
WHERE transactions.id> {} \
|
||||||
ORDER BY transactions.id;".format(idmin))
|
ORDER BY transactions.id;".format(idmin)
|
||||||
|
)
|
||||||
n = cur.rowcount
|
n = cur.rowcount
|
||||||
for idx, row in enumerate(cur):
|
for idx, row in enumerate(cur):
|
||||||
update_line(idx, n, row["description"])
|
update_line(idx, n, row["description"])
|
||||||
try:
|
try:
|
||||||
date = make_aware(row["transac_date"])
|
date = make_aware(row["transac_date"])
|
||||||
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
|
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
|
||||||
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1)
|
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1))
|
||||||
|
|
||||||
|
# standart transaction object
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
# "pk": row["id"],
|
# "pk": row["id"],
|
||||||
"destination_id": MAP_IDBDE[row["destinataire"]],
|
"destination_id": MAP_IDBDE[row["destinataire"]],
|
||||||
|
@ -256,20 +267,19 @@ def import_transaction(cur):
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
raise e
|
raise e
|
||||||
elif ttype == "invitation":
|
elif ttype == "invitation":
|
||||||
m = re.search("Invitation (.*?) \((.*?)\)", row["description"])
|
m = re.search(r"Invitation (.*?) \((.*?)\)", row["description"])
|
||||||
if m is None:
|
if m is None:
|
||||||
raise IntegrityError("Invitation is not well formated: {} (must be 'Invitation ACTIVITY_NAME (NAME)')"
|
raise IntegrityError(f"Invitation is not well formated: {row['description']} (must be 'Invitation ACTIVITY_NAME (NAME)')")
|
||||||
.format(row["description"]))
|
|
||||||
|
|
||||||
activity_name = m.group(1)
|
activity_name = m.group(1)
|
||||||
guest_name = m.group(2)
|
guest_name = m.group(2)
|
||||||
|
|
||||||
if activity_name not in MAP_NAMEACTIVITY:
|
if activity_name not in MAP_NAMEACTIVITY:
|
||||||
raise IntegrityError("Activity {} is not found".format(activity_name,))
|
raise IntegrityError(f"Activity {activity_name} is not found")
|
||||||
activity = MAP_NAMEACTIVITY[activity_name]
|
activity = MAP_NAMEACTIVITY[activity_name]
|
||||||
|
|
||||||
if guest_name not in MAP_NAMEGUEST:
|
if guest_name not in MAP_NAMEGUEST:
|
||||||
raise IntegrityError("Guest {} is not found".format(guest_name,))
|
raise IntegrityError(f"Guest {guest_name} is not found")
|
||||||
|
|
||||||
guest = None
|
guest = None
|
||||||
for g in MAP_NAMEGUEST[guest_name]:
|
for g in MAP_NAMEGUEST[guest_name]:
|
||||||
|
@ -277,7 +287,7 @@ def import_transaction(cur):
|
||||||
guest = g
|
guest = g
|
||||||
break
|
break
|
||||||
if guest is None:
|
if guest is None:
|
||||||
raise IntegrityError("Guest {} didn't go to the activity {}".format(guest_name, activity_name,))
|
raise IntegrityError("Guest {guest_name} didn't go to the activity {activity_name}")
|
||||||
|
|
||||||
obj_dict["guest"] = guest
|
obj_dict["guest"] = guest
|
||||||
|
|
||||||
|
@ -297,7 +307,7 @@ def import_aliases(cur):
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
"note_id": MAP_IDBDE[row["idbde"]],
|
"note_id": MAP_IDBDE[row["idbde"]],
|
||||||
"name": alias_name_good,
|
"name": alias_name_good,
|
||||||
"normalized_name": Alias.normalize(alias_name_good)
|
"normalized_name": Alias.normalize(alias_name_good),
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
|
@ -321,7 +331,7 @@ def import_activities(cur):
|
||||||
update_line(idx, n, row["alias"])
|
update_line(idx, n, row["alias"])
|
||||||
organizer = Club.objects.filter(name=row["signature"])
|
organizer = Club.objects.filter(name=row["signature"])
|
||||||
if organizer.exists():
|
if organizer.exists():
|
||||||
# Try to find the club that organizes the activity. If not founded, assume that is Kfet (fix manually)
|
# Try to find the club that organizes the activity. If not founded, assume it's Kfet (fix manually)
|
||||||
organizer = organizer.get()
|
organizer = organizer.get()
|
||||||
else:
|
else:
|
||||||
organizer = kfet
|
organizer = kfet
|
||||||
|
@ -398,7 +408,6 @@ def import_activity_entries(cur):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def import_remittances(cur):
|
def import_remittances(cur):
|
||||||
cur.execute("SELECT * FROM remises ORDER by id")
|
cur.execute("SELECT * FROM remises ORDER by id")
|
||||||
|
|
Loading…
Reference in New Issue