aboutsummaryrefslogtreecommitdiffstats
path: root/client/views.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client/views.py51
1 files changed, 49 insertions, 2 deletions
diff --git a/client/views.py b/client/views.py
index 96eb977..78ca7d1 100644
--- a/client/views.py
+++ b/client/views.py
@@ -1,9 +1,10 @@
from random import randint
+from django.contrib.auth.models import Group, Permission, User
+from client.models import UserCode, Keys, DocumentType, Document, PersonalData
+from django.db.models import Q
from django.shortcuts import render
-from .models import UserCode
-
# Create your views here.
@@ -19,6 +20,15 @@ def index(request):
break
userCode = UserCode(user=request.user, code=code)
userCode.save()
+
+ documents = Document.objects.filter(user=request.user)
+ out = []
+ for i in documents:
+ out.append(i)
+ context = {
+ "docs": out,
+ "empty": len(out) == 0,
+ }
return render(request, 'client/index.html', context)
@@ -33,3 +43,40 @@ def approve(request):
return render(request, 'client/approve.html', context)
else:
return render(request, 'client/index.html', context)
+
+
+def create(request):
+ context = {}
+ if request.user.is_authenticated:
+ parent_group = request.user.groups.values_list('name', flat=True)[
+ 0]
+ group = Group.objects.get(name=parent_group)
+ public_types = DocumentType.objects.filter(
+ Q(group_private=False) | Q(group=group))
+ out = []
+ for doc in public_types:
+ out.append(doc)
+
+ context = {'docs': out}
+ if request.method == "POST":
+ usercode = UserCode.objects.filter(user=request.user)[0]
+ code = 0
+ status = 0
+ document_type = DocumentType.objects.get(
+ id=request.POST["doctype"])
+ personal_data = PersonalData(parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country,
+ nationality=usercode.nationality, born_date=usercode.born_date, home_phone=usercode.home_phone, phone=usercode.phone)
+ personal_data.save()
+
+ while (True):
+ code = randint(100000, 999999)
+ if len(Document.objects.filter(code=code)) == 0:
+ break
+
+ document = Document(
+ user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data)
+ document.save()
+
+ return render(request, 'client/doc_create.html', context)
+ else:
+ return render(request, 'client/index.html', context)