mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-27 01:42:24 +00:00
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 note.models import Note
|
||||
from note.models import Alias
|
||||
from note.models import TemplateCategory, TransactionTemplate, \
|
||||
Transaction, RecurrentTransaction, SpecialTransaction
|
||||
from note.models import (
|
||||
TemplateCategory,
|
||||
TransactionTemplate,
|
||||
Transaction,
|
||||
RecurrentTransaction,
|
||||
MembershipTransaction,
|
||||
SpecialTransaction,
|
||||
)
|
||||
from member.models import Club, Membership
|
||||
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')
|
||||
note_name = qs[0]["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)
|
||||
else:
|
||||
raise e
|
||||
@ -164,20 +170,25 @@ def import_transaction(cur):
|
||||
idmin = 58770
|
||||
bde = Club.objects.get(name="BDE")
|
||||
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\
|
||||
a.idbde,a.annee, a.wei, a.date AS adh_date, a.section
|
||||
FROM transactions AS t\
|
||||
LEFT JOIN adhesions AS a ON t.id = a.idtransaction\
|
||||
WHERE transactions.id> {}\
|
||||
ORDER BY transactions.id;".format(idmin))
|
||||
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 \
|
||||
a.idbde, a.annee, a.wei, a.date AS adh_date, a.section\
|
||||
FROM transactions AS t \
|
||||
LEFT JOIN adhesions AS a ON t.id = a.idtransaction \
|
||||
WHERE transactions.id> {} \
|
||||
ORDER BY transactions.id;".format(idmin)
|
||||
)
|
||||
n = cur.rowcount
|
||||
for idx, row in enumerate(cur):
|
||||
update_line(idx, n, row["description"])
|
||||
try:
|
||||
date = make_aware(row["transac_date"])
|
||||
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 = {
|
||||
# "pk": row["id"],
|
||||
"destination_id": MAP_IDBDE[row["destinataire"]],
|
||||
@ -256,20 +267,19 @@ def import_transaction(cur):
|
||||
except IntegrityError as e:
|
||||
raise e
|
||||
elif ttype == "invitation":
|
||||
m = re.search("Invitation (.*?) \((.*?)\)", row["description"])
|
||||
m = re.search(r"Invitation (.*?) \((.*?)\)", row["description"])
|
||||
if m is None:
|
||||
raise IntegrityError("Invitation is not well formated: {} (must be 'Invitation ACTIVITY_NAME (NAME)')"
|
||||
.format(row["description"]))
|
||||
raise IntegrityError(f"Invitation is not well formated: {row['description']} (must be 'Invitation ACTIVITY_NAME (NAME)')")
|
||||
|
||||
activity_name = m.group(1)
|
||||
guest_name = m.group(2)
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
for g in MAP_NAMEGUEST[guest_name]:
|
||||
@ -277,7 +287,7 @@ def import_transaction(cur):
|
||||
guest = g
|
||||
break
|
||||
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
|
||||
|
||||
@ -297,7 +307,7 @@ def import_aliases(cur):
|
||||
obj_dict = {
|
||||
"note_id": MAP_IDBDE[row["idbde"]],
|
||||
"name": alias_name_good,
|
||||
"normalized_name": Alias.normalize(alias_name_good)
|
||||
"normalized_name": Alias.normalize(alias_name_good),
|
||||
}
|
||||
try:
|
||||
with transaction.atomic():
|
||||
@ -321,7 +331,7 @@ def import_activities(cur):
|
||||
update_line(idx, n, row["alias"])
|
||||
organizer = Club.objects.filter(name=row["signature"])
|
||||
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()
|
||||
else:
|
||||
organizer = kfet
|
||||
@ -398,7 +408,6 @@ def import_activity_entries(cur):
|
||||
raise e
|
||||
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def import_remittances(cur):
|
||||
cur.execute("SELECT * FROM remises ORDER by id")
|
||||
|
Loading…
Reference in New Issue
Block a user