1. Dan Watson
  2. leaves-cms

Commits

Dan Watson  committed b184cb5

Check attachment site, order attachments

  • Participants
  • Parent commits 1b44581
  • Branches default

Comments (0)

Files changed (2)

File leaves/models.py

View file
  • Ignore whitespace
 	num_downloads = models.PositiveIntegerField(default=0, editable=False)
 	rank = models.IntegerField(default=0, help_text=_('Used for ordering attachments.'))
 
+	class Meta:
+		ordering = ('rank', 'title', 'filename')
+
 	def __unicode__(self):
 		if self.title:
 			return self.title

File leaves/views.py

View file
  • Ignore whitespace
 	})
 
 def view_attachment(request, attachment_id, filename):
-	attachment = get_object_or_404(Attachment, pk=attachment_id)
+	attachment = get_object_or_404(Attachment.objects.filter(leaf__sites=request.site), pk=attachment_id)
 	try:
 		name = os.path.basename(attachment.attachment.name)
-		mime = mimetypes.guess_type(name)[0] 
+		mime = mimetypes.guess_type(name)[0]
+		disp = 'inline'
+		if not mime:
+			mime = 'application/octet-stream'
+			disp = 'attachment'
 		resp = HttpResponse(attachment.attachment, mimetype=mime)
 		if attachment.filename:
 			name = attachment.filename
-		resp['Content-Disposition'] = 'inline; filename="%s"' % name
+		resp['Content-Disposition'] = '%s; filename="%s"' % (disp, name)
 		attachment.num_downloads += 1
 		attachment.save(checksum=False)
 		return resp
 	except Exception, ex:
-		return HttpResponse('')	
+		return HttpResponse('')
 
 def leaf_search(request):
 	leaves = Leaf.on_site.stream()