coding utf-8 from django db import models from kamwh settings import M

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# ^^, coding: utf-8 ^^,
from django.db import models
from kamwh.settings import MEDIA_ROOT
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
# Create your models here.
class Fraction(models.Model):
title = models.CharField(_('Fraction'),max_length=30,null=False)
def __unicode__(self):
return self.title
class Side(models.Model):
name = models.CharField(_('Side'),max_length=40,null=False)
fraction = models.ForeignKey(Fraction)
def __unicode__(self):
return self.name
class Army(models.Model):
name = models.CharField(_('Army'),max_length=100,null=False)
side = models.ForeignKey(Side)
def __unicode__(self):
return "[%s]:%s" % ( self.side.name, self.name)
class Meta:
verbose_name = _('Army')
verbose_name_plural = _('Armies')
class MiniQuote(models.Model):
content = models.CharField(_('Content'),max_length=255)
class Meta:
verbose_name = _('Mini Quote')
verbose_name_plural = _('Mini Quotes')
class Expression(models.Model):
author = models.CharField(_('Author'), max_length=50, blank=True)
original_content = models.TextField(_('Original'), help_text=_('Original text of expression'), max_length=500, blank=True)
content = models.TextField(_('Translation'), help_text=_('Translation of original sentence'), max_length=500, blank=True)
fraction = models.ForeignKey(Fraction)
def show_original_content(self):
num = 50
if self.original_content:
if len(self.original_content)>num: return self.original_content[0:num] + " ..."
else: return self.original_content[0:num]
return ''
show_original_content.short_description = _('original content')
def show_content(self):
num = 50
if self.content:
if len(self.content)>num: return self.content[0:num] + " ..."
else: return self.content[0:num]
return ''
show_content.short_description = _('content')
def show_author(self):
num = 20
if self.author:
if len(self.author)>num: return self.author[0:num] + " ..."
else: return self.author[0:num]
return ''
show_author.short_description = _('author')
def __unicode__(self):
if self.original_content:
return self.original_content
elif self.content:
return self.content
return ''
class Meta:
ordering = ['id']
verbose_name = _('expression')
verbose_name_plural = _('expressions')
class Profile(models.Model):
#account = models.ForeignKey(User,unique=True)
nickname = models.CharField(_('Nickname'),max_length=50,null=False,unique=True)
photo = models.ImageField(_('Photo'),upload_to=MEDIA_ROOT+'/photos',blank=True)
avatar = models.ImageField(_('Avatar'),upload_to=MEDIA_ROOT+'/avatars/',help_text=_('Image must be 100x100 karge.'),blank=True)
army = models.ForeignKey(Army)
gender = models.CharField(_('Gender'),blank=True,default='n',max_length=1,choices=[('m','male'),('f','female'),('n','not identified')])
jid = models.CharField(_('Jabber ID'),blank=True,max_length=255)
uin = models.IntegerField(_('UIN (icq number'), max_length=12, blank=True)
def __unicode__(self):
if self.nickname: return self.nickname
return ''
class PM(models.Model):
sender = models.ForeignKey(User,related_name='sender')
addressee = models.ForeignKey(User,related_name='addressee')
title = models.CharField(_('Title'), max_length=50)
content = models.TextField(_('Text'))
is_read = models.BooleanField(_('Is read'))
sent = models.DateTimeField(_('Sent'))
dbs = models.BooleanField(_('Deleted by sendr'))
dba = models.BooleanField(_('Delete by addr'))
#TODO: Do we need files in PM ?
#file = models.ForeignKey(_____)
class Meta:
verbose_name = _('Private Message')
verbose_name_plural = _('Private Messages')
class RegisterSid(models.Model):
sid = models.CharField(_('SID'), max_length=40, primary_key=True)
ip = models.CharField(_('IP'), max_length=16)
value = models.CharField(_('Value'), max_length=10)
expired = models.DateTimeField(_('Expired'))
class WishList(models.Model):
anonymous = models.CharField(_('Name'), max_length=40, null=True, blank=True)
author = models.ForeignKey(User)
post = models.TextField(_('Post'))
ip = models.CharField(_('IP'), max_length=16, null=True)
published = models.BooleanField(_('Published'))
approved = models.BooleanField(_('Approved'))
class Meta:
permissions = (
('can_approve', 'Can approve'),
#('can_publish', _('Can publish')),
)
class Skin(models.Model):
name = models.CharField(_('Name'), max_length=40)
description = models.TextField(_('Description'))
def __unicode__(self):
return self.name
class Rank(models.Model):
short_name = models.CharField(_('Short name'), max_length=20)
description = models.CharField(_('Description'), max_length=255)
#class Settings(models.Model):
# skin = models.ForeignKey(Skin)
#monkey patching админки, внедрить после отладки профиля
User.add_to_class('nickname', models.CharField(_('Nickname'),max_length=30,null=False, unique=True))
User.add_to_class('photo', models.ImageField(_('Photo'),upload_to=MEDIA_ROOT+'/photos/',blank=True))
User.add_to_class('avatar', models.ImageField(_('Avatar'),upload_to=MEDIA_ROOT+'/avatars/',blank=True))
User.add_to_class('army', models.ForeignKey(Army))
User.add_to_class('gender', models.CharField(_('Gender'), default='n', max_length=1, choices=[('m',_('male')),('f',_('female')),('n',_('not identified'))]))
User.add_to_class('jid', models.CharField(_('Jabber ID'), max_length=255, blank=True,null=True))
User.add_to_class('uin', models.IntegerField(_('UIN (icq number)'), max_length=12, blank=True,null=True))
User.add_to_class('about', models.TextField(_('About myself'), blank=True))
User.add_to_class('skin', models.ForeignKey(Skin))
User.add_to_class('rank', models.ForeignKey(Rank,null=True,blank=True))
#User.add_to_class('settings', models.ForeignKey(Settings))
#Не работает с apache
UserAdmin.fieldsets += (
(_('Profile'),
{
'fields': ('nickname','photo','avatar','army','gender','jid','uin','about', 'skin'),
#'list_display': ('nickname','photo', 'avatar', 'army', 'gender', 'jid', 'uin', 'about', 'skin')
}
),
)
#USERPERMS = (
# ('can_test', 'Can test functional'),
#)
from kamwh.core import USERPERMS
class UserProfile(object):
def _get_comments(self):
return Comment.object.get(user=self,
is_public=True)
public_comments = property(_get_comments)
del _get_comments
def _show_user(self):
return self.username
show_user = _show_user
del _show_user
def __unicode__(self):
return self.username
class Meta:
permissions = USERPERMS
User.__bases__ = User.__bases__ + (UserProfile,)