diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 5141ed66d..45ce9f504 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1661,52 +1661,68 @@ class QuickAction(object): """ Quick action available from tables """ - def __init__(self, url, icon='', text='', target=None, rights=None): + def __init__(self, url, icon_class='', text='', target=None, rights=None, + module=None): self.url = url - self.icon = icon + self.icon_class = icon_class self.text = text self.rights = rights self.target = target + self.module = module assert self.target in ('one', 'many', None) def is_available(self, user, session=None, obj=None): + if self.module and not getattr(get_current_profile(), self.module): + return False if not self.rights: # no restriction return True + if not user or not hasattr(user, 'ishtaruser') or not user.ishtaruser: + return False + user = user.ishtaruser + for right in self.rights: if user.has_perm(right, session=session, obj=obj): return True return False - def render(self): - lbl = self.text - if self.icon: - lbl = self.icon + @property + def rendered_icon(self): + if not self.icon_class: + return "" + return u"<i class='{}' aria-hidden='true'></i>".format(self.icon_class) + + @property + def base_url(self): if self.target is None: url = reverse(self.url) else: # put arbitrary pk for the target url = reverse(self.url, args=[0]) - url = url[:-1] # all quick action url have to finish with the - # pk of the selected item - return u'<a href="#" data-url="{}" title="{}">{}</a>'.format( - url, self.text, lbl - ) + url = url[:-2] # all quick action url have to finish with the + # pk of the selected item and a "/" + return url class MainItem(ShortMenuItem): """ - Item with quick actions availables from tables + Item with quick actions available from tables """ QUICK_ACTIONS = [] @classmethod - def render_quick_actions(cls, user, session=None, obj=None): - rendered = [] + def get_quick_actions(cls, user, session=None, obj=None): + """ + Get a list of (url, title, icon, target) actions for an user + """ + qas = [] for action in cls.QUICK_ACTIONS: if not action.is_available(user, session=session, obj=obj): continue - rendered.append(action.render()) - return mark_safe(u" ".join(rendered)) + qas.append([action.base_url, + mark_safe(action.text), + mark_safe(action.rendered_icon), + action.target or ""]) + return qas class LightHistorizedItem(BaseHistorizedItem): |