##// END OF EJS Templates
Added last access time and registration time for user. This refs #61
neko259 -
r121:a76c11ea 1.1
parent child Browse files
Show More
@@ -35,39 +35,6 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
71 class PostManager(models.Manager):
38 class PostManager(models.Manager):
72 def create_post(self, title, text, image=None, parent_id=NO_PARENT,
39 def create_post(self, title, text, image=None, parent_id=NO_PARENT,
73 ip=NO_IP, tags=None, user=None):
40 ip=NO_IP, tags=None, user=None):
@@ -317,15 +284,43 b' class Post(models.Model):'
317 return last_replies
284 return last_replies
318
285
319
286
320 class Admin(models.Model):
287 class User(models.Model):
321 """
288
322 Model for admin users
289 user_id = models.CharField(max_length=50)
323 """
290 rank = models.IntegerField()
324 name = models.CharField(max_length=100)
291
325 password = models.CharField(max_length=100)
292 registration_time = models.DateTimeField()
293 last_access_time = models.DateTimeField()
294
295 fav_tags = models.ManyToManyField(Tag)
296 fav_threads = models.ManyToManyField(Post)
297
298 def save_setting(self, name, value):
299 setting, created = Setting.objects.get_or_create(name=name, user=self)
300 setting.value = value
301 setting.save()
302
303 return setting
304
305 def get_setting(self, name):
306 settings = Setting.objects.filter(name=name, user=self)
307 if len(settings) > 0:
308 setting = settings[0]
309 else:
310 setting = None
311
312 if setting:
313 setting_value = setting.value
314 else:
315 setting_value = None
316
317 return setting_value
318
319 def is_moderator(self):
320 return RANK_MODERATOR >= self.rank
326
321
327 def __unicode__(self):
322 def __unicode__(self):
328 return self.name + '/' + '*' * len(self.password)
323 return self.user_id
329
324
330
325
331 class Setting(models.Model):
326 class Setting(models.Model):
@@ -3,6 +3,7 b' from django.core.urlresolvers import rev'
3 from django.template import RequestContext
3 from django.template import RequestContext
4 from django.shortcuts import render, redirect, get_object_or_404
4 from django.shortcuts import render, redirect, get_object_or_404
5 from django.http import HttpResponseRedirect
5 from django.http import HttpResponseRedirect
6 from django.utils import timezone
6
7
7 from boards import forms
8 from boards import forms
8 import boards
9 import boards
@@ -278,10 +279,14 b' def _get_user(request):'
278 md5.update(session.session_key)
279 md5.update(session.session_key)
279 new_id = md5.hexdigest()
280 new_id = md5.hexdigest()
280
281
281 user = User.objects.create(user_id=new_id, rank=RANK_USER)
282 user = User.objects.create(user_id=new_id, rank=RANK_USER,
283 registration_time=timezone.now())
282
284
283 session['user_id'] = user.id
285 session['user_id'] = user.id
284 else:
286 else:
285 user = User.objects.get(id=session['user_id'])
287 user = User.objects.get(id=session['user_id'])
288 user.save()
289
290 user.last_access_time = timezone.now()
286
291
287 return user No newline at end of file
292 return user
General Comments 0
You need to be logged in to leave comments. Login now