Private
Public Access
1
0

standards can be downloaded and deactivated

This commit is contained in:
Sander Roosendaal
2020-05-28 06:16:59 +02:00
parent 7f402225b8
commit 98efddb8d7
7 changed files with 163 additions and 46 deletions

View File

@@ -40,7 +40,7 @@ def courses_view(request):
def standards_view(request):
r = getrower(request.user)
standards = StandardCollection.objects.all().order_by("name")
standards = StandardCollection.objects.filter(active=True).order_by("name")
# add search processing
query = request.GET.get('q')
@@ -521,11 +521,57 @@ def course_upload_view(request):
else:
return {'result':0}
# Standards deactivate
@login_required()
def standard_deactivate_view(request,id=0):
is_ajax = False
if request.is_ajax():
is_ajax = True
r = getrower(request.user)
try:
collection = StandardCollection.objects.get(id=id)
except StandardCollection.DoesNotExist:
raise Http404("Does not exist")
if request.user != collection.manager:
raise PermissionDenied("You cannot change this set of time standards")
collection.active = False
collection.save()
url = reverse(standards_view)
return HttpResponseRedirect(url)
def standards_download_view(request,id=0):
try:
collection = StandardCollection.objects.get(id=id)
except StandardCollection.DoesNotExist:
raise Http404("Does not exist")
filename = 'Standard Times {name} {id} {date}.csv'.format(
id=id,
name=collection.name,
date=timezone.now().strftime("%Y-%m-%d %H:%M:%S %Z")
)
standards = CourseStandard.objects.filter(standardcollection=collection)
df = pd.DataFrame.from_records(standards.values())
response = HttpResponse(df.to_csv())
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
response['Content-Type'] = 'application/octet-stream'
return response
# Standards upload
@login_required()
def standards_upload_view(request,id=0):
is_ajax = False
print(id,'aap')
if request.is_ajax():
is_ajax = True
r = getrower(request.user)