'js/formset.js',
'pybb/js/pybbjs.js',
'fnpdjango/annoy/annoy.js',
+ 'js/checkfile.js',
),
'output_filename': 'compressed/base.js',
},
{% load i18n static %}
{% load fnp_common fnp_share fnp_lang macros %}
{% load compressed static %}
-{% load subdomainurls %}
{% load piwik_tags %}
{% macro title %}{% block title %}{% endblock %}{% endmacro %}
style="position:absolute; opacity: 0.5; top:0; left: -83px; z-index:1000"
-->
{% if request.user.is_authenticated %}
- <a href="{% url 'logout' subdomain=None %}" style="position: absolute; top:5px; right: 10px; font-size: 12px;">Wyloguj</a>
+ <a href="{% url 'logout' %}" style="position: absolute; top:5px; right: 10px; font-size: 12px;">Wyloguj</a>
{% endif %}
<div id="header-top">
<a id="logo" href="/">{% block logo %}<img src="{% static "img/logo-oc.png" %}" alt="Olimpiada Cyfrowa" height="73"/>{% endblock %}</a>
# -*- coding: utf-8 -*-
from django import forms
from django.conf import settings
-from django.core.exceptions import ValidationError
from django.template.defaultfilters import filesizeformat
from stage2.models import Attachment, Mark
model = Attachment
fields = ['file']
- def __init__(self, assignment, file_no, label, *args, **kwargs):
+ def __init__(self, assignment, file_no, label, extensions=None, *args, **kwargs):
prefix = 'att%s-%s' % (assignment.id, file_no)
super(AttachmentForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['file'].label = label
+ if extensions:
+ self.fields['file'].widget.attrs = {'data-ext': '|'.join(extensions)}
+ self.extensions = extensions
def clean_file(self):
file = self.cleaned_data['file']
raise forms.ValidationError(
'Please keep filesize under %s. Current filesize: %s' % (
filesizeformat(settings.MAX_UPLOAD_SIZE), filesizeformat(file.size)))
+ if self.extensions and ('.' not in file.name or file.name.rsplit('.', 1)[1].lower() not in self.extensions):
+ raise forms.ValidationError('Incorrect extension, should be one of: %s' % ', '.join(self.extensions))
return file
def clean_points(self):
points = self.cleaned_data['points']
if points > self.answer.assignment.max_points:
- raise ValidationError('Too many points for this assignment')
+ raise forms.ValidationError('Too many points for this assignment')
if points < 0:
- raise ValidationError('Points cannot be negative')
+ raise forms.ValidationError('Points cannot be negative')
return points
file_descriptions = JSONField(_('file descriptions'))
class Meta:
- ordering = ['deadline']
+ ordering = ['deadline', 'title']
verbose_name = _('assignment')
verbose_name_plural = _('assignments')
--- /dev/null
+$(function() {
+ "use strict";
+ $('input[type=file]').on('change', function () {
+ if (window.FileReader && this.files && this.files[0]) {
+ var ok = true;
+ var name = this.files[0].name;
+ if (this.getAttribute('data-ext')) {
+ var ext = this.getAttribute('data-ext');
+ var re = new RegExp('\\.(' + ext + ')$', 'i');
+ if (!re.exec(name)) {
+ alert('Błędne rozszerzenie! Powinno być jedno z: ' + ext.replace(/\|/g, ', '));
+ ok = false;
+ }
+ }
+ var size = this.files[0].size;
+ if (size > 10 * 1024 * 1024) {
+ alert('Rozmiar pliku nie może przekraczać 10 MB!');
+ ok = false;
+ }
+ if (!ok) {
+ this.form.reset();
+ }
+ }
+ });
+});
{% extends 'base.html' %}
{% load textile_pl from fnp_markup %}
+{% load chunks %}
{% block title %}Drugi etap{% endblock %}
{% block body %}
<h1>Drugi etap Olimpiady Cyfrowej</h1>
+ {% chunk 'stage2_header' %}
+
{% for assignment in assignments %}
<h2>{{ assignment.title }} (do {{ assignment.deadline }})</h2>
<p>{{ assignment.content|textile_pl }}</p>
for assignment in assignments:
assignment.answer = assignment.answer_set.filter(participant=participant).first()
assignment.forms = [
- (AttachmentForm(assignment=assignment, file_no=i, label=label),
+ (AttachmentForm(assignment=assignment, file_no=i, label=label, extensions=ext),
assignment.answer.attachment_set.filter(file_no=i).first() if assignment.answer else None)
- for i, label in enumerate(assignment.file_descriptions, 1)]
+ for i, (label, ext) in enumerate(assignment.file_descriptions, 1)]
return assignments
now = timezone.now()
if assignment.deadline < now:
raise Http404 # TODO za późno
- for i, label in enumerate(assignment.file_descriptions, 1):
+ for i, (label, ext) in enumerate(assignment.file_descriptions, 1):
answer, created = Answer.objects.get_or_create(participant=participant, assignment=assignment)
attachment, created = Attachment.objects.get_or_create(answer=answer, file_no=i)
form = AttachmentForm(
data=request.POST, files=request.FILES,
- assignment=assignment, file_no=i, label=label, instance=attachment)
+ assignment=assignment, file_no=i, label=label, instance=attachment, extensions=ext)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('stage2_participant', args=(participant_id, key)))
attachments_by_file_no = {attachment.file_no: attachment for attachment in attachments}
answer.attachments = [
(desc, attachments_by_file_no.get(i))
- for (i, desc) in enumerate(assignment.file_descriptions, 1)]
+ for (i, (desc, ext)) in enumerate(assignment.file_descriptions, 1)]
if answer == answer_with_errors:
answer.form = form_with_errors
else: