Show More
@@ -4,6 +4,7 b' from random import random' | |||||
4 | import time |
|
4 | import time | |
5 | from django.db import models |
|
5 | from django.db import models | |
6 | from boards import thumbs |
|
6 | from boards import thumbs | |
|
7 | from boards.models.base import Viewable | |||
7 |
|
8 | |||
8 | __author__ = 'neko259' |
|
9 | __author__ = 'neko259' | |
9 |
|
10 | |||
@@ -11,9 +12,13 b' from boards import thumbs' | |||||
11 | IMAGE_THUMB_SIZE = (200, 150) |
|
12 | IMAGE_THUMB_SIZE = (200, 150) | |
12 | IMAGES_DIRECTORY = 'images/' |
|
13 | IMAGES_DIRECTORY = 'images/' | |
13 | FILE_EXTENSION_DELIMITER = '.' |
|
14 | FILE_EXTENSION_DELIMITER = '.' | |
|
15 | HASH_LENGTH = 36 | |||
|
16 | ||||
|
17 | CSS_CLASS_IMAGE = 'image' | |||
|
18 | CSS_CLASS_THUMB = 'thumb' | |||
14 |
|
19 | |||
15 |
|
20 | |||
16 | class PostImage(models.Model): |
|
21 | class PostImage(models.Model, Viewable): | |
17 | class Meta: |
|
22 | class Meta: | |
18 | app_label = 'boards' |
|
23 | app_label = 'boards' | |
19 | ordering = ('id',) |
|
24 | ordering = ('id',) | |
@@ -43,7 +48,7 b' class PostImage(models.Model):' | |||||
43 | height_field='height', |
|
48 | height_field='height', | |
44 | preview_width_field='pre_width', |
|
49 | preview_width_field='pre_width', | |
45 | preview_height_field='pre_height') |
|
50 | preview_height_field='pre_height') | |
46 |
hash = models.CharField(max_length= |
|
51 | hash = models.CharField(max_length=HASH_LENGTH) | |
47 |
|
52 | |||
48 | def save(self, *args, **kwargs): |
|
53 | def save(self, *args, **kwargs): | |
49 | """ |
|
54 | """ | |
@@ -60,3 +65,19 b' class PostImage(models.Model):' | |||||
60 | def __str__(self): |
|
65 | def __str__(self): | |
61 | return self.image.url |
|
66 | return self.image.url | |
62 |
|
67 | |||
|
68 | def get_view(self): | |||
|
69 | return '<div class="{}">' \ | |||
|
70 | '<a class="{}" href="{}">' \ | |||
|
71 | '<img' \ | |||
|
72 | ' src="{}"' \ | |||
|
73 | ' alt="{}"' \ | |||
|
74 | ' width="{}"' \ | |||
|
75 | ' height="{}"' \ | |||
|
76 | ' data-width="{}"' \ | |||
|
77 | ' data-height="{}" />' \ | |||
|
78 | '</a>' \ | |||
|
79 | '</div>'\ | |||
|
80 | .format(CSS_CLASS_IMAGE, CSS_CLASS_THUMB, self.image.url, | |||
|
81 | self.image.url_200x150, | |||
|
82 | str(self.hash), str(self.pre_width), | |||
|
83 | str(self.pre_height), str(self.width), str(self.height)) |
@@ -46,22 +46,20 b'' | |||||
46 | </span> |
|
46 | </span> | |
47 | {% endif %} |
|
47 | {% endif %} | |
48 | </div> |
|
48 | </div> | |
|
49 | {% comment %} | |||
|
50 | Post images. Currently only 1 image can be posted and shown, but post model | |||
|
51 | supports multiple. | |||
|
52 | {% endcomment %} | |||
49 | {% if post.images.exists %} |
|
53 | {% if post.images.exists %} | |
50 | {% with post.images.all.0 as image %} |
|
54 | {% with post.images.all.0 as image %} | |
51 | <div class="image"> |
|
55 | {% autoescape off %} | |
52 | <a |
|
56 | {{ image.get_view }} | |
53 | class="thumb" |
|
57 | {% endautoescape %} | |
54 | href="{{ image.image.url }}"><img |
|
|||
55 | src="{{ image.image.url_200x150 }}" |
|
|||
56 | alt="{{ post.id }}" |
|
|||
57 | width="{{ image.pre_width }}" |
|
|||
58 | height="{{ image.pre_height }}" |
|
|||
59 | data-width="{{ image.width }}" |
|
|||
60 | data-height="{{ image.height }}"/> |
|
|||
61 | </a> |
|
|||
62 | </div> |
|
|||
63 | {% endwith %} |
|
58 | {% endwith %} | |
64 | {% endif %} |
|
59 | {% endif %} | |
|
60 | {% comment %} | |||
|
61 | Post message (text) | |||
|
62 | {% endcomment %} | |||
65 | <div class="message"> |
|
63 | <div class="message"> | |
66 | {% autoescape off %} |
|
64 | {% autoescape off %} | |
67 | {% if truncated %} |
|
65 | {% if truncated %} | |
@@ -78,6 +76,9 b'' | |||||
78 | </div> |
|
76 | </div> | |
79 | {% endif %} |
|
77 | {% endif %} | |
80 | </div> |
|
78 | </div> | |
|
79 | {% comment %} | |||
|
80 | Thread metadata: counters, tags etc | |||
|
81 | {% endcomment %} | |||
81 | {% if is_opening %} |
|
82 | {% if is_opening %} | |
82 | <div class="metadata"> |
|
83 | <div class="metadata"> | |
83 | {% if is_opening and need_open_link %} |
|
84 | {% if is_opening and need_open_link %} |
General Comments 0
You need to be logged in to leave comments.
Login now