diff options
Diffstat (limited to '')
-rw-r--r-- | client/migrations/0020_alter_document_user_alter_document_usercode.py | 26 | ||||
-rw-r--r-- | client/models.py | 4 | ||||
-rw-r--r-- | client/templates/client/approve_doc_pdf.html | 2 | ||||
-rw-r--r-- | client/templates/client/doc_create.html | 8 | ||||
-rw-r--r-- | client/templates/client/index.html | 8 | ||||
-rw-r--r-- | client/urls.py | 2 | ||||
-rw-r--r-- | client/views.py | 36 | ||||
-rw-r--r-- | version.txt | 2 |
8 files changed, 61 insertions, 27 deletions
diff --git a/client/migrations/0020_alter_document_user_alter_document_usercode.py b/client/migrations/0020_alter_document_user_alter_document_usercode.py new file mode 100644 index 0000000..8df069d --- /dev/null +++ b/client/migrations/0020_alter_document_user_alter_document_usercode.py @@ -0,0 +1,26 @@ +# Generated by Django 4.1.5 on 2023-07-25 10:46 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('client', '0019_alter_document_usercode'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='user', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='document', + name='usercode', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='client.usercode'), + ), + ] diff --git a/client/models.py b/client/models.py index c39a5ea..c6cfdfd 100644 --- a/client/models.py +++ b/client/models.py @@ -97,8 +97,8 @@ class UserCode(models.Model): class Document(models.Model):
- usercode = models.ForeignKey(UserCode, default=None, on_delete=models.CASCADE, null=True)
- user = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
+ usercode = models.ForeignKey(UserCode, default=None, on_delete=models.CASCADE)
+ user = models.ForeignKey(User, default=None, on_delete=models.CASCADE, null=True)
group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE)
code = models.IntegerField(default=0)
compilation_date = models.DateTimeField(auto_now_add=True)
diff --git a/client/templates/client/approve_doc_pdf.html b/client/templates/client/approve_doc_pdf.html index d2ba29b..0a62886 100644 --- a/client/templates/client/approve_doc_pdf.html +++ b/client/templates/client/approve_doc_pdf.html @@ -16,7 +16,7 @@ </div> <br><br> <div class="row"> - <p class="center">{{doc.user.first_name}} {{doc.user.last_name}} ({{doc.user.username}})</p> + <p class="center">{{doc.usercode.first_name}} {{doc.usercode.last_name}}</p> </div> <div class="row"> <h2 class="center">{{doc.code}}</h2> diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html index c42fa05..a6efae8 100644 --- a/client/templates/client/doc_create.html +++ b/client/templates/client/doc_create.html @@ -13,11 +13,17 @@ <div class="col l8 offset-l2 s12"> <div class="card-panel"> <div class="row"> - <form id="form" action="{% url 'create'%}" method="post" class="col s12"> + <form id="form" action="{% url 'create' code=uc.code %}" method="post" class="col s12"> {% csrf_token %} <input type="hidden" name="action" id="action"> {% if not next %} <div class="row"> + <div class="col s12"> + {{uc.first_name}} {{uc.last_name}} + <div style="font-size: 0.5em; line-height: normal;">{{uc.born_date}}</div> + </div> + </div> + <div class="row"> <div class="input-field col s12"> <select name="doctype"> <option value="" disabled selected>Scegli</option> diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 8bb2d41..d0fcc9b 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -38,7 +38,7 @@ <p style="text-decoration: underline; text-decoration-thickness: 3px; text-decoration-color: {{data.2}};">{{data.0.first_name}} {{data.0.last_name}}<a href="{% url "edit_user" code=data.0.code %}" class="btn-flat"><i class="material-icons">edit</i></a></p> <div style="font-size: 0.5em; line-height: normal;">{{data.0.born_date}}</div> </span> - <a id="add" class="btn-floating halfway-fab btn-large {{color}}" href="{% url 'create'%}"><i class="material-icons">add</i></a> + <a id="add" class="btn-floating halfway-fab btn-large {{color}}" href="{% url 'create' code=data.0.code %}"><i class="material-icons">add</i></a> {% if data.1|length > 0 %} <ul class="collapsible"> {% for doc in data.1 %} @@ -150,11 +150,11 @@ <div class="collapsible-body"><span> <div class="row"> <div class="input-field col l4 s12"> - <input disabled value="{{doc.user.first_name}}" id="first_name" type="text" > + <input disabled value="{{doc.usercode.first_name}}" id="first_name" type="text" > <label for="first_name">Nome</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{doc.user.last_name}}" id="last_name" type="text" > + <input disabled value="{{doc.usercode.last_name}}" id="last_name" type="text" > <label for="last_name">Cognome</label> </div> <div class="input-field col l4 s12"> @@ -162,7 +162,7 @@ <label for="birth_date">Data di nascita</label> </div> <div class="input-field col l4 s12"> - <input disabled value="{{base_group}}" id="branca" type="text"> + <input disabled value="{{doc.usercode.branca.name}}" id="branca" type="text"> <label for="branca">Branca</label> </div> <div class="input-field col l4 s12"> diff --git a/client/urls.py b/client/urls.py index 4da5169..d76aa96 100644 --- a/client/urls.py +++ b/client/urls.py @@ -4,7 +4,7 @@ from . import views urlpatterns = [ path('', views.index, name='index'), - path('create', views.create, name='create'), + path('create/<int:code>', views.create, name='create'), path('edit', views.edit, name='edit'), path('about', views.about, name='about'), ] diff --git a/client/views.py b/client/views.py index 5160927..2ed0c6b 100644 --- a/client/views.py +++ b/client/views.py @@ -46,7 +46,7 @@ def index(request): document = Document.objects.get(id=request.POST["action"][1:]) # check if document is valid to modify - if document.user != request.user: + if document.usercode not in ucs: return HttpResponseRedirect("/") if document.status == "ok" or document.status == "archive": @@ -124,26 +124,28 @@ def index(request): @login_required -def create(request): +def create(request, code): context = {} - usercode = UserCode.objects.filter(user=request.user)[0] - - if usercode.midata_id > 0: - if not copy_from_midata(request, usercode): - return HttpResponseRedirect(request.path_info) + usercode = UserCode.objects.filter(user=request.user, code=code) + if (len(usercode) == 0): + # the user has no person + return HttpResponseRedirect("/") - # group name and obj - parent_groups = request.user.groups.values_list('name', flat=True) + usercode = usercode[0] + + if usercode.branca == None: + return HttpResponseRedirect("/") # get available types for user - filter = (Q(group_private=False) | Q(group__name__in=parent_groups)) & Q(enabled=True) + filter = (Q(group_private=False) | Q(group__name=usercode.branca.name)) & Q(enabled=True) if not request.user.is_staff and "capi" not in request.user.groups.values_list('name',flat = True): filter = filter & Q(staff_only=False) # remove from the list documents from already used types - doctypes = DocumentType.objects.filter(filter).values_list("id", flat=True).difference(Document.objects.filter(Q(user=request.user) & ~Q(status="archive")).select_related("document_type").values_list("document_type", flat=True)) - doctypes = doctypes.difference(HideGroup.objects.filter(group__name__in=parent_groups).select_related("doc_type").values_list("doc_type", flat=True)) + doctypes = DocumentType.objects.filter(filter).values_list("id", flat=True).difference(Document.objects.filter(Q(usercode=usercode) & ~Q(status="archive")).select_related("document_type").values_list("document_type", flat=True)) + doctypes = doctypes.difference(HideGroup.objects.filter(group__name=usercode.branca.name).select_related("doc_type").values_list("doc_type", flat=True)) + context["uc"] = usercode context['docs'] = DocumentType.objects.filter(id__in=doctypes) if request.method == "POST": if request.POST["action"] == "details": @@ -190,12 +192,12 @@ def create(request): # user is cheating abort return HttpResponseRedirect("/") - if document_type.group_private and document_type.group.name not in request.user.groups.values_list('name', flat=True): + if document_type.group_private and document_type.group.name != usercode.branca.name: # user is cheating abort return HttpResponseRedirect("/") # get list of docs with that type - current_docs = Document.objects.filter(user=request.user).filter(Q(document_type=document_type) & ~Q(status="archive")) + current_docs = Document.objects.filter(usercode=usercode).filter(Q(document_type=document_type) & ~Q(status="archive")) if len(current_docs) > 0: # if there is already a document with that type abort (user is cheating) return HttpResponseRedirect("/") @@ -224,13 +226,13 @@ def create(request): # generate document code while (True): - code = randint(100000, 999999) - if len(Document.objects.filter(code=code)) == 0: + dcode = randint(100000, 999999) + if len(Document.objects.filter(code=dcode)) == 0: break # save document document = Document( - user=request.user, group=document_type.group, code=code, status=status, document_type=document_type, personal_data=personal_data, medical_data=medical_data) + usercode=usercode, group=document_type.group, code=dcode, status=status, document_type=document_type, personal_data=personal_data, medical_data=medical_data) document.save() # attach custom keys diff --git a/version.txt b/version.txt index 4936b1d..c157b42 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.6 -rev=31 +rev=32 |