mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-28 15:42:25 +00:00
[Printer] Digicode are stored in bdd
This commit is contained in:
parent
6b3fa3b15a
commit
4b315c3ecf
3 changed files with 64 additions and 14 deletions
38
printer/migrations/0010_auto_20181025_1257.py
Normal file
38
printer/migrations/0010_auto_20181025_1257.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2018-10-25 10:57
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
import django.core.files.storage
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import printer.utils
|
||||
import printer.validators
|
||||
import re2o.mixins
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('printer', '0009_jobwithoptions_paid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Digicode',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.BigIntegerField(default=0, unique=True)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('used_time', models.DateTimeField(null=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
bases=(re2o.mixins.RevMixin, models.Model),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='jobwithoptions',
|
||||
name='file',
|
||||
field=models.FileField(storage=django.core.files.storage.FileSystemStorage(location='/var/impressions'), upload_to=printer.models.user_printing_path, validators=[printer.validators.FileValidator(allowed_types=['application/pdf'], max_size=41943040)]),
|
||||
),
|
||||
]
|
|
@ -11,6 +11,7 @@ from numpy.random import randint
|
|||
import unidecode
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from django.db import models
|
||||
from django.forms import ValidationError
|
||||
|
@ -21,8 +22,6 @@ from re2o.mixins import RevMixin
|
|||
|
||||
import users.models
|
||||
|
||||
import unidecode
|
||||
|
||||
from .validators import (
|
||||
FileValidator,
|
||||
)
|
||||
|
@ -54,6 +53,28 @@ def user_printing_path(instance, filename):
|
|||
return 'printings/user_{0}/{1}'.format(instance.user.id, unidecode.unidecode(filename))
|
||||
|
||||
|
||||
class Digicode(RevMixin, models.Model):
|
||||
"""
|
||||
This is a model to represent a digicode, maybe should be an external app.
|
||||
"""
|
||||
code = models.BigIntegerField(default=0, unique=True)
|
||||
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
used_time = models.DateTimeField(null=True)
|
||||
|
||||
def _gen_code(user):
|
||||
try_again = True
|
||||
while try_again:
|
||||
try:
|
||||
code = randint(695895, 6958942)*1437+38
|
||||
Digicode.objects.get(code=code)
|
||||
except ObjectDoesNotExist:
|
||||
try_again = False
|
||||
digicode = Digicode.objects.create(code=code, user=user)
|
||||
digicode.save()
|
||||
return (str(code) + '#')
|
||||
|
||||
|
||||
class JobWithOptions(RevMixin, models.Model):
|
||||
"""
|
||||
This is the main model of printer application :
|
||||
|
|
|
@ -5,9 +5,9 @@ import os
|
|||
from django.template.loader import get_template
|
||||
from django.core.mail import EmailMessage
|
||||
|
||||
from preferences.models import OptionalPrinter, GeneralOption, AssoOption
|
||||
from preferences.models import GeneralOption, AssoOption
|
||||
|
||||
from numpy.random import randint
|
||||
from .models import Digicode
|
||||
|
||||
import datetime
|
||||
|
||||
|
@ -54,20 +54,11 @@ def pdfbook(file_path):
|
|||
])
|
||||
return newfile
|
||||
|
||||
|
||||
def gen_code():
|
||||
code = randint(10**9, 10**10-1)
|
||||
while code % 1437 != 38:
|
||||
code = randint(10**9, 10**10-1)
|
||||
return (str(code) + '#')
|
||||
|
||||
|
||||
def send_mail_printer(client):
|
||||
"""Sends an email to the client explaning how to get the printings"""
|
||||
|
||||
template = get_template('printer/email_printer')
|
||||
code = gen_code()
|
||||
|
||||
code = Digicode._gen_code(client)
|
||||
|
||||
printer_access_fr = "au quatrième (4) étage du bâtiment J (code B7806)"
|
||||
printer_access_en = "on fourth (4th) floor of building J (code B7806)"
|
||||
|
|
Loading…
Reference in a new issue