mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Add pictures to products
This commit is contained in:
parent
a49d9850ab
commit
4cbfd58660
@ -288,11 +288,20 @@ label {
|
|||||||
}
|
}
|
||||||
.form_button {
|
.form_button {
|
||||||
width: 150px;
|
width: 150px;
|
||||||
height: 100px;
|
height: 120px;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
.form_button span {
|
||||||
|
width: 70px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.form_button img {
|
||||||
|
max-width: 50px;
|
||||||
|
max-height: 50px;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
.form_button strong {
|
.form_button strong {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
|
@ -91,7 +91,14 @@
|
|||||||
<h5>{{ t }}</h5>
|
<h5>{{ t }}</h5>
|
||||||
<div id="cat_{{ t }}">
|
<div id="cat_{{ t }}">
|
||||||
{% for p in counter.products.filter(product_type=t).all() -%}
|
{% for p in counter.products.filter(product_type=t).all() -%}
|
||||||
{{ add_product(p.id, "<strong>%s</strong><hr>%s €<br>%s" % (p.name, p.selling_price, p.code)) }}
|
{% set file = None %}
|
||||||
|
{% if p.icon %}
|
||||||
|
{% set file = p.icon.url %}
|
||||||
|
{% else %}
|
||||||
|
{% set file = static('core/img/na.gif') %}
|
||||||
|
{% endif %}
|
||||||
|
{% set prod = '<strong>%s</strong><hr><img src="%s" /><span>%s €<br>%s</span>' % (p.name, file, p.selling_price, p.code) %}
|
||||||
|
{{ add_product(p.id, prod) }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
36
migrate.py
36
migrate.py
@ -5,6 +5,7 @@ import random
|
|||||||
import datetime
|
import datetime
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
from os import listdir
|
||||||
|
|
||||||
os.environ["DJANGO_SETTINGS_MODULE"] = "sith.settings"
|
os.environ["DJANGO_SETTINGS_MODULE"] = "sith.settings"
|
||||||
os.environ['DJANGO_COLORS'] = 'nocolor'
|
os.environ['DJANGO_COLORS'] = 'nocolor'
|
||||||
@ -15,6 +16,7 @@ from django.conf import settings
|
|||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
|
from django.core.files import File
|
||||||
|
|
||||||
|
|
||||||
from core.models import User, SithFile
|
from core.models import User, SithFile
|
||||||
@ -147,9 +149,6 @@ def migrate_users():
|
|||||||
def migrate_profile_pict():
|
def migrate_profile_pict():
|
||||||
PROFILE_ROOT = "/data/matmatronch/"
|
PROFILE_ROOT = "/data/matmatronch/"
|
||||||
|
|
||||||
from os import listdir
|
|
||||||
from django.core.files import File
|
|
||||||
|
|
||||||
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
profile = SithFile.objects.filter(parent=None, name="profiles").first()
|
||||||
profile.children.all().delete()
|
profile.children.all().delete()
|
||||||
print("Profiles pictures deleted")
|
print("Profiles pictures deleted")
|
||||||
@ -400,7 +399,7 @@ def migrate_refillings():
|
|||||||
new = Refilling(
|
new = Refilling(
|
||||||
id=r['id_rechargement'],
|
id=r['id_rechargement'],
|
||||||
counter=counter or mde,
|
counter=counter or mde,
|
||||||
customer=cust,
|
customer=cust or root_cust,
|
||||||
operator=op or root_cust.user,
|
operator=op or root_cust.user,
|
||||||
amount=r['montant_rech']/100,
|
amount=r['montant_rech']/100,
|
||||||
payment_method=PAYMENT[r['type_paiement_rech']],
|
payment_method=PAYMENT[r['type_paiement_rech']],
|
||||||
@ -462,6 +461,27 @@ def migrate_products():
|
|||||||
print("FAIL to migrate product %s: %s" % (r['nom_prod'], repr(e)))
|
print("FAIL to migrate product %s: %s" % (r['nom_prod'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
|
def migrate_product_pict():
|
||||||
|
FILE_ROOT = "/data/files/"
|
||||||
|
|
||||||
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
|
cur.execute("""
|
||||||
|
SELECT *
|
||||||
|
FROM cpt_produits
|
||||||
|
WHERE id_file IS NOT NULL
|
||||||
|
""")
|
||||||
|
for r in cur:
|
||||||
|
print(r['nom_prod'])
|
||||||
|
try:
|
||||||
|
prod = Product.objects.filter(id=r['id_produit']).first()
|
||||||
|
if prod:
|
||||||
|
f = File(open(FILE_ROOT + '/' + str(r['id_file']) + ".1", 'rb'))
|
||||||
|
f.name = prod.name
|
||||||
|
prod.icon = f
|
||||||
|
prod.save()
|
||||||
|
except Exception as e:
|
||||||
|
print(repr(e))
|
||||||
|
|
||||||
def migrate_products_to_counter():
|
def migrate_products_to_counter():
|
||||||
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
@ -558,9 +578,7 @@ def migrate_sellings():
|
|||||||
)
|
)
|
||||||
new.save()
|
new.save()
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
print(repr(e) + " for %s (%s), assigning to root" % (customer, customer.user.id))
|
print(repr(e) + " for %s (%s)" % (customer, customer.user.id))
|
||||||
new.customer = root.customer
|
|
||||||
new.save()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FAIL to migrate selling %s: %s" % (r['id_facture'], repr(e)))
|
print("FAIL to migrate selling %s: %s" % (r['id_facture'], repr(e)))
|
||||||
cur.close()
|
cur.close()
|
||||||
@ -599,9 +617,11 @@ def main():
|
|||||||
migrate_permanencies()
|
migrate_permanencies()
|
||||||
migrate_typeproducts()
|
migrate_typeproducts()
|
||||||
migrate_products()
|
migrate_products()
|
||||||
|
migrate_product_pict()
|
||||||
migrate_products_to_counter()
|
migrate_products_to_counter()
|
||||||
# reset_customer_amount()
|
reset_customer_amount()
|
||||||
migrate_refillings()
|
migrate_refillings()
|
||||||
|
reset_index('counter')
|
||||||
migrate_invoices()
|
migrate_invoices()
|
||||||
migrate_sellings()
|
migrate_sellings()
|
||||||
reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
||||||
|
Loading…
Reference in New Issue
Block a user