def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) if format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) c.sidebar_delegations = (_('Delegations are enabled.') if c.page_instance.allow_delegate else _('Delegations are disabled.')) #pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) #c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) #tags = model.Tag.popular_tags(limit=40) #c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if asbool(config.get('adhocracy.show_instance_overview_milestones')) \ and c.page_instance.milestones: number = asint(config.get( 'adhocracy.number_instance_overview_milestones', 3)) milestones = model.Milestone.all_future_q( instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time) events = model.Event.find_by_instance(c.page_instance, limit=3) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } c.tutorial_intro = _('tutorial_instance_show_intro') c.tutorial = 'instance_show' return render("/instance/show.html")
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) if format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) #pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) #c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) #tags = model.Tag.popular_tags(limit=40) #c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if c.page_instance.milestones: c.milestones = model.Milestone.all(instance=c.page_instance) c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } return render("/instance/show.html")
def index(self, format='html'): if c.instance: redirect(h.entity_url(c.instance)) if format == 'rss': return EventController().all(format='rss') name = config.get('adhocracy.redirect_startpage_to_instance') if name != u'': # get_entity_or_abort does no work for instances instance = model.Instance.find(name) if instance is not None: redirect(h.entity_url(instance)) data = {} instances_in_root = config.get_int( 'adhocracy.startpage.instances.list_length') if instances_in_root > 0: data['instances'] = model.Instance.all(limit=instances_in_root) elif instances_in_root == -1: data['instances'] = model.Instance.all() add_static_content(data, u'adhocracy.static_index_path') c.body_css_classes += data.get('css_classes', []) c.body_css_classes.append('added_static_content') if data['title'] is None: data['title'] = config.get('adhocracy.site.name') proposals_number = config.get_int( 'adhocracy.startpage.proposals.list_length') if proposals_number > 0: proposals = model.Proposal.all_q()\ .join(model.Instance).filter(not_( model.Instance.key.in_(model.Instance.SPECIAL_KEYS)))\ .order_by(model.Proposal.create_time.desc()) data['new_proposals_pager'] = pager.proposals( proposals, size=proposals_number, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False) else: data['new_proposals_pager'] = None if config.get_bool('adhocracy.show_stats_on_frontpage'): data['stats_global'] = { "members": model.User.all_q().count(), "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q().count(), "votes": model.Vote.all_q().count(), } if format == 'overlay': return render('index.html', data, overlay=True) else: return render('index.html', data)
def show(self, id, format="html"): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == "json": return render_json(c.page_instance) if format == "rss": return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest ) c.sidebar_delegations = ( _("Delegations are enabled.") if c.page_instance.allow_delegate else _("Delegations are disabled.") ) # pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) # c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) # tags = model.Tag.popular_tags(limit=40) # c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if asbool(config.get("adhocracy.show_instance_overview_milestones")) and c.page_instance.milestones: number = asint(config.get("adhocracy.number_instance_overview_milestones", 3)) milestones = model.Milestone.all_future_q(instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time ) events = model.Event.find_by_instance(c.page_instance, limit=3) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) c.stats = { "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q(instance=c.page_instance).count(), "members": model.Membership.all_q().count(), } c.tutorial_intro = _("tutorial_instance_show_intro") c.tutorial = "instance_show" return render("/instance/show.html")
def proposals(self, id, format='html'): c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) require.user.show(c.page_user) proposals = model.Proposal.find_by_creator(c.page_user) c.proposals_pager = pager.proposals(proposals) if format == 'json': return render_json(c.proposals_pager) self._common_metadata(c.page_user, member='proposals') return render("/user/proposals.html")
def dashboard_proposals(self, id): '''Render all proposals for all instances the use is member''' #user object c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) require.user.show(c.page_user) #instances instances = c.page_user.instances #proposals proposals = [model.Proposal.all(instance=i) for i in instances] proposals = proposals and reduce(lambda x, y: x + y, proposals) c.proposals_pager = pager.proposals(proposals) #render result return render("/user/proposals.html")
def index(self, format='html'): require.proposal.index() if c.instance: redirect(h.entity_url(c.instance)) instances_in_root = asint( config.get('adhocracy.startpage.instances.list_length', 0)) if instances_in_root > 0: c.instances = model.Instance.all(limit=instances_in_root) elif instances_in_root == -1: c.instances = model.Instance.all() c.page = get_static_page('index') proposals_number = asint( config.get('adhocracy.startpage.proposals.list_length', 0)) if proposals_number > 0: proposals = model.Proposal.all_q()\ .join(model.Instance).filter(not_( model.Instance.key.in_(model.Instance.SPECIAL_KEYS)))\ .order_by(model.Proposal.create_time.desc()) c.new_proposals_pager = pager.proposals( proposals, size=proposals_number, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False) else: c.new_proposals_pager = None if asbool(config.get('adhocracy.show_stats_on_frontpage', 'true')): c.stats_global = { "members": model.User.all_q().count(), "comments": model.Comment.all_q().count(), "proposals": model.Proposal.all_q().count(), "votes": model.Vote.all_q().count(), } if format == 'rss': return EventController().all(format='rss') return render('index.html')
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) if format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) proposals = model.Proposal.all(instance=c.page_instance) c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) #pages = model.Page.all(instance=c.page_instance, # functions=[model.Page.NORM]) #c.top_pages_pager = pager.pages( # pages, size=7, enable_sorts=False, # enable_pages=False, default_sort=sorting.norm_selections) #tags = model.Tag.popular_tags(limit=40) #c.tags = sorted(text.tag_cloud_normalize(tags), # key=lambda (k, c, v): k.name) if c.page_instance.milestones: c.milestones = model.Milestone.all(instance=c.page_instance) c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q(instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } return render("/instance/show.html")
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) elif format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) c.sidebar_delegations = (_('Delegations are enabled.') if c.page_instance.allow_delegate else _('Delegations are disabled.')) overview_contents = config.get_list( 'adhocracy.instance_overview_contents') overview_sidebar_contents = config.get_list( 'adhocracy.instance_overview_sidebar_contents') if u'milestones' in overview_contents and c.page_instance.milestones: number = config.get_int( 'adhocracy.number_instance_overview_milestones') milestones = model.Milestone.all_future_q( instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time) c.events_pager = None if u'events' in overview_contents: events = model.Event.find_by_instance(c.page_instance, limit=10) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) c.sidebar_events_pager = None if u'events' in overview_sidebar_contents: events = model.Event.find_by_instance(c.page_instance, limit=3) c.sidebar_events_pager = pager.events(events, enable_pages=False, enable_sorts=False, row_type=u'sidebar_row') c.proposals_pager = None if u'proposals' in overview_contents: proposals = model.Proposal.all(instance=c.page_instance) if config.get_bool( 'adhocracy.show_instance_overview_proposals_all'): c.proposals_pager = pager.proposals(proposals, size=100, initial_size=100) else: c.proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) c.stats = None if config.get_bool('adhocracy.show_instance_overview_stats'): c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } c.tutorial_intro = _('tutorial_instance_show_intro') c.tutorial = 'instance_show' if c.page_instance.hidden: h.flash(_(u"This instance is not yet open for public " u"participation."), 'warning') elif c.page_instance.frozen: h.flash(_(u"This instance is not active for use and is archived. " u"It isn't possible to perform any changes to the " u"instance, but all content is available to be read."), 'warning') if format == 'overlay': return render("/instance/show.html", overlay=True) else: return render("/instance/show.html")
def dashboard(self, id): '''Render a personalized dashboard for users''' if 'logged_in' in session: c.fresh_logged_in = True c.suppress_attention_getter = True del session['logged_in'] if 'came_from' in session: c.came_from = session.get('came_from') del session['came_from'] if isinstance(c.came_from, str): c.came_from = unicode(c.came_from, 'utf-8') session.save() #user object c.page_user = get_entity_or_abort(model.User, id, instance_filter=False) require.user.show(c.page_user) #instances instances = c.page_user.instances #proposals proposals = [model.Proposal.all(instance=i) for i in instances] proposals = proposals and reduce(lambda x, y: x + y, proposals) c.proposals = proposals c.proposals_pager = pager.proposals(proposals, size=4, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False) #polls polls = [p.adopt_poll for p in proposals if p.is_adopt_polling()] polls = filter(lambda p: p.has_ended() != True and p.is_deleted() != True, polls) c.polls = polls c.polls_pager = pager.polls(polls, size=20, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False,) #pages require.page.index() pages = [model.Page.all(instance=i, functions=model.Page.LISTED) for i in instances] pages = pages and reduce(lambda x, y: x + y, pages) c.pages = pages c.pages_pager = pager.pages(pages, size=3, default_sort=sorting.entity_newest, enable_pages=False, enable_sorts=False) #watchlist require.watch.index() c.active_global_nav = 'user' watches = model.Watch.all_by_user(c.page_user) entities = [w.entity for w in watches if (w.entity is not None) and (not isinstance(w.entity, unicode))] c.watchlist_pager = NamedPager( 'watches', entities, tiles.dispatch_row_with_comments, size=3, enable_pages=False, enable_sorts=False, default_sort=sorting.entity_newest) #render result c.tutorial = 'user_dashboard' c.tutorial_intro = _('tutorial_dashboard_title') return render('/user/dashboard.html')
def show(self, id, format='html'): c.page_instance = get_entity_or_abort(model.Instance, id) require.instance.show(c.page_instance) if format == 'json': return render_json(c.page_instance) if format == 'rss': return self.activity(id, format) if c.page_instance != c.instance: redirect(h.entity_url(c.page_instance)) c.tile = tiles.instance.InstanceTile(c.page_instance) c.sidebar_delegations = (_('Delegations are enabled.') if c.page_instance.allow_delegate else _('Delegations are disabled.')) if asbool(config.get('adhocracy.show_instance_overview_milestones')) \ and c.page_instance.milestones: number = asint(config.get( 'adhocracy.number_instance_overview_milestones', 3)) milestones = model.Milestone.all_future_q( instance=c.page_instance).limit(number).all() c.next_milestones_pager = pager.milestones( milestones, size=number, enable_sorts=False, enable_pages=False, default_sort=sorting.milestone_time) c.events_pager = None if asbool(config.get('adhocracy.show_instance_overview_events', 'true')): events = model.Event.find_by_instance(c.page_instance, limit=3) c.events_pager = pager.events(events, enable_pages=False, enable_sorts=False) proposals = model.Proposal.all(instance=c.page_instance) show_new_proposals_cfg = config.get( 'adhocracy.show_instance_overview_proposals_new') if show_new_proposals_cfg is None: # Fall back to legacy option show_new_proposals = asbool(config.get( 'adhocracy.show_instance_overview_proposals', 'true')) else: show_new_proposals = asbool(show_new_proposals_cfg) c.new_proposals_pager = None if asbool(show_new_proposals): c.new_proposals_pager = pager.proposals( proposals, size=7, enable_sorts=False, enable_pages=False, default_sort=sorting.entity_newest) c.all_proposals_pager = None if asbool(config.get('adhocracy.show_instance_overview_proposals_all', 'false')): c.all_proposals_pager = pager.proposals(proposals) c.stats = None if asbool(config.get('adhocracy.show_instance_overview_stats', 'true')): c.stats = { 'comments': model.Comment.all_q().count(), 'proposals': model.Proposal.all_q( instance=c.page_instance).count(), 'members': model.Membership.all_q().count() } c.tutorial_intro = _('tutorial_instance_show_intro') c.tutorial = 'instance_show' return render("/instance/show.html")