První pokus o upload příloh při nahrávání řešitelova řešení
This commit is contained in:
		
							parent
							
								
									2766bee5e7
								
							
						
					
					
						commit
						f43b0b4da7
					
				
					 4 changed files with 97 additions and 74 deletions
				
			
		|  | @ -33,79 +33,7 @@ | |||
| 
 | ||||
| <hr> | ||||
| 
 | ||||
| {{ prilohy.management_form }} | ||||
| 
 | ||||
| <h4>Soubory s řešením</h4> | ||||
| 
 | ||||
| <p style="text-align: justify">Maximální součet velikostí příloh je cca 49 MB. Pokud je to možné a dává to smysl, pošli nám prosím své řešení ve formátu PDF, ostatní formáty nemusíme umět otevřít.</p> | ||||
| <p style="text-align: justify">Pokud svůj soubor rozumně pojmenuješ, urychlíš opravování a předejdeš tomu, že si nějakého tvého řešení nevšimneme. Například z <code>img_250921_101205.pdf</code> nepoznáme, kterou úlohu jsi odevzdal, zato <code>uloha_3.pdf</code> nebo <code>tema_1.pdf</code>, to už je něco jiného. Případně můžeš využít i poznámku řešitele.</p> | ||||
| 
 | ||||
| <div id="form_set"> | ||||
| {% for form in prilohy.forms %} | ||||
| 	<div class="attachment"> | ||||
| 	{{ form.non_field_errors }} | ||||
| 	{# {{ form.errors }} FIXME: možná tohle chceme zobrazovat? #} | ||||
|         <table class='form' id="reseni"> | ||||
|           <tr> | ||||
|           {% for field in form.visible_fields %} | ||||
| 
 | ||||
|               <td> | ||||
|                 <label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}"> | ||||
|                   {{ field.label }}: | ||||
|                 </label> | ||||
| 
 | ||||
|               </td> | ||||
|               <td {% if field.help_text %} class="field-with-comment"{% endif %}> | ||||
|                 {{ field }} | ||||
|                   <span class="field-comment">{{ field.help_text|safe }}</span> | ||||
|               </td> | ||||
| 
 | ||||
|             <td><span class="field-error">{{ field.errors }}</span></td> | ||||
| 
 | ||||
|           {% endfor %} | ||||
| 
 | ||||
|         <td> | ||||
|           <input type="button" value="Odebrat přílohu" class="remove_attachment" id="{{form.prefix}}-jsremove"> | ||||
|         </td> | ||||
| 	</tr> | ||||
|   </table> | ||||
| 	</div> | ||||
| {% endfor %} | ||||
| </div> | ||||
| 
 | ||||
| <input type="button" value="Přidat přílohu" id="add_attachment"> | ||||
| 
 | ||||
| <div id="empty_form" style="display:none"> | ||||
| 	<div class="attachment"> | ||||
| 
 | ||||
|         <table class='form no_error' id="reseni"> | ||||
|           <tr> | ||||
|           {% for field in prilohy.empty_form.visible_fields %} | ||||
| 
 | ||||
|               <td> | ||||
|                 <label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}"> | ||||
|                   {{ field.label }}: | ||||
|                 </label> | ||||
| 
 | ||||
|               </td> | ||||
|               <td {% if field.help_text %} class="field-with-comment"{% endif %}> | ||||
|                 {{ field }} | ||||
|                 <span class="field-comment">{{ field.help_text|safe }}</span> | ||||
|               </td> | ||||
| 
 | ||||
|             <td><span class="field-error">{{ field.errors }}</span></td> | ||||
| 
 | ||||
|           {% endfor %} | ||||
| 
 | ||||
|         <td> | ||||
| 
 | ||||
| 
 | ||||
| 	<input type="button" value="Odebrat přílohu" class="remove_attachment" id="id_prilohy-__prefix__-jsremove"> | ||||
|   </td> | ||||
| </tr> | ||||
| </table> | ||||
| 	</div> | ||||
| </div> | ||||
| {% include "odevzdavatko/prilohy.html" %} | ||||
| 
 | ||||
| <hr> | ||||
| <h4>Odevzdat řešení</h4> | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| {% block script %} | ||||
|     <!--script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script!--> | ||||
|     {{form.media}} | ||||
|     <script src="{% static 'odevzdavatko/dynamic_formsets.js' %}"></script> | ||||
| {% endblock %} | ||||
| 
 | ||||
| {% block content %} | ||||
|  | @ -11,9 +12,16 @@ | |||
|     Vložit řešení | ||||
|   {% endblock %}{% endblock %} | ||||
| </h1> | ||||
| <form action="{% url 'seminar_vloz_reseni' %}" method="post"> | ||||
| <form enctype="multipart/form-data" action="{% url 'seminar_vloz_reseni' %}" method="post" onsubmit="return zkontroluj_prilohy();"> | ||||
|   {% csrf_token %} | ||||
| {{form.as_p}} | ||||
| 
 | ||||
| <hr> | ||||
| 
 | ||||
| {% include "odevzdavatko/prilohy.html" %} | ||||
| 
 | ||||
| <hr> | ||||
| <h4>Vložit řešení</h4> | ||||
|     <input type="submit" value="Vložit"> | ||||
| </form> | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										73
									
								
								odevzdavatko/templates/odevzdavatko/prilohy.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								odevzdavatko/templates/odevzdavatko/prilohy.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | |||
| {{ prilohy.management_form }} | ||||
| 
 | ||||
| <h4>Soubory s řešením</h4> | ||||
| 
 | ||||
| <p style="text-align: justify">Maximální součet velikostí příloh je cca 49 MB. Pokud je to možné a dává to smysl, pošli nám prosím své řešení ve formátu PDF, ostatní formáty nemusíme umět otevřít.</p> | ||||
| <p style="text-align: justify">Pokud svůj soubor rozumně pojmenuješ, urychlíš opravování a předejdeš tomu, že si nějakého tvého řešení nevšimneme. Například z <code>img_250921_101205.pdf</code> nepoznáme, kterou úlohu jsi odevzdal, zato <code>uloha_3.pdf</code> nebo <code>tema_1.pdf</code>, to už je něco jiného. Případně můžeš využít i poznámku řešitele.</p> | ||||
| 
 | ||||
| <div id="form_set"> | ||||
| {% for form in prilohy.forms %} | ||||
| 	<div class="attachment"> | ||||
| 	{{ form.non_field_errors }} | ||||
| 	{# {{ form.errors }} FIXME: možná tohle chceme zobrazovat? #} | ||||
|         <table class='form' id="reseni"> | ||||
|           <tr> | ||||
|           {% for field in form.visible_fields %} | ||||
| 
 | ||||
|               <td> | ||||
|                 <label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}"> | ||||
|                   {{ field.label }}: | ||||
|                 </label> | ||||
| 
 | ||||
|               </td> | ||||
|               <td {% if field.help_text %} class="field-with-comment"{% endif %}> | ||||
|                 {{ field }} | ||||
|                   <span class="field-comment">{{ field.help_text|safe }}</span> | ||||
|               </td> | ||||
| 
 | ||||
|             <td><span class="field-error">{{ field.errors }}</span></td> | ||||
| 
 | ||||
|           {% endfor %} | ||||
| 
 | ||||
|         <td> | ||||
|           <input type="button" value="Odebrat přílohu" class="remove_attachment" id="{{form.prefix}}-jsremove"> | ||||
|         </td> | ||||
| 	</tr> | ||||
|   </table> | ||||
| 	</div> | ||||
| {% endfor %} | ||||
| </div> | ||||
| 
 | ||||
| <input type="button" value="Přidat přílohu" id="add_attachment"> | ||||
| 
 | ||||
| <div id="empty_form" style="display:none"> | ||||
| 	<div class="attachment"> | ||||
| 
 | ||||
|         <table class='form no_error' id="reseni"> | ||||
|           <tr> | ||||
|           {% for field in prilohy.empty_form.visible_fields %} | ||||
| 
 | ||||
|               <td> | ||||
|                 <label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}"> | ||||
|                   {{ field.label }}: | ||||
|                 </label> | ||||
| 
 | ||||
|               </td> | ||||
|               <td {% if field.help_text %} class="field-with-comment"{% endif %}> | ||||
|                 {{ field }} | ||||
|                 <span class="field-comment">{{ field.help_text|safe }}</span> | ||||
|               </td> | ||||
| 
 | ||||
|             <td><span class="field-error">{{ field.errors }}</span></td> | ||||
| 
 | ||||
|           {% endfor %} | ||||
| 
 | ||||
|         <td> | ||||
| 
 | ||||
| 
 | ||||
| 	<input type="button" value="Odebrat přílohu" class="remove_attachment" id="id_prilohy-__prefix__-jsremove"> | ||||
|   </td> | ||||
| </tr> | ||||
| </table> | ||||
| 	</div> | ||||
| </div> | ||||
|  | @ -357,10 +357,24 @@ class PosliReseniView(LoginRequiredMixin, FormView): | |||
| 		nove_reseni.resitele.add(data['resitel']) | ||||
| 		nove_reseni.problem.add(data['problem']) | ||||
| 		nove_reseni.save() | ||||
| 
 | ||||
| 		context = self.get_context_data() | ||||
| 		prilohy = context['prilohy'] | ||||
| 		prilohy.instance = nove_reseni | ||||
| 		prilohy.save() | ||||
| 		# Chtěl jsem, aby bylo vidět, že se to uložilo, tak přesměrovávám na profil. | ||||
| 		return redirect(reverse('profil')) | ||||
| 
 | ||||
| 
 | ||||
| 	def get_context_data(self,**kwargs): | ||||
| 		data = super().get_context_data(**kwargs) | ||||
| 		if self.request.POST: | ||||
| 			data['prilohy'] = f.ReseniSPrilohamiFormSet(self.request.POST,self.request.FILES) | ||||
| 		else: | ||||
| 			data['prilohy'] = f.ReseniSPrilohamiFormSet() | ||||
| 		return data | ||||
| 
 | ||||
| 
 | ||||
| class NahrajReseniView(LoginRequiredMixin, CreateView): | ||||
| 	model = m.Reseni | ||||
| 	template_name = 'odevzdavatko/nahraj_reseni.html' | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue