Create date from default method (not write or function field)

This commit is contained in:
resteve 2015-08-12 23:42:29 +02:00
parent 58ed92f95e
commit 37ff28c813

View file

@ -89,6 +89,10 @@ class GalateaTutorial(ModelSQL, ModelView):
return website.tutorial_anonymous_user.id
return None
@staticmethod
def default_tutorial_create_date():
return datetime.now()
@classmethod
def __setup__(cls):
super(GalateaTutorial, cls).__setup__()
@ -110,15 +114,6 @@ class GalateaTutorial(ModelSQL, ModelView):
res['slug'] = slugify(self.name)
return res
@classmethod
def create(cls, vlist):
now = datetime.now()
vlist = [x.copy() for x in vlist]
for vals in vlist:
vals['tutorial_create_date'] = now
photos = super(GalateaTutorial, cls).create(vlist)
return photos
@classmethod
def write(cls, *args):
now = datetime.now()
@ -252,8 +247,7 @@ class GalateaTutorialComment(ModelSQL, ModelView):
'the MediaWiki (http://meta.wikimedia.org/wiki/Help:Editing) syntax.')
active = fields.Boolean('Active',
help='Dissable to not show content tutorial.')
comment_create_date = fields.Function(fields.Char('Create Date'),
'get_comment_create_date')
comment_create_date = fields.DateTime('Create Date', readonly=True)
@classmethod
def __setup__(cls):
@ -276,11 +270,11 @@ class GalateaTutorialComment(ModelSQL, ModelView):
return website.tutorial_anonymous_user.id
return None
@staticmethod
def default_comment_create_date():
return datetime.now()
@classmethod
def get_comment_create_date(cls, records, name):
'Created domment date'
res = {}
DATE_FORMAT = '%s %s' % (Transaction().context['locale']['date'], '%H:%M:%S')
for record in records:
res[record.id] = record.create_date.strftime(DATE_FORMAT) or ''
return res
def copy(cls, comments, default=None):
default['comment_create_date'] = datetime.now()
return super(GalateaTutorialComment, cls).copy(comments, default=default)