Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
3
¤[\òCã@sìddlmZddlmZmZmZddlmZmZddl    m
Z
m Z ddl m Z ddlmZddlmZmZmZdd    lmZdd
lmZdd lmZdd lmZdd lmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%Z%ddl    m&Z&ddl'm(Z(m)Z)ddl*Z*ddl+Z+ddl,m-Z-ddl.m/Z/m0Z0ddlm1Z1ddl2jZ3ddl4m5Z6ddl7m8Z8ddl9Z9ddl:Z;ddl<m=Z=m>Z>dd„Z?eeedd„ƒƒƒZ@eeddGd d!„d!eejAƒƒZBeeddGd"d#„d#eejCƒƒZDeeddGd$d%„d%eejEejFƒƒZGeeddGd&d'„d'eejEƒƒZHeeed(d)„ƒƒƒZIeeed*d+„ƒƒƒZJeed,d-„ƒƒZKeeed.d/„ƒƒƒZLeeeed0d1„ƒƒƒƒZMeeeed2d3„ƒƒƒƒZNeeed4d5„ƒƒƒZOeeed6d7„ƒƒƒZPGd8d9„d9ƒZQd:d;„ZReed<d=„ƒƒZSeed>d?„ƒƒZTdS)@é)Úreverse)ÚrenderÚget_object_or_404ÚHttp404é)ÚExamÚGeneratedPaper)Ú HttpResponseÚHttpResponseRedirect)Úloader)Úgeneric)ÚExamFormÚ
UploadFormÚ GenerateForm)Úlogin_required)Ústaff_member_required)Úmethod_decorator)ÚLoginRequiredMixin)Úajax)Ú csrf_exempt)Úsettings)ÚProblemÚ ProblemGroupN)Ú JsonResponse)ÚScanÚ ProblemReport)ÚUser)Úmatrix2old_formatÚold_format2matrix)Úredirect)Ú
BerkiParse)Ú ProblemSource)Ú
itemgetterÚ
attrgetterc    Cs8y"tjj|d}dj|j|jƒ}Wnd}YnX|S)N)Úusernamez{} {}Ú)rÚobjectsÚgetÚformatÚ
first_nameÚ    last_name)ÚsidÚuserÚ    user_data©r.ú;/home/samo/programiranje/django/sizif-web/aoi/exam/views.pyÚget_username_by_sid!s 
r0cCs@tjtjdƒtt|d}tjdƒ}tjj    |ddj
ƒ}dd„|Dƒ}t |t dƒd    }g}x@|D]8}t |jƒ}|dkrˆ|j||jd
œƒt |d d „d    }q`Wg}    x8|D]0}tj|jƒ}
t|
d ƒr¦|    j|j|jdœƒq¦Wg} xB|D]:}tjj    |dj
ƒ} x"| D]} | j|j|jdœƒqWqäW|||    | dœ}t|j||ƒƒS)Nr%)Úpkzexam/postprocess.htmlr)ÚexamÚpage_nocSsg|]}|j|jdœ‘qS))Ú
student_idÚscan_id)r4r1)Ú.0Úscanr.r.r/ú
<listcomp>4szpostprocess.<locals>.<listcomp>r4)Úkey)Ú student_namer5cSstj|dƒS)Nr:)ÚlocaleÚstrxfrm)Úkr.r.r/Ú<lambda><szpostprocess.<locals>.<lambda>Úerrors)r4r5)r7)Ústudent_id_listÚ    name_listÚbad_listÚ report_list)r;Ú    setlocaleÚLC_ALLrrr Ú get_templaterr&ÚfilterÚallÚsortedr"r0r4Úappendr1ÚjsonÚloadsÚ    ocr_debugÚlenrr    r)Úrequestr1r2ÚtemplateÚscansr@rAr7r$rBÚdebugrCÚrepÚrÚcontextr.r.r/Ú postprocess+s6 
 
 
 
 
 
rVÚdispatch)Únamec@seZdZeZdZdd„ZdS)Ú ExamListViewzexam/index.htmlcCstjj|jjdS)N)r,)rr&rGrOr,)Úselfr.r.r/Ú get_querysetYszExamListView.get_querysetN)Ú__name__Ú
__module__Ú __qualname__rÚmodelÚ template_namer[r.r.r.r/rYTsrYc@seZdZeZdZdd„ZdS)Ú ExamNewViewzexam/exam_new.htmlcCs tdfdS)NÚexamlist)Úargs)r)rZr.r.r/Úget_success_urlcszExamNewView.get_success_urlN)r\r]r^r Ú
form_classr`rdr.r.r.r/ra^sracs0eZdZeZeZdZdd„Z‡fdd„Z    ‡Z
S)ÚExamDetailViewzexam/exam_detail.htmlcCstd|jjfdS)NÚ
examdetail)rc)rÚobjectr1)rZr.r.r/rdnszExamDetailView.get_success_urlc stt|ƒjf|Ž}d|d<|S)NzThis is just some dataÚ    some_data)ÚsuperrfÚget_context_data)rZÚkwargsrU)Ú    __class__r.r/rkqszExamDetailView.get_context_data) r\r]r^rr_r rer`rdrkÚ __classcell__r.r.)rmr/rfhs
rfc@s eZdZeZeZdZdd„ZdS)ÚGenerateExamViewzexam/generate.htmlcCs tdfdS)Nrb)rc)r)rZr.r.r/rd€sz GenerateExamView.get_success_urlN)    r\r]r^rr_r rer`rdr.r.r.r/rozsroc Csàtt|d}ytjj|djƒ}Wn YnXddddddddddddœ }xF|D]>}|jƒ\}}|dkrnd}|ttj    |dƒdƒd7<qRWt
t |j ƒƒƒ}t
t |j ƒƒƒ}    tjdƒ}
d|i||    |d    œ} t|
j| |ƒƒS)
N)r1)r2r) ré
ééé(é2é<éFéPéZédrprzexam/statistics.htmlÚid)r2ÚkeysÚvaluesZfullexam)rrrr&rGrHÚgradeÚintÚnpÚfloorÚstrÚlistr{r|r rFr    r) rOr1r2rQÚbinsr7ÚpÚgr{r|rPrUr.r.r/Ú
statistics…s  
 &
r†c Csytjj|d}Wnt‚YnXytjj|ddjƒ}Wnt‚YnXg}x8|D]0}|jƒ\}}|j}t    |ƒ}    |j
||    ||gƒqXWt j t j dƒt|dd„d}d}
x0|D](}|
d    j|d
|d|d |d ƒ}
q´Wd } t|
| dd} tt|
ddƒ| d<d| d<| S)N)r1r)r2r3r%cSstj|dƒS)Nr)r;r<)r=r.r.r/r>¸szget_exam_csv.<locals>.<lambda>)r9z+SID, Student Name, Grade, Grade percentage
z {},{},{},{}
rééztext/csvzutf-8)Ú content_typeÚcharsetÚutf8)ÚencodingzContent-Lengthzinline; filename=statistics.csvzContent-Disposition)rr&r'rrrGrHr}r4r0rJr;rDrErIr(r    rNÚbytes) rOr1r2rQZgradesr7r„r…r+r$ÚretvalÚmimetypeÚresponser.r.r/Ú get_exam_csv›s0
 
 
 
(r‘cCs2||jd<ttjj|dƒ|jd<ttdfdƒS)NÚ selected_exam)r1Zselected_exam_namerb)rc)Úsessionrrr&r'rr)rOr1r.r.r/Ú
setdefaultÅs
r”c    Cs^ddl}tjj|d}|jjdƒ}ytjj|d}Wnd}YnX|j|ƒ|jddiƒS)Nr)r1r’ÚstatusÚok)rKrr&r'r“rÚ add_problemrL)rOr1rKÚproblemÚexam_idr2r.r.r/ÚaddProblemToExamÏs 
 
ršcCs,ddl}dd|ii}t|j|jdƒƒ|S)Nrzinner-fragmentsz#testÚdata)rKÚprintrLÚPOST)rOr1rKr›r.r.r/Ú saveGroupingÝs ržcCsZytjj|dd}WntdƒtddiƒStjj|jdjƒjdƒ}tt    |ƒƒg}x|D]}|t
|j ƒ}q`Wt |ƒ}t|ƒd}x0t |ƒD]$\}}    |d    j|d|    j|dƒ7}q”Wtj|jƒ}
y$tjj|jd
} d j| j| jƒ} Wnd} YnX|jƒ\} }|j|
d || |jd t|jƒdt|jƒd||t |jj ƒ| ddœ }t|ƒS)Nr)r1r3zCANNOT FIND PAPER IDÚvpisnaÚERROR)Úpaperr3r%zC<input type='button' value='{}' onclick='load_image_page({},{})' />)r$z{} {}Úqrz<a href="/exam/show_image/z/1"><img src="/exam/show_image/z&/1" width=800 height=600 border=0></a>) rŸZcrtnaZocenaZprocentZ opispritozbeZslikaZpagesÚodgovoriZpravilniZimeZpritozba)rr&r'rœrrGr¡rHÚorder_byrNÚevalÚ answer_matrixrÚ    enumerater(r1rKrLrMrr4r)r*r}rrz)rOr1r7Zsubscansr¦ÚssÚanswersZsubpagesÚirzZ    debugdatar,r-Ú
percentager}r›r.r.r/Ú load_valuesîsF  
 
 
r¬c
CsXytjj|dd}WntddiƒS|jd|_t|jdƒ|_|jƒtddiƒS)Nr)r1r3rŸr r£ÚOK)    rr&r'rÚGETr4rr¦Úsave)rOr1r7r.r.r/Ú save_values!s  r°c CsŒtjj||djj}tjjtj    |ƒ}tjj
|ƒr„t |dƒD}t j |ƒ}t|jƒ|d}tj|ƒj|d<dtjj|ƒ|d<|SQRXt‚dS)N)r1r3Úrb)r‰zContent-Lengthzinline; filename=zContent-Disposition)rr&r'Ú
scan_imagerXÚosÚpathÚjoinrÚ
MEDIA_ROOTÚexistsÚopenÚ    mimetypesÚ
guess_typer    ÚreadÚstatÚst_sizeÚbasenamer)rOr1ZpagenoÚfilenameÚ    file_pathÚfhZ file_mimetyperr.r.r/Ú
show_image0s  
 
rÂc@sJeZdZdZddd„Zdd„Zdd    „Zd
d „Zd d „Zdd„Z    dd„Z
dS)Ú    DirectoryzN
    Class deals with the paths where the simulation is run and data is stored.
    Ú.r%cCs||_||_dS)z«Initialization Directory() takes two optional parameters, namely maindir and simdir. Defaults to current directory. It sets local variables maindir and simdir accordingly.N)ÚmaindirÚsimdir)rZrÅrÆr.r.r/Ú__init__GszDirectory.__init__cCstjj|j|jƒS)z
        Method returns string of path where the data is stored. It combines values of maindir and simdir as maindir/simdir on Unix.
        )r³r´rµrÅrÆ)rZr.r.r/ÚfullpathMszDirectory.fullpathcCs |jƒ}tjj|ƒrdSdSdS)zi Method checks whether the directory  specified by fullpath() exists. It return True/False on completion.TFN)rÈr³r´r·)rZr´r.r.r/r·Ss zDirectory.existsc    Cs@ytj|jƒƒWn(td|jƒdƒtdƒYnXdS)zV Method make() creates directory. If it fails it exits the program with error message.zCannot make directory Ú
rN)r³ÚmakedirsrÈrœÚexit)rZr.r.r/Úmake[s zDirectory.makecCs |jƒdkr|jƒdSdSdS)z?Method makeifnotexist() creates directory if it does not exist.rTFN)r·rÌ)rZr.r.r/Úmakeifnotexistds zDirectory.makeifnotexistc    CsH|jƒrDytj|jƒƒWn(td|jƒdƒtdƒYnXdS)zKMethod remove() removes directory recursively. WARNING! No questions asked.zCannot remove directory rÉrN)r·r³ÚrmdirrÈrœrË)rZr.r.r/ÚremovelszDirectory.removec    Cs8ytj|jƒƒWn td|jƒdƒYnXdS)z¡
        Method goto() moves current directory to the one specified by fullpath(). WARNING: when using the relative paths, do not call this function multiple times.
        zCannot go to directory rÉN)r³ÚchdirrÈrœ)rZr.r.r/Úgotovs
zDirectory.gotoN)rÄr%) r\r]r^Ú__doc__rÇrÈr·rÌrÍrÏrÑr.r.r.r/rÃBs
    
rÃc Csttjjtjdƒt|jƒƒ}|jƒt|ƒ}|j    dƒd }t
tjj|j ƒ|ƒdƒ"}x|j ƒD]}|j |ƒq^WWdQRX|dkrd}t
tjj|j ƒ|ƒddd    }|jƒ}WdQRXytjj|d
}    WnDt|d
}    ||    _|    jƒt|d d }
|
jƒ|
jj|    ƒYnX|j|    ƒdS)NZexamsrÄrzwb+Útxtr%rTzutf-8)rŒ)ÚtitleT)rÔÚproblemhomegroupéÿÿÿÿ)rÃr³r´rµrÚBASE_DIRrr1rÍÚsplitr¸rÈÚchunksÚwriter»rr&r'Úcontentr¯rr˜Úaddr—) Úfr2r´r¿Ú    extensionÚ destinationÚchunkrÛÚfdr„r…r.r.r/Úhandle_uploaded_file„s*
 
 râcCsztt|d}|jdkr^t|j|jƒ}|jƒrLx|jjdƒD]}t||ƒq:Wt    t
d|fdƒStƒ}||dœ}t |d|ƒS)N)r1rÚ
file_fieldrg)rc)Úformr2zexam/exam_upload.html) rrÚmethodrrÚFILESÚis_validÚgetlistrâr
rr)rOr1r2rärÝrUr.r.r/Ú upload_filežs 
 
réc    CsXtt|d}tjdƒ}tƒ}d}|jdkrt|jƒ}|jƒr|j}|jj    ddƒ}|jj    ddƒdkrjd    nd}d
j
|j |j |j ƒ|jjd ƒ|j j|j jj|j|jd|j jjd œ}|j}    |    dk    rÜ|    d krÜdd„|jjdƒDƒ}    tj||    t|ƒtjjtjdƒd}
g|
_xl|jjƒD]^} g} x>| j jƒD]0} t!| j"ƒ}|j#ƒ| j$| jt%|ddœƒq$W|
jj$| j&| dœƒqW|
j'ƒ|
j(ƒ|_)|
j*ƒ}t+j,j-|dj.ƒxZt/t0||
j1ƒƒD]F\}\}}t+ƒ}||_2|j3dk    rà|j3d|_3||_4||_5|j6ƒq°W|rd    |_7nd|_7|j6ƒtƒ}|j)|j8d<|j7|j8d<||j8d<||dœ}t9|j:||ƒƒS)N)r1zexam/generate.htmlrrZnumber_of_testsÚfinalFÚonTz{} iz predmeta {} ({})z
%d. %m. %Y)Z
exam_titleÚdateZ faculty_nameÚ
faculty_idr™Ú    last_lineZ start_numberZ sid_prefillr%cSsg|]}|jdƒ‘qS)ú,)rØ)r6Z student_liner.r.r/r8Ñsz!generate_view.<locals>.<listcomp>rÉZ textemplates)rÚ student_listZnumber_of_papersrP)Úparser)rzZ parsed_source)ÚamountZproblems)r2rÚ generated_tex)rär2rÖ);rrr rFrrårrçÚ cleaned_datar'r(ÚtypeÚsubjectÚ
study_typerìÚstrftimeÚfacultyr1rîÚsid_maskrðrØÚaoi_examr~r³r´rµrr×Zproblem_source_listÚ problem_grouprHr˜ÚParserrÛZ parseSectionsrJr!ròZgeneratePapersZexam_to_templateróZ get_answersrr&rGÚdeleter§ÚzipZ
paper_listr¦r4Ú    serial_nor2r¯Ú    finalizedÚinitialr    r)rOr1r2rPräZtest_noÚcdZis_finalZ exam_settingsrðZaoiexamZproblem_groupsZproblem_in_group_listZproblem_data_sourceZparr¦ZserZ answer_paperr¡r…rUr.r.r/Ú generate_view²sz 
 
 
 
 
 
 
 
r)UÚ django.urlsrÚdjango.shortcutsrrrÚmodelsrrÚ django.httpr    r
Údjango.templater Z django.viewsr Úformsr rrÚdjango.contrib.auth.decoratorsrÚ%django.contrib.admin.views.decoratorsrÚdjango.utils.decoratorsrÚdjango.contrib.auth.mixinsrZdjango_ajax.decoratorsrÚdjango.views.decorators.csrfrÚ django.confrZproblem.modelsrrr³rZ scan.modelsrrrKr¹Údjango.contrib.auth.modelsrZ exam.modelsrrrZ aoi_gen.ExamrûZaoi_gen.BerkiParser rýZaoi_gen.Problemr!r;ÚnumpyrÚoperatorr"r#r0rVÚListViewrYÚ
CreateViewraÚ
UpdateViewÚ
DetailViewrfror†r‘r”ršržr¬r°rÂrÃrârérr.r.r.r/Ú<module>sŽ             
 
'          
(     0 B