Skip to content

Commit

Permalink
http://luc.lino-framework.org/blog/2015/0723.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaffre committed Jul 23, 2015
1 parent f9b1166 commit aea6482
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 77 deletions.
3 changes: 3 additions & 0 deletions THANKS.txt
Expand Up @@ -7,6 +7,9 @@ Publications
Here is a list of other publications who are at least partially being
distributed with Lino.

- :srcref:`/lino/utils/xmlgen/html.py` is a modified copy of the
ElementTree toolkit, Copyright (c) 1999-2004 by Fredrik Lundh.

- :srcref:`/media/extjs/Ext.ux.form.DateTime.js` :
Copyright (c) 2008, Ing. Jozef Sakáloš.

Expand Down
Binary file modified docs/tutorials/pisa/pisa.Person-1.pdf
Binary file not shown.
9 changes: 1 addition & 8 deletions docs/warnings_html.txt
@@ -1,8 +1 @@
/home/luc/hgwork/lino/docs/api/lino.modlib.clocking.ui.rst:26: WARNING: failed to import ServiceReport
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:29: WARNING: failed to import gfk2lookup
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import ByUser
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import ContactRelated
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import InterestsByUser
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import MyInterests
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import SiteStaff
/home/luc/hgwork/lino/docs/api/lino.modlib.tickets.ui.rst:42: WARNING: failed to import UserAuthored
/home/luc/hgwork/lino/docs/api/lino.modlib.ledger.models.rst:29: WARNING: failed to import customize_accounts
35 changes: 23 additions & 12 deletions lino/core/renderer.py
Expand Up @@ -12,19 +12,21 @@
logger = logging.getLogger(__name__)

from cgi import escape
from atelier import rstgen

from django.conf import settings
from django.utils.encoding import force_unicode

from django.utils.translation import ugettext as _
from django.utils.translation import get_language


from lino.utils.xmlgen.html import RstTable
from lino.utils import isiterable
from lino.utils.xmlgen.html import E
from lino.core import constants
# from lino.utils.xmlgen.html import _html2rst as html2rst
from lino.utils.xmlgen.html import html2rst
# from lino.utils.xmlgen.html import html2rst

from . import elems

Expand Down Expand Up @@ -91,12 +93,12 @@ def js2url(self, js):
def href(self, url, text):
return E.a(text, href=url)

def show_table(self, ar, **kw):
def show_table(self, ar, nosummary=False, **kw):
"""Returns a HTML element representing the given action request as a
table.
table. See :meth:`ar.show <lino.core.request.BaseRequest.show>`.
"""
if ar.actor.master is not None:
if ar.actor.master is not None and not nosummary:
if ar.actor.slave_grid_format == 'summary':
return E.tostring(
ar.actor.get_slave_summary(ar.master_instance, ar))
Expand Down Expand Up @@ -349,13 +351,17 @@ def unused_show_request(self, ar, *args, **kw):
# print(ar.table2rst(*args, **kw))
# return ar.to_rst(*args, **kw)

def show_table(self, ar, column_names=None, header_level=None, **kwargs):
"""Render the given table request as reStructuredText to stdout."""
def show_table(self, ar, column_names=None, header_level=None,
nosummary=False, stripped=True, **kwargs):
"""Render the given table request as reStructuredText to stdout.
See :meth:`ar.show <lino.core.request.BaseRequest.show>`.
"""

if ar.actor.master is not None:
if ar.actor.master is not None and not nosummary:
if ar.actor.slave_grid_format == 'summary':
print(html2rst(
ar.actor.get_slave_summary(ar.master_instance, ar)))
print(E.to_rst(
ar.actor.get_slave_summary(ar.master_instance, ar),
stripped=stripped))
return

fields, headers, widths = ar.get_field_info(column_names)
Expand All @@ -367,7 +373,11 @@ def show_table(self, ar, column_names=None, header_level=None, **kwargs):
recno += 1
rows.append([x for x in ar.row2text(fields, row, sums)])
if len(rows) == 0:
print("\n{0}\n".format(unicode(ar.no_data_text)))
s = unicode(ar.no_data_text)
if stripped:
print(s)
else:
print("\n", s, "\n")
return

if not ar.actor.hide_sums:
Expand All @@ -383,7 +393,8 @@ def show_table(self, ar, column_names=None, header_level=None, **kwargs):
t = RstTable(headers, **kwargs)
s = t.to_rst(rows)
if header_level is not None:
s = E.tostring(E.h2(ar.get_title())) + s
print(rstgen.header(header_level, ar.get_title()))
# s = E.tostring(E.h2(ar.get_title())) + s
print(s)

def show_story(self, ar, story, *args, **kwargs):
Expand All @@ -393,7 +404,7 @@ def show_story(self, ar, story, *args, **kwargs):

for item in story:
if E.iselement(item):
print(html2rst(item))
print(E.to_rst(item))
elif isinstance(item, type) and issubclass(item, Actor):
ar = item.default_action.request(parent=ar)
self.show_table(ar, *args, **kwargs)
Expand Down
16 changes: 12 additions & 4 deletions lino/core/requests.py
Expand Up @@ -561,17 +561,24 @@ def story2rst(self, story, *args, **kwargs):
return self.renderer.show_story(self, story, *args, **kwargs)

def show(self, spec, master_instance=None, column_names=None,
header_level=None, language=None, **kwargs):
header_level=None, language=None, nosummary=False,
stripped=True, **kwargs):
"""Show the specified table or action using the current renderer. If
the table is a :term:`slave table`, then a `master_instance` must
be specified as second argument.
The first argument, `spec` is forwarded to :meth:`spawn`.
The first argument specifies the table or actor to show. It is
forwarded to :meth:`spawn`.
Optional keyword arguments are:
:column_names: overrides default list of columns
:nosummary: if it is a table with :attr:`slave_grid_format
<lino.core.tables.AbstractTable.slave_grid_format>`
set to ``'summary'``, force rendering it as a
table.
:header_level: show also the header (using specified level)
:language: overrides the default language used for headers and
Expand Down Expand Up @@ -607,7 +614,8 @@ def doit():
story = ar.actor.get_story(None, ar)
return ar.renderer.show_story(self, story)
return ar.renderer.show_table(
ar, column_names=column_names, header_level=header_level)
ar, column_names=column_names, header_level=header_level,
nosummary=nosummary, stripped=stripped)

if language:
with translation.override(language):
Expand Down Expand Up @@ -666,7 +674,7 @@ def row_action_button_ar(self, obj, *args, **kw):
def ar2button(self, *args, **kw):
"""Return an HTML element with a button for running this action
request. Does not spawn another request. Does not check
permission.
permissions.
"""
return self.renderer.ar2button(self, *args, **kw)
Expand Down
4 changes: 2 additions & 2 deletions lino/modlib/contenttypes/mixins.py
Expand Up @@ -17,8 +17,8 @@ class Controllable(dd.Model):

"""Mixin for models that are "controllable" by another database object.
Defines three fields :attr:`owned_type`, :attr:`owned_id` and :attr:`owned`. And a class
attribute :attr:`owner_label`.
Defines three fields :attr:`owned_type`, :attr:`owned_id` and
:attr:`owned`. And a class attribute :attr:`owner_label`.
For example in :mod:`lino.modlibs.cal`, the owner of a Task or Event
is some other database object that caused the task's or event's
Expand Down
2 changes: 1 addition & 1 deletion lino/modlib/stars/__init__.py
@@ -1,7 +1,7 @@
# Copyright 2008-2015 Luc Saffre
# License: BSD (see file COPYING for details)

"""Adds functionality for starring database objects (marking them as
"""Adds functionality for "starring" database objects (marking them as
"favourite").
.. autosummary::
Expand Down
15 changes: 15 additions & 0 deletions lino/modlib/stars/models.py
Expand Up @@ -16,6 +16,21 @@


class Star(UserAuthored, Controllable):
"""Represents the fact that a given database object is starred by a
given User.
.. attribute:: owner
The starred database object
.. attribute:: user
The starring user (pointer to :class:lino.modlib.users.models.User`
"""

controller_is_optional = False

class Meta:
verbose_name = _("Star")
verbose_name_plural = _("Stars")
Expand Down
14 changes: 8 additions & 6 deletions lino/modlib/uploads/models.py
Expand Up @@ -224,18 +224,20 @@ def format_row_in_slave_summary(self, ar, obj):
@classmethod
def get_slave_summary(self, obj, ar):
"""Displays the uploads related to this controller as a list grouped
by uploads type.
by uploads type.
Note that this also works on
:class:`lino_welfare.modlib.uploads.models.UploadsByClient` and their
subclasses for the different `_upload_area`.
Note that this also works on
:class:`lino_welfare.modlib.uploads.models.UploadsByClient`
and their subclasses for the different `_upload_area`.
"""
UploadType = rt.modules.uploads.UploadType
# Upload = rt.modules.uploads.Upload
elems = []
types = []

perm = ar.get_user().profile.has_required_roles(self.required_roles)

for ut in UploadType.objects.filter(upload_area=self._upload_area):
sar = ar.spawn(
self, master_instance=obj,
Expand Down Expand Up @@ -264,8 +266,8 @@ def get_slave_summary(self, obj, ar):
files.append(E.span(edit, ' ', show))
else:
files.append(edit)
if ut.wanted and (
ut.max_number < 0 or len(files) < ut.max_number):
if perm and ut.wanted \
and (ut.max_number < 0 or len(files) < ut.max_number):
btn = self.insert_action.request_from(
sar, master_instance=obj,
known_values=dict(type_id=ut.id)).ar2button()
Expand Down

0 comments on commit aea6482

Please sign in to comment.