mirror of
https://github.com/NaN-tic/trytond-galatea_tutorial.git
synced 2023-12-14 02:32:55 +01:00
Tutorial Create/Write Date
This commit is contained in:
parent
d7c181237d
commit
9f5e65df01
3 changed files with 31 additions and 1 deletions
27
tutorial.py
27
tutorial.py
|
@ -6,6 +6,7 @@ from trytond.pool import Pool
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.cache import Cache
|
||||
from .tools import slugify
|
||||
from datetime import datetime
|
||||
|
||||
__all__ = ['GalateaTutorial', 'GalateaTutorialWebSite', 'GalateaTutorialComment']
|
||||
|
||||
|
@ -36,6 +37,8 @@ class GalateaTutorial(ModelSQL, ModelView):
|
|||
('register','Register'),
|
||||
('manager','Manager'),
|
||||
], 'Visibility', required=True)
|
||||
tutorial_create_date = fields.DateTime('Create Date', readonly=True)
|
||||
tutorial_write_date = fields.DateTime('Write Date', readonly=True)
|
||||
user = fields.Many2One('galatea.user', 'User', required=True)
|
||||
websites = fields.Many2Many('galatea.tutorial-galatea.website',
|
||||
'tutorial', 'website', 'Websites',
|
||||
|
@ -77,7 +80,8 @@ class GalateaTutorial(ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(GalateaTutorial, cls).__setup__()
|
||||
cls._order.insert(0, ('name', 'ASC'))
|
||||
cls._order.insert(0, ('tutorial_create_date', 'DESC'))
|
||||
cls._order.insert(1, ('name', 'ASC'))
|
||||
cls._error_messages.update({
|
||||
'delete_tutorials': ('You can not delete '
|
||||
'tutorials because you will get error 404 NOT Found. '
|
||||
|
@ -90,6 +94,27 @@ 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()
|
||||
|
||||
actions = iter(args)
|
||||
args = []
|
||||
for photos, values in zip(actions, actions):
|
||||
values = values.copy()
|
||||
values['tutorial_write_date'] = now
|
||||
args.extend((photos, values))
|
||||
return super(GalateaTutorial, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
def copy(cls, tutorials, default=None):
|
||||
new_tutorials = []
|
||||
|
|
|
@ -31,6 +31,10 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="gallery"/>
|
||||
<label name="comment"/>
|
||||
<field name="comment"/>
|
||||
<label name="tutorial_create_date"/>
|
||||
<field name="tutorial_create_date"/>
|
||||
<label name="tutorial_write_date"/>
|
||||
<field name="tutorial_write_date"/>
|
||||
</page>
|
||||
<page string="Websites" id="websites">
|
||||
<field name="websites" colspan="6"/>
|
||||
|
|
|
@ -4,6 +4,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<tree string="Tutorials">
|
||||
<field name="name"/>
|
||||
<field name="slug"/>
|
||||
<field name="tutorial_create_date"/>
|
||||
<field name="user"/>
|
||||
<field name="visibility"/>
|
||||
<field name="websites" tree_invisible="1"/>
|
||||
|
|
Loading…
Reference in a new issue