示例#1
0
文件: base.py 项目: whausen/part
    def __call__(self, environ, start_response):
        """Invoke the Controller"""

        c.instance = model.instance_filter.get_instance()
        if c.instance is not None:
            # setup a global variable to mark the current item in
            # the global navigation
            c.active_global_nav = 'instances'
        else:
            c.active_global_nav = 'home'
        c.user = environ.get('repoze.who.identity', {}).get('user')

        # make sure we're not using a detached user object
        if c.user:
            c.user = model.meta.Session.merge(c.user)

        if c.user and (c.user.banned or c.user.delete_time):
            c.user = None
        c.active_controller = request.environ.get('pylons.routes_dict')\
            .get('controller')
        c.debug = asbool(config.get('debug'))
        i18n.handle_request()

        monitor_page_time_interval = asint(
                config.get('adhocracy.monitor_page_time_interval', -1))
        if monitor_page_time_interval > 0:
            c.monitor_page_time_interval = monitor_page_time_interval
            c.monitor_page_time_url = h.base_url('/stats/on_page')

        if asbool(config.get('adhocracy.monitor_external_links', 'False')):
            c.monitor_external_links_url = h.base_url('/stats/record_external')

        h.add_rss("%s News" % h.site.name(),
                  h.base_url('/feed.rss', None))
        if c.instance:
            h.add_rss("%s News" % c.instance.label,
                      h.base_url('/instance/%s.rss' % c.instance.key))

        h.add_meta("description",
                   _("A liquid democracy platform for making decisions in "
                     "distributed, open groups by cooperatively creating "
                     "proposals and voting on them to establish their "
                     "support."))
        h.add_meta("keywords",
                   _("adhocracy, direct democracy, liquid democracy, liqd, "
                     "democracy, wiki, voting,participation, group decisions, "
                     "decisions, decision-making"))

        try:
            return WSGIController.__call__(self, environ, start_response)
        except Exception, e:
            log.exception(e)
            model.meta.Session.rollback()
            raise
示例#2
0
    def index(self, format='html'):
        require.instance.index()
        h.add_meta("description",
                   _("An index of instances run at this site. "
                     "Select which ones you would like to join "
                     "and participate!"))
        instances = model.Instance.all()

        if format == 'json':
            return render_json(instances)

        c.instances_pager = pager.instances(instances)
        return render("/instance/index.html")
示例#3
0
    def index(self, format='html'):
        require.instance.index()
        h.add_meta(
            "description",
            _("An index of instances run at this site. "
              "Select which ones you would like to join "
              "and participate!"))
        instances = model.Instance.all()

        if format == 'json':
            return render_json(instances)

        c.instances_pager = pager.instances(instances)
        return render("/instance/index.html")
示例#4
0
class BaseController(WSGIController):
    def __call__(self, environ, start_response):
        """Invoke the Controller"""

        c.instance = model.instance_filter.get_instance()
        if c.instance is not None:
            # setup a global variable to mark the current item in
            # the global navigation
            c.active_global_nav = 'instances'
        else:
            c.active_global_nav = 'home'
        c.user = environ.get('repoze.who.identity', {}).get('user')
        try:
            if c.user and (c.user.banned or c.user.delete_time):
                c.user = None
        except DetachedInstanceError, e:
            log.exception(e)
        c.active_controller = request.environ.get('pylons.routes_dict')\
            .get('controller')
        c.debug = asbool(config.get('debug'))
        i18n.handle_request()

        h.add_rss("%s News" % h.site.name(), h.base_url(None,
                                                        path='/feed.rss'))
        if c.instance:
            h.add_rss(
                "%s News" % c.instance.label,
                h.base_url(c.instance, '/instance/%s.rss' % c.instance.key))

        h.add_meta(
            "description",
            _("A liquid democracy platform for making decisions in "
              "distributed, open groups by cooperatively creating "
              "proposals and voting on them to establish their "
              "support."))
        h.add_meta(
            "keywords",
            _("adhocracy, direct democracy, liquid democracy, liqd, "
              "democracy, wiki, voting,participation, group decisions, "
              "decisions, decision-making"))

        try:
            return WSGIController.__call__(self, environ, start_response)
        except Exception, e:
            log.exception(e)
            model.meta.Session.rollback()
            raise
示例#5
0
 def _common_metadata(self, user, member=None, add_canonical=False):
     bio = user.bio
     if not bio:
         bio = _("%(user)s is using Adhocracy, a democratic "
                 "decision-making tool.") % {'user': c.page_user.name}
     description = h.truncate(text.meta_escape(bio), length=200,
                              whole_word=True)
     h.add_meta("description", description)
     h.add_meta("dc.title", text.meta_escape(user.name))
     h.add_meta("dc.date", user.access_time.strftime("%Y-%m-%d"))
     h.add_meta("dc.author", text.meta_escape(user.name))
     h.add_rss(_("%(user)ss Activity") % {'user': user.name},
               h.entity_url(user, format='rss'))
     if c.instance and not user.is_member(c.instance):
         h.flash(_("%s is not a member of %s") % (user.name,
                                                  c.instance.label),
                 'notice')
     if user.banned:
         h.flash(_("%s is banned from the system.") % user.name, 'notice')
示例#6
0
文件: base.py 项目: alkadis/vcv
    def __call__(self, environ, start_response):
        """Invoke the Controller"""

        c.body_css_classes = []
        c.body_css_classes.append('controller-' + self.identifier)

        if self.identifier in ['proposals', 'milestones', 'norms', 'category',
                               'members']:
            c.active_subheader_nav = self.identifier
            c.body_css_classes.append('area-' + self.identifier)

        c.instance = model.instance_filter.get_instance()
        if c.instance is not None:
            c.body_css_classes.append(u'instance-%s' % c.instance.key)
        # setup a global variable to mark the current item in
        # the global navigation
        global_nav = 'instances' if c.instance is not None else 'home'
        c.active_global_nav = global_nav
        c.body_css_classes.append('global_nav_' + global_nav)
        user_id = environ.get('repoze.who.identity', {}).get('user', None)
        user = None
        # make sure we're not using a detached user object
        if user_id is not None:
            user = model.meta.Session.merge(user_id)
        if user and (user.banned or user.delete_time):
            user = None
        if user is not None:
            c.body_css_classes.append('logged_in')
        else:
            c.body_css_classes.append('not_logged_in')
        c.user = user
        c.active_controller = request.environ.get('pylons.routes_dict')\
            .get('controller')
        c.debug = config.get_bool('debug')
        i18n.handle_request()

        if h.site.is_local_url(request.params.get(u'came_from', u'')):
            c.came_from = request.params.get(u'came_from', u'')

        monitor_page_time_interval = config.get_int(
            'adhocracy.monitor_page_time_interval', -1)
        c.page_stats_url = h.base_url('/stats/on_page')
        if monitor_page_time_interval > 0:
            c.monitor_page_time_interval = monitor_page_time_interval

        if config.get_bool('adhocracy.monitor_external_links'):
            c.monitor_external_links_url = h.base_url('/stats/record_external')

        if config.get_bool('adhocracy.monitor_browser_values'):
            c.monitor_browser_values = "enabled"
        if config.get_bool('adhocracy.monitor_extended'):
            c.monitor_extended = "enabled"
        if config.get_bool('adhocracy.monitor_page_performance'):
            c.monitor_page_performance = "enabled"

        if config.get_bool('adhocracy.monitor_pager_clicks'):
            c.monitor_pager_clicks = "enabled"

        h.add_rss("%s News" % h.site.name(),
                  h.base_url('/feed.rss', None))
        if c.instance:
            h.add_rss("%s News" % c.instance.label,
                      h.base_url('/instance/%s.rss' % c.instance.key))

        h.add_meta("description", config.get(
            'adhocracy.site.description',
            _(u"A liquid democracy platform for making decisions in "
              u"distributed, open groups by cooperatively creating "
              u"proposals and voting on them to establish their "
              u"support.")))

        h.add_meta("keywords",
                   _("adhocracy, direct democracy, liquid democracy, liqd, "
                     "democracy, wiki, voting,participation, group decisions, "
                     "decisions, decision-making"))

        try:
            return WSGIController.__call__(self, environ, start_response)
        except Exception, e:
            log.exception(e)
            model.meta.Session.rollback()
            raise
示例#7
0
    def __call__(self, environ, start_response):
        """Invoke the Controller"""

        c.instance = model.instance_filter.get_instance()
        if c.instance is not None:
            # setup a global variable to mark the current item in
            # the global navigation
            c.active_global_nav = 'instances'
        else:
            c.active_global_nav = 'home'
        c.user = environ.get('repoze.who.identity', {}).get('user')

        # make sure we're not using a detached user object
        if c.user:
            c.user = model.meta.Session.merge(c.user)

        if c.user and (c.user.banned or c.user.delete_time):
            c.user = None
        c.active_controller = request.environ.get('pylons.routes_dict')\
            .get('controller')
        c.debug = config.get_bool('debug')
        i18n.handle_request()

        monitor_page_time_interval = config.get_int(
            'adhocracy.monitor_page_time_interval', -1)
        c.page_stats_url = h.base_url('/stats/on_page')
        if monitor_page_time_interval > 0:
            c.monitor_page_time_interval = monitor_page_time_interval

        if config.get_bool('adhocracy.monitor_external_links', False):
            c.monitor_external_links_url = h.base_url('/stats/record_external')

        if config.get_bool('adhocracy.monitor_browser_values', False):
            c.monitor_browser_values = "enabled"
        if config.get_bool('adhocracy.monitor_extended', False):
            c.monitor_extended = "enabled"
        if config.get_bool('adhocracy.monitor_page_performance', False):
            c.monitor_page_performance = "enabled"

        if config.get_bool('adhocracy.monitor_pager_clicks', False):
            c.monitor_pager_clicks = "enabled"

        h.add_rss("%s News" % h.site.name(),
                  h.base_url('/feed.rss', None))
        if c.instance:
            h.add_rss("%s News" % c.instance.label,
                      h.base_url('/instance/%s.rss' % c.instance.key))

        h.add_meta("description", config.get(
            'adhocracy.site.description',
            _(u"A liquid democracy platform for making decisions in "
              u"distributed, open groups by cooperatively creating "
              u"proposals and voting on them to establish their "
              u"support.")))

        h.add_meta("keywords",
                   _("adhocracy, direct democracy, liquid democracy, liqd, "
                     "democracy, wiki, voting,participation, group decisions, "
                     "decisions, decision-making"))

        try:
            return WSGIController.__call__(self, environ, start_response)
        except Exception, e:
            log.exception(e)
            model.meta.Session.rollback()
            raise
示例#8
0
    def __call__(self, environ, start_response):
        """Invoke the Controller"""

        c.body_css_classes = []
        c.body_css_classes.append('controller-' + self.identifier)

        if self.identifier in [
                'proposals', 'milestones', 'norms', 'category', 'members'
        ]:
            c.active_subheader_nav = self.identifier
            c.body_css_classes.append('area-' + self.identifier)

        c.instance = model.instance_filter.get_instance()
        if c.instance is not None:
            c.body_css_classes.append(u'instance-%s' % c.instance.key)
        # setup a global variable to mark the current item in
        # the global navigation
        global_nav = 'instances' if c.instance is not None else 'home'
        c.active_global_nav = global_nav
        c.body_css_classes.append('global_nav_' + global_nav)
        user_id = environ.get('repoze.who.identity', {}).get('user', None)
        user = None
        # make sure we're not using a detached user object
        if user_id is not None:
            user = model.meta.Session.merge(user_id)
        if user and (user.banned or user.delete_time):
            user = None
        if user is not None:
            c.body_css_classes.append('logged_in')
        else:
            c.body_css_classes.append('not_logged_in')
        c.user = user
        c.active_controller = request.environ.get('pylons.routes_dict')\
            .get('controller')
        c.debug = config.get_bool('debug')
        i18n.handle_request()

        if h.site.is_local_url(request.params.get(u'came_from', u'')):
            c.came_from = request.params.get(u'came_from', u'')

        monitor_page_time_interval = config.get_int(
            'adhocracy.monitor_page_time_interval', -1)
        c.page_stats_url = h.base_url('/stats/on_page')
        if monitor_page_time_interval > 0:
            c.monitor_page_time_interval = monitor_page_time_interval

        if config.get_bool('adhocracy.monitor_external_links'):
            c.monitor_external_links_url = h.base_url('/stats/record_external')

        if config.get_bool('adhocracy.monitor_browser_values'):
            c.monitor_browser_values = "enabled"
        if config.get_bool('adhocracy.monitor_extended'):
            c.monitor_extended = "enabled"
        if config.get_bool('adhocracy.monitor_page_performance'):
            c.monitor_page_performance = "enabled"

        if config.get_bool('adhocracy.monitor_pager_clicks'):
            c.monitor_pager_clicks = "enabled"

        h.add_rss("%s News" % h.site.name(), h.base_url('/feed.rss', None))
        if c.instance:
            h.add_rss("%s News" % c.instance.label,
                      h.base_url('/instance/%s.rss' % c.instance.key))

        h.add_meta(
            "description",
            config.get(
                'adhocracy.site.description',
                _(u"A liquid democracy platform for making decisions in "
                  u"distributed, open groups by cooperatively creating "
                  u"proposals and voting on them to establish their "
                  u"support.")))

        h.add_meta(
            "keywords",
            _("adhocracy, direct democracy, liquid democracy, liqd, "
              "democracy, wiki, voting,participation, group decisions, "
              "decisions, decision-making"))

        try:
            return WSGIController.__call__(self, environ, start_response)
        except Exception, e:
            log.exception(e)
            model.meta.Session.rollback()
            raise