Defined functions for new import feature
This commit is contained in:
@@ -77,6 +77,8 @@ networks:
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
|
- Default value of association "Pagamento effettuato"
|
||||||
|
- import of storage, computers, courses.
|
||||||
- Tables Sorting with filters
|
- Tables Sorting with filters
|
||||||
|
|
||||||
# Licence
|
# Licence
|
||||||
|
|||||||
@@ -202,7 +202,6 @@ class StudentForm(forms.ModelForm):
|
|||||||
|
|
||||||
class AssignmentComputerForm(forms.Form):
|
class AssignmentComputerForm(forms.Form):
|
||||||
choice= (
|
choice= (
|
||||||
("", "Seleziona il motivo"),
|
|
||||||
("deposit_paid", "Pagamento Effettuato"),
|
("deposit_paid", "Pagamento Effettuato"),
|
||||||
("replacement", "Sostitutivo"),
|
("replacement", "Sostitutivo"),
|
||||||
("temporary", "Temporaneo")
|
("temporary", "Temporaneo")
|
||||||
@@ -216,7 +215,6 @@ class AssignmentComputerForm(forms.Form):
|
|||||||
|
|
||||||
class AssignmentAccessoryForm(forms.Form):
|
class AssignmentAccessoryForm(forms.Form):
|
||||||
choice= (
|
choice= (
|
||||||
("", "Seleziona il motivo"),
|
|
||||||
("needed", "Necessario"),
|
("needed", "Necessario"),
|
||||||
("replacement", "Sostitutivo"),
|
("replacement", "Sostitutivo"),
|
||||||
("temporary", "Temporaneo")
|
("temporary", "Temporaneo")
|
||||||
@@ -229,7 +227,6 @@ class AssignmentAccessoryForm(forms.Form):
|
|||||||
|
|
||||||
class ReturnComputerDateForm(forms.Form):
|
class ReturnComputerDateForm(forms.Form):
|
||||||
choice = (
|
choice = (
|
||||||
("", "Seleziona il motivo"),
|
|
||||||
("student_resigned", "Studente Dimesso"),
|
("student_resigned", "Studente Dimesso"),
|
||||||
("damaged", "Danneggiato"),
|
("damaged", "Danneggiato"),
|
||||||
("not_necessary", "Non più necessario")
|
("not_necessary", "Non più necessario")
|
||||||
@@ -239,7 +236,6 @@ class ReturnComputerDateForm(forms.Form):
|
|||||||
|
|
||||||
class ReturnAccessoryDateForm(forms.Form):
|
class ReturnAccessoryDateForm(forms.Form):
|
||||||
choice = (
|
choice = (
|
||||||
("", "Seleziona il motivo"),
|
|
||||||
("not_necessary", "Non più necessario"),
|
("not_necessary", "Non più necessario"),
|
||||||
("damaged", "Danneggiato"),
|
("damaged", "Danneggiato"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from datetime import datetime
|
|||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.views.defaults import bad_request
|
from django.views.defaults import bad_request
|
||||||
|
|
||||||
from ..forms import CSVUpdateForm
|
from ..forms import Bundle, CSVUpdateForm
|
||||||
from ..models import Computer, Accessory, Student, Course, Record, Ticket
|
from ..models import Computer, Accessory, Student, Course, Record, Ticket
|
||||||
|
|
||||||
from django.contrib.auth.decorators import user_passes_test, login_required
|
from django.contrib.auth.decorators import user_passes_test, login_required
|
||||||
@@ -98,6 +98,92 @@ def import_students(request):
|
|||||||
"form": form
|
"form": form
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def import_bundle(request):
|
||||||
|
if request.method == "POST":
|
||||||
|
form = CSVUpdateForm(request.POST, request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
csv_file = request.FILES["file"]
|
||||||
|
if not csv_file.endswith(".csv"):
|
||||||
|
form = CSVUpdateForm()
|
||||||
|
err = True
|
||||||
|
return render(request, "gestionale/import/bundle.html",{
|
||||||
|
"err": err, "form": form
|
||||||
|
})
|
||||||
|
try:
|
||||||
|
record = Record()
|
||||||
|
record.date = datetime.now().date()
|
||||||
|
record.action = "import"
|
||||||
|
record.product = "bundle"
|
||||||
|
record.user = request.user
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
csv_data = csv_file.read().decode("utf-8").splitlines()
|
||||||
|
reader = csv.DictReader(csv_data)
|
||||||
|
for row in reader:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
if request.method == "POST":
|
||||||
|
form = CSVUpdateForm(request.POST, request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
csv_file = request.FILES["file"]
|
||||||
|
if not csv_file.endswith(".csv"):
|
||||||
|
form = CSVUpdateForm()
|
||||||
|
err = True
|
||||||
|
return render(request, "gestionale/import/bundle.html",{
|
||||||
|
"err": err, "form": form
|
||||||
|
})
|
||||||
|
try:
|
||||||
|
record = Record()
|
||||||
|
record.date = datetime.now().date()
|
||||||
|
record.action = "import"
|
||||||
|
record.product = "bundle"
|
||||||
|
record.user = request.user
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
csv_data = csv_file.read().decode("utf-8").splitlines()
|
||||||
|
reader = csv.DictReader(csv_data)
|
||||||
|
for row in reader:
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
passpass
|
||||||
|
pass
|
||||||
|
|
||||||
|
def import_computers(request):
|
||||||
|
if request.method == "POST":
|
||||||
|
form = CSVUpdateForm(request.POST, request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
csv_file = request.FILES["file"]
|
||||||
|
if not csv_file.endswith(".csv"):
|
||||||
|
form = CSVUpdateForm()
|
||||||
|
err = True
|
||||||
|
return render(request, "gestionale/import/computers.html",{
|
||||||
|
"err": err, "form": form
|
||||||
|
})
|
||||||
|
try:
|
||||||
|
record = Record()
|
||||||
|
record.date = datetime.now().date()
|
||||||
|
record.action = "import"
|
||||||
|
record.product = "computers"
|
||||||
|
record.user = request.user
|
||||||
|
record.save()
|
||||||
|
|
||||||
|
csv_data = csv_file.read().decode("utf-8").splitlines()
|
||||||
|
reader = csv.DictReader(csv_data)
|
||||||
|
for row in reader:
|
||||||
|
bundle= get_object_or_404(Bundle, id = row["Id Bundle"])
|
||||||
|
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def import_accessories(request):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def import_courses(request):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@user_passes_test(lambda u: u.is_superuser or u.is_staff )
|
@user_passes_test(lambda u: u.is_superuser or u.is_staff )
|
||||||
def toggle_course(request, id):
|
def toggle_course(request, id):
|
||||||
course = get_object_or_404(Course, id=id)
|
course = get_object_or_404(Course, id=id)
|
||||||
|
|||||||
Reference in New Issue
Block a user