Úpravy novinek
* předvyplnění přihlášeného uživatele * zobrazení pěti nejnovějších na titulní straně bez ohledu na stáří * archiv
This commit is contained in:
		
							parent
							
								
									c3fa39c0a5
								
							
						
					
					
						commit
						01f41bc71d
					
				
					 6 changed files with 61 additions and 31 deletions
				
			
		|  | @ -380,6 +380,15 @@ class NovinkyAdmin(admin.ModelAdmin): | |||
|     list_display = ['datum', 'autor', 'text', 'zverejneno', 'obrazek'] | ||||
|     actions = [zverejnit_novinky, zneverejnit_novinky] | ||||
| 
 | ||||
|     # předvyplnění přihlášeného uživatele jako autora novinky | ||||
|     def formfield_for_foreignkey(self, db_field, request, **kwargs): | ||||
|         if db_field.name == 'autor': | ||||
|             kwargs['initial'] = request.user.id | ||||
|         return super(NovinkyAdmin, self).formfield_for_foreignkey( | ||||
|             db_field, request, **kwargs | ||||
|         ) | ||||
| 
 | ||||
| 
 | ||||
| admin.site.register(Novinky, NovinkyAdmin) | ||||
| 
 | ||||
| ### Organizator | ||||
|  |  | |||
							
								
								
									
										31
									
								
								seminar/templates/seminar/novinky.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								seminar/templates/seminar/novinky.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | |||
| {% for novinka in object_list %} | ||||
| {# pripravene div-y na stylovani#} | ||||
| <div> | ||||
|   {# datum #} | ||||
|   <div><b>{{novinka.datum}}</b></div> | ||||
|   {# text #} | ||||
|   {{ novinka.text | safe }} | ||||
|   {# obrazek #} | ||||
|   {% if novinka.obrazek %} | ||||
|     <div> | ||||
|       <img src='{{novinka.obrazek.url}}' | ||||
|       height=' | ||||
|       {% if novinka.obrazek.height > 200 %} {# vyska obrazku natvrdo #} | ||||
|         200 | ||||
|       {% else %} | ||||
|         {{novinka.obrazek.height}} | ||||
|       {% endif%} | ||||
|       '> | ||||
|     </div> | ||||
|   {% endif %} | ||||
|   {# autor #} | ||||
|   {% if user.is_staff %} | ||||
|     <div>{{novinka.autor.first_name}} | ||||
|       {% if novinka.autor.organizator.prezdivka%} | ||||
|         „{{novinka.autor.organizator.prezdivka}}“ | ||||
|       {% endif %} | ||||
|       {{novinka.autor.last_name}} | ||||
|     </div> | ||||
|   {% endif %} | ||||
| </div> | ||||
| {% endfor%} | ||||
							
								
								
									
										11
									
								
								seminar/templates/seminar/stare_novinky.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								seminar/templates/seminar/stare_novinky.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| {% extends 'base.html' %} | ||||
| 
 | ||||
| {% block content %} | ||||
| 
 | ||||
|   <h2> | ||||
|     Archiv novinek | ||||
|   </h2> | ||||
| 
 | ||||
|   {% include 'seminar/novinky.html' %} | ||||
| 
 | ||||
| {% endblock %} | ||||
|  | @ -13,34 +13,8 @@ | |||
| 
 | ||||
|   {# Novinky #} | ||||
|   <h2>Novinky</h2> | ||||
|   {% include 'seminar/novinky.html' %} | ||||
| 
 | ||||
|   <a href='/stare-novinky/'>Archiv novinek</a> | ||||
|     | ||||
|   {% for novinka in object_list %} | ||||
|   {# pripravene div-y na stylovani#} | ||||
|   <div> | ||||
|     {# datum #} | ||||
|     <div><b>{{novinka.datum}}</b></div> | ||||
|     {# text #} | ||||
|     {% autoescape off %}{{novinka.text}}{% endautoescape %} | ||||
|     {# obrazek #} | ||||
|     {% if novinka.obrazek %} | ||||
|       <div> | ||||
|         <img src='{{novinka.obrazek.url}}' | ||||
|         height=' | ||||
|         {% if novinka.obrazek.height > 200 %} {# vyska obrazku natvrdo #} | ||||
|           200 | ||||
|         {% else %} | ||||
|           {{novinka.obrazek.height}} | ||||
|         {% endif%} | ||||
|         '> | ||||
|       </div> | ||||
|     {% endif %} | ||||
|     {# autor #} | ||||
|     <div>{{novinka.autor.first_name}} | ||||
|       {% if novinka.autor.organizator.prezdivka%} | ||||
|         „{{novinka.autor.organizator.prezdivka}}“ | ||||
|       {% endif %} | ||||
|       {{novinka.autor.last_name}} | ||||
|     </div> | ||||
|   </div> | ||||
|   {% endfor%} | ||||
| {% endblock %} | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ urlpatterns = patterns('', | |||
|     url(r'^zadani/aktualni/$', views.AktualniZadaniView, name='seminar_aktualni_zadani'), | ||||
|     url(r'^zadani/temata/$', views.ZadaniTemataView, name='seminar_temata'), | ||||
|     url(r'^$', views.TitulniStranaView.as_view(), name='titulni_strana'), | ||||
|     url(r'^stare-novinky/$', views.StareNovinkyView.as_view(), name='stare_novinky'), | ||||
| 
 | ||||
|     url(r'^stav$', views.StavDatabazeView, name='stav_databaze'), | ||||
| 
 | ||||
|  |  | |||
|  | @ -42,13 +42,17 @@ def ZadaniTemataView(request): | |||
| class TitulniStranaView(generic.ListView): | ||||
|     model = Novinky | ||||
|     template_name='seminar/titulnistrana.html' | ||||
|     pred_dvema_mesici = (date.today() - timedelta(2*365/12)) | ||||
|     queryset = Novinky.objects.filter(datum__range=(pred_dvema_mesici, date.today())).filter(zverejneno=True).order_by('-datum') | ||||
|     queryset = Novinky.objects.filter(zverejneno=True).order_by('-datum')[:5] | ||||
| 
 | ||||
|     #def get_context_data(self, **kwargs): | ||||
|     #    context = super(TitulniStranaView, self).get_context_data(**kwargs) | ||||
|     #    return context | ||||
| 
 | ||||
| class StareNovinkyView(generic.ListView): | ||||
|     model = Novinky | ||||
|     template_name = 'seminar/stare_novinky.html' | ||||
|     queryset = Novinky.objects.filter(zverejneno=True).order_by('-datum') | ||||
| 
 | ||||
| ### Co je M&M | ||||
| 
 | ||||
| ## Organizatori | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Matěj Kocián
						Matěj Kocián