def shortdate(self):
return self.date.strftime("%Y%m%d%H%M")
+ # We explicitly cache the attachments here, so we can use them
+ # multiple times from templates without generating multiple queries
+ # to the database.
+ _attachments = None
+ @property
+ def attachments(self):
+ if not self._attachments:
+ self._attachments = self.attachment_set.extra(select={'len': 'length(attachment)'}).all()
+ return self._attachments
+
class ListGroup(models.Model):
groupid = models.IntegerField(null=False, primary_key=True)
groupname = models.CharField(max_length=200, null=False, blank=False)
class Meta:
db_table = 'attachments'
+
+ def inlineable(self):
+ # Return True if this image should be inlined
+ if self.contenttype in ('image/png', 'image/gif', 'image/jpg', 'image/jpeg'):
+ # Note! len needs to be set with extra(select=)
+ if self.len < 75000:
+ return True
+ return False
<pre>{{msg.bodytxt|hideallemail|urlize}}</pre>
{%if msg.has_attachment%}
-{%for a in msg.attachment_set.all%}
+{%for a in msg.attachments%}
+{%if a.inlineable%}<a href="/message-id/attachment/{{a.id}}/{{a.filename}}"><img class="attachedimage" src="/message-id/attachment/{{a.id}}/{{a.filename}}" /></a>{%endif%}
+{%if forloop.last%}<hr/>{%endif%}
+{%endfor%}
+
+{%for a in msg.attachments%}
<div>
<b>Attachment: <a href="/message-id/attachment/{{a.id}}/{{a.filename}}">{{a.filename}}</a></b><br/>
-Description: {{a.contenttype}}
+Description: {{a.contenttype}} {%if a.inlineable%}(inlined above){%endif%}
</div>
{%endfor%}
{%endif%}