##// END OF EJS Templates
Added user to the posts. This refs #12
neko259 -
r113:aabf6422 1.1
parent child Browse files
Show More
@@ -35,9 +35,42 b' RANK_MODERATOR = 10'
35 RANK_USER = 100
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 class PostManager(models.Manager):
71 class PostManager(models.Manager):
39 def create_post(self, title, text, image=None, parent_id=NO_PARENT,
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 post = self.create(title=title,
74 post = self.create(title=title,
42 text=text,
75 text=text,
43 pub_time=timezone.now(),
76 pub_time=timezone.now(),
@@ -45,7 +78,8 b' class PostManager(models.Manager):'
45 image=image,
78 image=image,
46 poster_ip=ip,
79 poster_ip=ip,
47 poster_user_agent=UNKNOWN_UA,
80 poster_user_agent=UNKNOWN_UA,
48 last_edit_time=timezone.now())
81 last_edit_time=timezone.now(),
82 user=user)
49
83
50 if tags:
84 if tags:
51 map(post.tags.add, tags)
85 map(post.tags.add, tags)
@@ -224,6 +258,7 b' class Post(models.Model):'
224 parent = models.BigIntegerField()
258 parent = models.BigIntegerField()
225 tags = models.ManyToManyField(Tag)
259 tags = models.ManyToManyField(Tag)
226 last_edit_time = models.DateTimeField()
260 last_edit_time = models.DateTimeField()
261 user = models.ForeignKey(User, null=True, default=None)
227
262
228 def __unicode__(self):
263 def __unicode__(self):
229 return '#' + str(self.id) + ' ' + self.title + ' (' + self.text.raw + \
264 return '#' + str(self.id) + ' ' + self.title + ' (' + self.text.raw + \
@@ -293,39 +328,6 b' class Admin(models.Model):'
293 return self.name + '/' + '*' * len(self.password)
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 class Setting(models.Model):
331 class Setting(models.Model):
330
332
331 name = models.CharField(max_length=50)
333 name = models.CharField(max_length=50)
@@ -9,6 +9,7 b' from PIL import Image'
9 from django.core.files.base import ContentFile
9 from django.core.files.base import ContentFile
10 import cStringIO
10 import cStringIO
11
11
12
12 def generate_thumb(img, thumb_size, format):
13 def generate_thumb(img, thumb_size, format):
13 """
14 """
14 Generates a thumbnail image and returns a ContentFile object with the thumbnail
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 xnewsize = (xsize-minsize)/2
39 xnewsize = (xsize - minsize) / 2
39 ynewsize = (ysize-minsize)/2
40 ynewsize = (ysize - minsize) / 2
40 # crop it
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 # load is necessary after crop
44 # load is necessary after crop
43 image2.load()
45 image2.load()
44 # thumbnail of the cropped image (with ANTIALIAS to make it look better)
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 image2.save(io, format)
58 image2.save(io, format)
57 return ContentFile(io.getvalue())
59 return ContentFile(io.getvalue())
58
60
61
59 class ImageWithThumbsFieldFile(ImageFieldFile):
62 class ImageWithThumbsFieldFile(ImageFieldFile):
60 """
63 """
61 See ImageWithThumbsField for usage example
64 See ImageWithThumbsField for usage example
62 """
65 """
66
63 def __init__(self, *args, **kwargs):
67 def __init__(self, *args, **kwargs):
64 super(ImageWithThumbsFieldFile, self).__init__(*args, **kwargs)
68 super(ImageWithThumbsFieldFile, self).__init__(*args, **kwargs)
65 self.sizes = self.field.sizes
69 self.sizes = self.field.sizes
@@ -92,7 +96,8 b' class ImageWithThumbsFieldFile(ImageFiel'
92 thumb_name_ = self.storage.save(thumb_name, thumb_content)
96 thumb_name_ = self.storage.save(thumb_name, thumb_content)
93
97
94 if not thumb_name == thumb_name_:
98 if not thumb_name == thumb_name_:
95 raise ValueError('There is already a file named %s' % thumb_name)
99 raise ValueError(
100 'There is already a file named %s' % thumb_name)
96
101
97 def delete(self, save=True):
102 def delete(self, save=True):
98 name=self.name
103 name = self.name
@@ -107,6 +112,7 b' class ImageWithThumbsFieldFile(ImageFiel'
107 except:
112 except:
108 pass
113 pass
109
114
115
110 class ImageWithThumbsField(ImageField):
116 class ImageWithThumbsField(ImageField):
111 attr_class = ImageWithThumbsFieldFile
117 attr_class = ImageWithThumbsFieldFile
112 """
118 """
@@ -151,10 +157,17 b' class ImageWithThumbsField(ImageField):'
151 Add method to regenerate thubmnails
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 self.verbose_name=verbose_name
163 self.verbose_name = verbose_name
156 self.name=name
164 self.name = name
157 self.width_field=width_field
165 self.width_field = width_field
158 self.height_field=height_field
166 self.height_field = height_field
159 self.sizes = sizes
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 'django_cleanup',
140 'django_cleanup',
141 'boards',
141 'boards',
142 'captcha',
142 'captcha',
143 'south',
143 )
144 )
144
145
145 # TODO: NEED DESIGN FIXES
146 # TODO: NEED DESIGN FIXES
@@ -187,13 +188,14 b" SITE_NAME = 'Neboard'"
187
188
188 THEMES = [
189 THEMES = [
189 ('md', 'Mystic Dark'),
190 ('md', 'Mystic Dark'),
190 ('sw', 'Snow White') ]
191 ('sw', 'Snow White')
192 ]
191
193
192 DEFAULT_THEME = 'md'
194 DEFAULT_THEME = 'md'
193
195
194 POPULAR_TAGS = 10
196 POPULAR_TAGS = 10
195 LAST_REPLIES_COUNT = 3
197 LAST_REPLIES_COUNT = 3
196
198
197 ENABLE_CAPTCHA = True
199 ENABLE_CAPTCHA = False
198 # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown
200 # if user tries to post before CAPTCHA_DEFAULT_SAFE_TIME. Captcha will be shown
199 CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds
201 CAPTCHA_DEFAULT_SAFE_TIME = 30 # seconds
General Comments 0
You need to be logged in to leave comments. Login now