summaryrefslogtreecommitdiffstats
path: root/src/authentic2_cut/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/authentic2_cut/views.py')
-rw-r--r--src/authentic2_cut/views.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/authentic2_cut/views.py b/src/authentic2_cut/views.py
index 1a73bea..bf9c746 100644
--- a/src/authentic2_cut/views.py
+++ b/src/authentic2_cut/views.py
@@ -15,13 +15,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import magic
+from contextlib import closing
+
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.views.generic.base import TemplateView
from django.core.exceptions import PermissionDenied
-from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.db.transaction import atomic
@@ -207,9 +209,7 @@ class Validation(UserEditCoreView):
def get_context_data(self, **kwargs):
ctx = super(Validation, self).get_context_data(**kwargs)
ctx['validation_request'] = self.validation_request
- ctx['attachment_urls'] = [
- reverse('cut-manager-user-validation-attachment', kwargs={'pk': attachment.pk})
- for attachment in self.validation_request.attachments.all()]
+ ctx['attachments'] = self.validation_request.attachments.all()
ctx['action'] = u'Valider'
ctx['validation_form'] = forms.ValidationForm()
return ctx
@@ -270,11 +270,24 @@ class Validation(UserEditCoreView):
validation = Validation.as_view()
-def validation_attachment(request, pk):
+def validation_attachment(request, pk, filename):
+ if not request.user.is_authenticated() or not request.user.has_perm_any('custom_user.cut_validate_user'):
+ raise PermissionDenied
+ attachment = models.ValidationRequestAttachment.objects.get(pk=pk)
+ attachment.image.open()
+ mime_type = magic.from_buffer(attachment.image.read(10000), mime=True)
+ attachment.image.open()
+ return HttpResponse(attachment.image, content_type=mime_type)
+
+
+def validation_attachment_thumbnail(request, pk, filename):
if not request.user.is_authenticated() or not request.user.has_perm_any('custom_user.cut_validate_user'):
raise PermissionDenied
attachment = models.ValidationRequestAttachment.objects.get(pk=pk)
- return HttpResponse(attachment.image, content_type='image/jpeg')
+ thumbnail = attachment.thumbnail
+ if not thumbnail:
+ raise Http404
+ return HttpResponse(thumbnail.read(), content_type='image/jpeg')
class ValidationHomepage(BaseTableView):