summaryrefslogtreecommitdiff
path: root/kpov_judge/web
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-16 17:44:42 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-02-16 19:07:33 +0100
commit448ff2cd1168ccee81f848238170ad156a3684b4 (patch)
tree986de33116f7b313b61a1807e402222298de0f1b /kpov_judge/web
parentdd9eaef3b467ffe1693ceeee4a0398d191945faf (diff)
Create disk images in multiple formats
Refactor some code in create_disk_images.oy into a »prepare_disks« function that creates disk images in the given format for one task. Store paths to images in multiple formats in the database and update the front-end.
Diffstat (limited to 'kpov_judge/web')
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py16
-rw-r--r--kpov_judge/web/kpov_judge/templates/task_greeting.html36
2 files changed, 34 insertions, 18 deletions
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index c0bf885..9e4e24a 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -255,11 +255,17 @@ def task_greeting(class_id, task_id, lang):
}]
except Exception as e:
instructions = str(e)
+
computer_list = list(db.student_computers.find({'class_id': class_id, 'task_id': task_id, 'student_id': student_id}))
- backing_images = set()
+
+ backing_files = collections.defaultdict(set)
for computer in computer_list:
- for disk_url in computer.get('disk_urls', []):
- backing_images |= set(disk_url['backing'])
+ if 'disk_urls' not in computer:
+ continue
+ for name, disk in computer['disk_urls'].items():
+ for fmt in disk['formats']:
+ backing_files[fmt] |= set(disk[fmt][1:])
+
if request.args.get('narediStack', 'false') == 'true':
#db.student_tasks.update({'task_id': task_id, 'student_id': student_id}, {'$set': {'create_openstack': True}}, upsert = True)
openstackCreated = False # Spremeni na True, ko odkomentiras zgornjo vrstico.
@@ -285,8 +291,8 @@ def task_greeting(class_id, task_id, lang):
disk_base_url='/'.join([app.config['STUDENT_DISK_URL'], student_id, class_id, task_id, '']),
class_id=class_id,
task_id=task_id,
- computers=computer_list,
- backing_images=sorted(backing_images),
+ computers=sorted((c for c in computer_list if 'disk_urls' in c), key=lambda c: c['name']),
+ backing_files={fmt: sorted(images) for fmt, images in backing_files.items()},
lang='sl' if lang == 'si' else lang, # TODO s/si/sl in all tasks (and maybe elsewhere)
openstack=openstackCreated,
instructions=jinja2.Template(instructions),
diff --git a/kpov_judge/web/kpov_judge/templates/task_greeting.html b/kpov_judge/web/kpov_judge/templates/task_greeting.html
index 49288e3..ee27853 100644
--- a/kpov_judge/web/kpov_judge/templates/task_greeting.html
+++ b/kpov_judge/web/kpov_judge/templates/task_greeting.html
@@ -56,37 +56,47 @@ section > ul {
<section class="data">
<section class="disks">
<h1>{{ _('Računalniki') }}</h1>
+{% if computers %}
<p>
-{{ _('Slike diskov za to nalogo:') }}
+{{ _('Za GNS3 uporabite slike v formatu qcow2 ali VMDK, za katere rabite še zaledne datoteke (angl. <em lang="en">backing files</em>). VirtualBox ne podpira zalednih datotek, zato so slike VDI precej večje. Namesto prenosa lahko slike VDI <a href="">dobite iz formata qcow2 ali VMDK</a>.') }}
{% for c in computers %}
<ul>
<li>{{c['name']}}
- {% if 'disk_urls' in c %}
<ul>
- {% for u in c['disk_urls'] %}
- <li><a href="{{disk_base_url+u['file']}}">{{u['name']}}</a>
+ {% for name, disk in c['disk_urls'].items() %}
+ <li>{{name}} [ {% for fmt in disk['formats'] %}<a href="{{disk_base_url+disk[fmt][0]}}">{{fmt}}</a> {% endfor %}]
+ {% else %}
{% endfor %}
</ul>
- {% else %}
- <br>{{ _('Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.') }}
- {% endif %}
</ul>
{% endfor %}
+{% if backing_files %}
<section>
-{% if backing_images %}
-<h1>{{ _('Osnovne slike') }}</h1>
+<h1>{{ _('Zaledne datoteke') }}</h1>
<p>
-{{ _('Te slike so enake za vse naloge. Prenesite samo tiste, ki jih še nimate.') }}
+{{ _('Vsako od spodnjih slik prenesete samo pri prvi nalogi, v kateri se pojavi. Vse datoteke morajo biti v istem imeniku.') }}
<ul>
-{% for b in backing_images %}
- <li><a href="{{disk_base_url+b}}">{{b}}</a></li>
+{% for fmt, images in backing_files.items() %}
+ {% if images %}
+ <li>{{fmt}}
+ <ul>
+ {% for image in images %}
+ <li><a href="{{disk_base_url+image}}">{{image}}</a></li>
+ {% endfor %}
+ </ul>
+ </li>
+ {% endif %}
{% endfor %}
</ul>
-{% endif %}
</section>
+{% endif %}
+
+{% else %}
+ <p>{{ _('Slike navideznih diskov so v izdelavi in bodo kmalu na voljo.') }}
+{% endif %}
</section>
<section>