Commit d7a749e5 authored by BrunoMeyer's avatar BrunoMeyer
Browse files

#229: Fix bugs

- Change url ``/adega/admin`` to ``/admin``
- Fix bug when downloading .zip files with utf-8 when nginx container is enabled
- Remove hardcoded ``csv_data_file.csv`` from json_to_csv module
- Rename ``makefile`` to ``Makefile``
parent 85800cec
Pipeline #23594 passed with stage
in 3 minutes and 10 seconds
......@@ -29,5 +29,5 @@ urlpatterns = [
url(r'^logout/$', views.logout, name='logout'),
url(r'^adega/admin/', admin.site.urls),
url(r'^admin/', admin.site.urls),
]
......@@ -8,11 +8,12 @@ from pathlib import Path
class AdmissionConversor:
def __init__(self, submission_path, not_allowed_keys=None,
min_year=None, max_year=None):
min_year=None, max_year=None,
submission_raw_data_fname="csv_data_file.csv"):
admission_dir = os.path.join(submission_path, "admissions")
self.submission_path = submission_path
self.admission_dir = admission_dir
self.submission_raw_data_fname = submission_raw_data_fname
if not_allowed_keys is None:
self.not_allowed_keys = ["evasion_per_semester"]
......@@ -24,7 +25,8 @@ class AdmissionConversor:
self.max_year = max_year
def init_min_max_year(self):
df = pd.read_csv(os.path.join(self.submission_path,"csv_data_file.csv"))
df = pd.read_csv(os.path.join(self.submission_path,
self.submission_raw_data_fname))
self.min_year = int(df["ANO_ATIV_CURRIC"].min())
self.max_year = int(df["ANO_ATIV_CURRIC"].max())
......
......@@ -8,10 +8,12 @@ from pathlib import Path
class CourseConversor:
def __init__(self, submission_path, not_allowed_keys=None,
min_year=None, max_year=None):
min_year=None, max_year=None,
submission_raw_data_fname="csv_data_file.csv"):
course_dir = os.path.join(submission_path, "courses")
self.submission_path = submission_path
self.course_dir = course_dir
self.submission_raw_data_fname = submission_raw_data_fname
if not_allowed_keys is None:
......@@ -24,7 +26,8 @@ class CourseConversor:
self.max_year = max_year
def init_min_max_year(self):
df = pd.read_csv(os.path.join(self.submission_path,"csv_data_file.csv"))
df = pd.read_csv(os.path.join(self.submission_path,
self.submission_raw_data_fname))
self.min_year = int(df["ANO_ATIV_CURRIC"].min())
self.max_year = int(df["ANO_ATIV_CURRIC"].max())
......
......@@ -8,11 +8,12 @@ from collections import defaultdict
class StudentConversor:
def __init__(self, submission_path, not_allowed_keys=None,
min_year=None, max_year=None):
min_year=None, max_year=None,
submission_raw_data_fname="csv_data_file.csv"):
student_dir = os.path.join(submission_path, "students")
self.submission_path = submission_path
self.student_dir = student_dir
self.submission_raw_data_fname = submission_raw_data_fname
if not_allowed_keys is None:
self.not_allowed_keys = ["evasion_per_semester"]
......@@ -24,7 +25,8 @@ class StudentConversor:
self.max_year = max_year
def init_min_max_year(self):
df = pd.read_csv(os.path.join(self.submission_path,"csv_data_file.csv"))
df = pd.read_csv(os.path.join(self.submission_path,
self.submission_raw_data_fname))
self.min_year = int(df["ANO_ATIV_CURRIC"].min())
self.max_year = int(df["ANO_ATIV_CURRIC"].max())
......
......@@ -44,7 +44,7 @@ class ZipUtilities:
elif os.path.isdir(full_path):
self.addFolderToZip(zip_file, full_path)
def main(submission_path, zip_path):
def main(submission_path, submission_raw_data_fname, zip_path):
'''
Create a zip file with the summary of json analysis
'''
......@@ -52,19 +52,24 @@ def main(submission_path, zip_path):
course_csv_path = os.path.join(submission_path,"course.csv")
student_csv_path = os.path.join(submission_path,"student.csv")
admission = AdmissionConversor(submission_path)
admission = AdmissionConversor(
submission_path,
submission_raw_data_fname=submission_raw_data_fname)
data_admission,header_admission = admission.get_admission_as_matrix()
df_admission = pd.DataFrame(data_admission)
df_admission.columns = header_admission
df_admission.to_csv(admission_csv_path, index=False)
course = CourseConversor(submission_path)
course = CourseConversor(
submission_path,
submission_raw_data_fname=submission_raw_data_fname)
data_course,header_course = course.get_course_as_matrix()
df_course = pd.DataFrame(data_course)
df_course.columns = header_course
df_course.to_csv(course_csv_path, index=False)
student = StudentConversor(submission_path)
student = StudentConversor(submission_path,
submission_raw_data_fname=submission_raw_data_fname)
data_student,header_student = student.get_student_as_matrix()
df_student = pd.DataFrame(data_student)
df_student.columns = header_student
......
......@@ -23,7 +23,9 @@ def analyze(submission, debug=True, create_csv_data=True):
submission.relative_year, submission.relative_semester)
if create_csv_data:
parse_to_csv(path, submission.zip_path())
parse_to_csv(path,
submission.csv_data_file.path,
submission.zip_path())
submission.set_done(round(time.clock() - start_time))
......
......@@ -17,26 +17,32 @@ from guardian.decorators import permission_required_or_403
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse, Http404
from django.utils.text import slugify
import os
import urllib.parse
def download(request, submission_id):
submission_id = int(submission_id)
submission = Submission.objects.get(id=submission_id)
# if (request.user != submission.author.user) and not request.user.is_superuser:
# if (request.user != submission.author.user):
if not submission.download_allowed(request.user):
raise PermissionDenied
file_path = submission.zip_path()
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/zip")
# response = HttpResponse(fh.read())
print(os.path.basename(file_path))
response['Content-Disposition'] = 'inline; filename="{}"'.format(
os.path.basename(file_path))
# response['Content-Disposition'] = "inline; filename=a\ b.zip"
response = HttpResponse(
fh.read(),
content_type='application/zip charset=utf-8')
content_disposition = \
"attachment; " \
"filename={ascii_filename};" \
"filename*=UTF-8''{utf_filename}".format(
ascii_filename=slugify(os.path.basename(file_path)),
utf_filename=urllib.parse.quote(
os.path.basename(file_path).encode("utf-8")))
response['Content-Disposition'] = content_disposition
return response
raise Http404
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment