- widget = forms.Textarea(attrs={'readonly':True})
- initial = get_open_answer(answers, exercise)
+ # widget = forms.Textarea(attrs={'readonly':True})
+ widget = TextareaWithLinks(attrs={'readonly': True})
+ links = []
+ qfiles = []
+ for qfield in exercise.get('fields', []):
+ if qfield.get('type') == 'file':
+ qfiles.append((qfield['id'], qfield['caption']))
+ if qfiles:
+ eid = int(exercise['id'])
+ by_tag = {}
+ for att in Attachment.objects.filter(submission=submission, exercise_id=eid).order_by('tag'):
+ by_tag[att.tag] = att.file.url
+ for tag, caption in qfiles:
+ v = by_tag.get(tag)
+ if v:
+ links.append((caption, "file_%s__%s" % (eid, tag), v))
+ initial = get_open_answer(answers, exercise), links