From deeb2b5b6f21b6d051a2ad71be66e6695415d932 Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 4 Oct 2016 00:32:07 +0200 Subject: [PATCH] Migrate and fix etickets --- counter/views.py | 4 ++-- migrate.py | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/counter/views.py b/counter/views.py index ac4f2e50..9ff15e39 100644 --- a/counter/views.py +++ b/counter/views.py @@ -999,7 +999,7 @@ class EticketPDFView(CanViewMixin, DetailView): self.object = self.get_object() eticket = self.object.product.eticket user = self.object.customer.user - code = "%s %s %s" % (self.object.customer.user.id, self.object.quantity, self.object.product.id) + code = "%s %s %s" % (self.object.customer.user.id, self.object.product.id, self.object.quantity) code += " " + eticket.get_hash(code)[:8].upper() response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'filename="eticket.pdf"' @@ -1030,7 +1030,7 @@ class EticketPDFView(CanViewMixin, DetailView): p.drawCentredString(10.5 * cm, 23.6 * cm, eticket.event_title) if eticket.event_date: p.setFont("Helvetica-Bold", 16) - p.drawCentredString(10.5 * cm, 22.6 * cm, eticket.event_date.strftime("%d %b %Y")) + p.drawCentredString(10.5 * cm, 22.6 * cm, eticket.event_date.strftime("%d %b %Y")) # FIXME with a locale p.setFont("Helvetica-Bold", 14) p.drawCentredString(10.5 * cm, 15 * cm, user.get_display_name()) p.setFont("Courier-Bold", 14) diff --git a/migrate.py b/migrate.py index 90dfcded..19c5b19c 100644 --- a/migrate.py +++ b/migrate.py @@ -21,7 +21,7 @@ from django.core.files import File from core.models import User, SithFile from club.models import Club, Membership -from counter.models import Customer, Counter, Selling, Refilling, Product, ProductType, Permanency +from counter.models import Customer, Counter, Selling, Refilling, Product, ProductType, Permanency, Eticket from subscription.models import Subscription, Subscriber from eboutic.models import Invoice, InvoiceItem from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType, Company, SimplifiedAccountingType @@ -962,6 +962,36 @@ def migrate_godfathers(): print("Godfathers migrated at %s" % datetime.datetime.now()) print("Running time: %s" % (datetime.datetime.now()-start)) +def migrate_etickets(): + FILE_ROOT = "/data/files/" + cur = db.cursor(MySQLdb.cursors.SSDictCursor) + cur.execute(""" + SELECT * + FROM cpt_etickets + """) + Eticket.objects.all().delete() + for r in cur: + try: + p = Product.objects.filter(id=r['id_produit']).first() + try: + f = File(open(FILE_ROOT + '/' + str(r['banner']) + ".1", 'rb')) + except: + f = None + e = Eticket( + product=p, + secret=to_unicode(r['secret']), + banner=f, + event_title=p.name, + ) + e.save() + e.secret=to_unicode(r['secret']) + e.save() + except Exception as e: + print("FAIL to migrate eticket: %s" % (repr(e))) + cur.close() + print("Etickets migrated at %s" % datetime.datetime.now()) + print("Running time: %s" % (datetime.datetime.now()-start)) + def main(): print("Start at %s" % start) # Core @@ -975,7 +1005,8 @@ def main(): # check_accounts() # Accounting # migrate_accounting() - migrate_godfathers() + # migrate_godfathers() + migrate_etickets() # reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter') end = datetime.datetime.now() print("End at %s" % end)