ctdo-trac/TracRendezVous/tracrendezvous/rendezvous/macros.py

89 lines
3.7 KiB
Python
Raw Normal View History

2012-03-31 15:45:24 +00:00
# -*- coding: utf-8 -*-
from genshi.builder import tag
from trac.util.translation import _
from trac.wiki.macros import WikiMacroBase
from tracrendezvous.rendezvous import api
from tracrendezvous.rendezvous import model
__all__ = ['ExpiredRendezVousesMacro', 'CanceledRendezVousesMacro', 'ScheduledRendezVousesMacro']
class ExpiredRendezVousesMacro(WikiMacroBase):
"""Renders an overview of canceled or expired !RendezVouses"""
revision = "$Rev: 186 $"
def expand_macro(self, formatter, name, content):
if 'RENDEZVOUS_VIEW' not in formatter.perm:
return ""
uperm = model.RendezVousTypePermissionSystem(self.env)
controller = api.RendezVousSystem(self.env).workflow_controller
ls = controller.expired_rendezvouses()
lsr = [tag.li(tag.a("%s: (%s)" % (i.name, i.status), href=formatter.href.rendezvous(i.rendezvous_id)))
for i in ls
if 'RENDEZVOUS_ADMIN' in formatter.perm or uperm.check_user_type_permissions(formatter.req.authname, i.type_id)]
if lsr:
return tag.div([tag.ul(lsr)])
return None
class CanceledRendezVousesMacro(WikiMacroBase):
"""Renders an overview of canceled or expired !RendezVouses"""
revision = "$Rev: 186 $"
def expand_macro(self, formatter, name, content):
if 'RENDEZVOUS_VIEW' not in formatter.perm:
return ""
uperm = model.RendezVousTypePermissionSystem(self.env)
controller = api.RendezVousSystem(self.env).workflow_controller
ls = controller.canceled_rendezvouses()
lsr = [tag.li(tag.a("%s: (%s)" % (i.name, i.status), href=formatter.href.rendezvous(i.rendezvous_id)))
for i in ls
if 'RENDEZVOUS_ADMIN' in formatter.perm or uperm.check_user_type_permissions(formatter.req.authname, i.type_id)]
if lsr:
return tag.div([tag.ul(lsr)])
return None
class CurrentRendezVousesMacro(WikiMacroBase):
"""Renders an overview of current !RendezVouses"""
revision = "$Rev:$"
def expand_macro(self, formatter, name, content):
if 'RENDEZVOUS_VIEW' not in formatter.perm:
return ""
uperm = model.RendezVousTypePermissionSystem(self.env)
controller = api.RendezVousSystem(self.env).workflow_controller
ls = controller.voting_rendezvouses()
lsr = [tag.li(tag.a("%s: (%s)" % (i.name, i.status), href=formatter.href.rendezvous(i.rendezvous_id)))
for i in ls
if 'RENDEZVOUS_ADMIN' in formatter.perm or uperm.check_user_type_permissions(formatter.req.authname, i.type_id)]
if lsr:
return tag.div([tag.ul(lsr)])
return None
class ScheduledRendezVousesMacro(WikiMacroBase):
"""Renders an overview of scheduled !RendezVouses"""
revision = "$Rev: 186 $"
def expand_macro(self, formatter, name, content):
if 'RENDEZVOUS_VIEW' not in formatter.perm:
return ""
uperm = model.RendezVousTypePermissionSystem(self.env)
controller = api.RendezVousSystem(self.env).workflow_controller
rendezvouses = controller.scheduled_rendezvouses(check=True)
lsr = []
for i in rendezvouses:
if i.elected and ('RENDEZVOUS_ADMIN' in formatter.perm or uperm.check_user_type_permissions(formatter.req.authname, i.type_id)):
lsr.append(tag.li(tag.a("%s: %s - %s" % (i.name, i.get_date(i.elected).time_begin.strftime('%Y.%m.%d %H:%M'), i.get_date(i.elected).time_end.strftime('%Y.%m.%d %H:%M')), href=formatter.href.rendezvous(i.rendezvous_id))))
if lsr:
return tag.div([tag.ul(lsr, style="list-style-image:url(%s)" % formatter.href("/chrome/hw/images/selected.png"))])
return None