repairs 'notes' in master before branching

This commit is contained in:
artus
2016-08-06 13:42:29 +02:00
parent f3dd74d367
commit ebb1c849e6
7 changed files with 54 additions and 70 deletions

View File

@@ -1,4 +1,5 @@
from django.db import models
from django.utils.html import format_html
class Note(models.Model):
""" Note relative à un sujet.
@@ -15,25 +16,51 @@ class Note(models.Model):
blank=True,
null=True
)
#date_created = models.DateField('Crée le')
created_date = models.DateField('Crée le', blank=True, null=True)
def as_table(self):
pass
html = format_html(
"<tr><th>{} <span class='label label-info'>{}</span>\
<span class='label label-info'>{}</span></th>\
\n<tr><td>{}</td></tr>",
self.sujet,
self.created_date,
self.created_by,
self.text
)
return html
def get_header(self):
""" Informations included in headers """
return ('Note', [])
def as_inline_table(self):
html = format_html(
"<tr><th class='bg-success'><strong>{}</strong> <small>{}</small> \n\
<span class='label label-info pull-right'>{}</span></th>\n\
<tr><td>{}</td></tr>",
self.subclass.__qualname__,
self.created_date,
self.created_by,
self.text
)
return html
def get_date(self):
raise NotImplementedError
def header_label(self):
return self.get_header()[0]
def header_infos(self):
return self.get_header()[1]
def _get_child_and_subclass(self):
self._child_instance = None
self._subclass = None
for f in self._meta.get_fields():
if f.is_relation and f.one_to_one:
self._child_instance = getattr(self, f.name)
self._subclass = self._child_instance.__class__
return
@property
def date(self):
return self.get_date()
def subclass(self):
if not hasattr(self, '_subclass'):
self._get_child_and_subclass()
return self._subclass
def cast(self):
if not hasattr(self, '_child_instance'):
self._get_child_and_subclass()
return self._child_instance
def __str__(self):
return "%s of %s" % (self.subclass.__qualname__, self.created_by)