From 62e7f1dfbc334f9cee0444b989de02994b79a661 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= <matej.kocian@gmail.com>
Date: Sat, 19 Dec 2015 23:11:50 +0100
Subject: [PATCH] =?UTF-8?q?Fix:=20Probl=C3=A9m:=20jen=20orgov=C3=A9=20si?=
 =?UTF-8?q?=20mohou=20zobrazit=20n=C3=A1vrh?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 seminar/templates/seminar/archiv/problem.html          |  2 +-
 .../templates/seminar/archiv/problem_uloha_tema.html   | 10 +++-------
 seminar/views.py                                       |  7 +++++--
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/seminar/templates/seminar/archiv/problem.html b/seminar/templates/seminar/archiv/problem.html
index 67071dea..6fdc5fac 100644
--- a/seminar/templates/seminar/archiv/problem.html
+++ b/seminar/templates/seminar/archiv/problem.html
@@ -3,7 +3,7 @@
 {% load comments %}
 
 {% block content %}
-<div>
+<div {% if not problem.verejne and user.is_staff %}class="mam-org-only"{% endif %}>
   {% block problem %}
   {% endblock %}
 
diff --git a/seminar/templates/seminar/archiv/problem_uloha_tema.html b/seminar/templates/seminar/archiv/problem_uloha_tema.html
index 12ee40ac..bd68a6fb 100644
--- a/seminar/templates/seminar/archiv/problem_uloha_tema.html
+++ b/seminar/templates/seminar/archiv/problem_uloha_tema.html
@@ -8,14 +8,10 @@
     </h2>
   {% if problem.cislo_zadani %}
     <p>Zadáno v čísle <a href='{{ problem.cislo_zadani.verejne_url }}'>{{ problem.cislo_zadani.kod }}</a>.
-    {% if problem.cislo_reseni %}
-      <p>Řešeno v čísle <a href='{{ problem.cislo_reseni.verejne_url }}'>{{ problem.cislo_reseni.kod }}</a>.
-    {% endif %}
-  {% else %}
-    {# TODO ? #}
-    <h2>Problém {{ problem.nazev }}</h2>
   {% endif %}
-
+  {% if problem.cislo_reseni %}
+    <p>Řešeno v čísle <a href='{{ problem.cislo_reseni.verejne_url }}'>{{ problem.cislo_reseni.kod }}</a>.
+  {% endif %}
 
   <h3>Zadání</h3>
   {{ problem.text_zadani |safe }}
diff --git a/seminar/views.py b/seminar/views.py
index 4bef203a..93945778 100644
--- a/seminar/views.py
+++ b/seminar/views.py
@@ -1,9 +1,9 @@
 # coding:utf-8
 
 from django.shortcuts import get_object_or_404, render
-from django.http import HttpResponseRedirect
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
 from django.core.urlresolvers import reverse
+from django.core.exceptions import PermissionDenied
 from django.views import generic
 from django.utils.translation import ugettext as _
 from django.http import Http404
@@ -235,11 +235,14 @@ class ProblemView(generic.DetailView):
 
     def get_context_data(self, **kwargs):
         context = super(ProblemView, self).get_context_data(**kwargs)
+        if not context['problem'].verejne() and not self.request.user.is_staff:
+            raise PermissionDenied()
         if context['problem'].typ == Problem.TYP_RES_CLANEK:
             context['reseni'] = Reseni.objects.filter(problem=context['problem']).select_related('resitel').order_by('resitel__prijmeni')
         return context
 
 
+
 class RadekVysledkovky(object):
     pass