Show More
@@ -35,9 +35,42 b' RANK_MODERATOR = 10' | |||
|
35 | 35 | RANK_USER = 100 |
|
36 | 36 | |
|
37 | 37 | |
|
38 | class User(models.Model): | |
|
39 | ||
|
40 | user_id = models.CharField(max_length=50) | |
|
41 | rank = models.IntegerField() | |
|
42 | ||
|
43 | def save_setting(self, name, value): | |
|
44 | setting, created = Setting.objects.get_or_create(name=name, user=self) | |
|
45 | setting.value = value | |
|
46 | setting.save() | |
|
47 | ||
|
48 | return setting | |
|
49 | ||
|
50 | def get_setting(self, name): | |
|
51 | settings = Setting.objects.filter(name=name, user=self) | |
|
52 | if len(settings) > 0: | |
|
53 | setting = settings[0] | |
|
54 | else: | |
|
55 | setting = None | |
|
56 | ||
|
57 | if setting: | |
|
58 | setting_value = setting.value | |
|
59 | else: | |
|
60 | setting_value = None | |
|
61 | ||
|
62 | return setting_value | |
|
63 | ||
|
64 | def is_moderator(self): | |
|
65 | return RANK_MODERATOR >= self.rank | |
|
66 | ||
|
67 | def __unicode__(self): | |
|
68 | return self.user_id | |
|
69 | ||
|
70 | ||
|
38 | 71 | class PostManager(models.Manager): |
|
39 | 72 | def create_post(self, title, text, image=None, parent_id=NO_PARENT, |
|
40 | ip=NO_IP, tags=None): | |
|
73 | ip=NO_IP, tags=None, user=None): | |
|
41 | 74 | post = self.create(title=title, |
|
42 | 75 | text=text, |
|
43 | 76 | pub_time=timezone.now(), |
@@ -45,7 +78,8 b' class PostManager(models.Manager):' | |||
|
45 | 78 | image=image, |
|
46 | 79 | poster_ip=ip, |
|
47 | 80 | poster_user_agent=UNKNOWN_UA, |
|
48 |
last_edit_time=timezone.now() |
|
|
81 | last_edit_time=timezone.now(), | |
|
82 | user=user) | |
|
49 | 83 | |
|
50 | 84 | if tags: |
|
51 | 85 | map(post.tags.add, tags) |
@@ -224,6 +258,7 b' class Post(models.Model):' | |||
|
224 | 258 | parent = models.BigIntegerField() |
|
225 | 259 | tags = models.ManyToManyField(Tag) |
|
226 | 260 | last_edit_time = models.DateTimeField() |
|
261 | user = models.ForeignKey(User, null=True, default=None) | |
|
227 | 262 | |
|
228 | 263 | def __unicode__(self): |
|
229 | 264 | return '#' + str(self.id) + ' ' + self.title + ' (' + self.text.raw + \ |
@@ -293,39 +328,6 b' class Admin(models.Model):' | |||
|
293 | 328 | return self.name + '/' + '*' * len(self.password) |
|
294 | 329 | |
|
295 | 330 | |
|
296 | class User(models.Model): | |
|
297 | ||
|
298 | user_id = models.CharField(max_length=50) | |
|
299 | rank = models.IntegerField() | |
|
300 | ||
|
301 | def save_setting(self, name, value): | |
|
302 | setting, created = Setting.objects.get_or_create(name=name, user=self) | |
|
303 | setting.value = value | |
|
304 | setting.save() | |
|
305 | ||
|
306 | return setting | |
|
307 | ||
|
308 | def get_setting(self, name): | |
|
309 | settings = Setting.objects.filter(name=name, user=self) | |
|
310 | if len(settings) > 0: | |
|
311 | setting = settings[0] | |
|
312 | else: | |
|
313 | setting = None | |
|
314 | ||
|
315 | if setting: | |
|
316 | setting_value = setting.value | |
|
317 | else: | |
|
318 | setting_value = None | |
|
319 | ||
|
320 | return setting_value | |
|
321 | ||
|
322 | def is_moderator(self): | |
|
323 | return RANK_MODERATOR >= self.rank | |
|
324 | ||
|
325 | def __unicode__(self): | |
|
326 | return self.user_id | |
|
327 | ||
|
328 | ||
|
329 | 331 | class Setting(models.Model): |
|
330 | 332 | |
|
331 | 333 | name = models.CharField(max_length=50) |
@@ -9,6 +9,7 b' from PIL import Image' | |||
|
9 | 9 | from django.core.files.base import ContentFile |
|
10 | 10 | import cStringIO |
|
11 | 11 | |
|
12 | ||
|
12 | 13 | def generate_thumb(img, thumb_size, format): |
|
13 | 14 | """ |
|
14 | 15 | Generates a thumbnail image and returns a ContentFile object with the thumbnail |
@@ -38,7 +39,8 b' def generate_thumb(img, thumb_size, form' | |||
|
38 | 39 | xnewsize = (xsize-minsize)/2 |
|
39 | 40 | ynewsize = (ysize-minsize)/2 |
|
40 | 41 | # crop it |
|
41 | image2 = image.crop((xnewsize, ynewsize, xsize-xnewsize, ysize-ynewsize)) | |
|
42 | image2 = image.crop( | |
|
43 | (xnewsize, ynewsize, xsize - xnewsize, ysize - ynewsize)) | |
|
42 | 44 | # load is necessary after crop |
|
43 | 45 | image2.load() |
|
44 | 46 | # thumbnail of the cropped image (with ANTIALIAS to make it look better) |
@@ -56,10 +58,12 b' def generate_thumb(img, thumb_size, form' | |||
|
56 | 58 | image2.save(io, format) |
|
57 | 59 |
return ContentFile(io.getvalue()) |
|
58 | 60 | |
|
61 | ||
|
59 | 62 | class ImageWithThumbsFieldFile(ImageFieldFile): |
|
60 | 63 | """ |
|
61 | 64 | See ImageWithThumbsField for usage example |
|
62 | 65 | """ |
|
66 | ||
|
63 | 67 | def __init__(self, *args, **kwargs): |
|
64 | 68 | super(ImageWithThumbsFieldFile, self).__init__(*args, **kwargs) |
|
65 | 69 | self.sizes = self.field.sizes |
@@ -92,7 +96,8 b' class ImageWithThumbsFieldFile(ImageFiel' | |||
|
92 | 96 |
thumb_name_ = self.storage.save(thumb_name, thumb_content) |
|
93 | 97 | |
|
94 | 98 | if not thumb_name == thumb_name_: |
|
95 |
raise ValueError( |
|
|
99 | raise ValueError( | |
|
100 | 'There is already a file named %s' % thumb_name) | |
|
96 | 101 | |
|
97 | 102 | def delete(self, save=True): |
|
98 | 103 | name=self.name |
@@ -107,6 +112,7 b' class ImageWithThumbsFieldFile(ImageFiel' | |||
|
107 | 112 | except: |
|
108 | 113 | pass |
|
109 | 114 | |
|
115 | ||
|
110 | 116 | class ImageWithThumbsField(ImageField): |
|
111 | 117 | attr_class = ImageWithThumbsFieldFile |
|
112 | 118 | """ |
@@ -151,10 +157,17 b' class ImageWithThumbsField(ImageField):' | |||
|
151 | 157 | Add method to regenerate thubmnails |
|
152 | 158 | |
|
153 | 159 | """ |
|
154 | def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, sizes=None, **kwargs): | |
|
160 | ||
|
161 | def __init__(self, verbose_name=None, name=None, width_field=None, | |
|
162 | height_field=None, sizes=None, **kwargs): | |
|
155 | 163 | self.verbose_name=verbose_name |
|
156 | 164 | self.name=name |
|
157 | 165 | self.width_field=width_field |
|
158 | 166 | self.height_field=height_field |
|
159 | 167 | self.sizes = sizes |
|
160 | super(ImageField, self).__init__(**kwargs) No newline at end of file | |
|
168 | super(ImageField, self).__init__(**kwargs) | |
|
169 | ||
|
170 | ||
|
171 | from south.modelsinspector import add_introspection_rules | |
|
172 | ||
|
173 | add_introspection_rules([], ["^boards\.thumbs\.ImageWithThumbsField"]) No newline at end of file |
@@ -140,6 +140,7 b' INSTALLED_APPS = (' | |||
|
140 | 140 | 'django_cleanup', |
|
141 | 141 | 'boards', |
|
142 | 142 | 'captcha', |
|
143 | 'south', | |
|
143 | 144 | ) |
|
144 | 145 | |
|
145 | 146 | # TODO: NEED DESIGN FIXES |
@@ -187,13 +188,14 b" SITE_NAME = 'Neboard'" | |||
|
187 | 188 | |
|
188 | 189 | THEMES = [ |
|
189 | 190 | ('md', 'Mystic Dark'), |
|
190 |
('sw', 'Snow White') |
|
|
191 | ('sw', 'Snow White') | |
|
192 | ] | |
|
191 | 193 | |
|
192 | 194 | DEFAULT_THEME = 'md' |
|
193 | 195 | |
|
194 | 196 | POPULAR_TAGS = 10 |
|
195 | 197 | LAST_REPLIES_COUNT = 3 |
|
196 | 198 | |
|
197 |
ENABLE_CAPTCHA = |
|
|
199 | ENABLE_CAPTCHA = False | |
|
198 | 200 | # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown |
|
199 | 201 | CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds |
General Comments 0
You need to be logged in to leave comments.
Login now