Пример #1
0
def render_proposal_text(request,
                         proposal,
                         tag_func=tags2links,
                         diff_brief=True):
    """ Render a proposal as a diff or as the original text. """
    if not IProposal.providedBy(proposal):
        raise TypeError("%s is not a proposal" % proposal)
    if proposal.diff_text_para is None:
        # This is a regular proposal without the diff functions active
        return request.transform_text(proposal.text, tag_func=tag_func)
    else:
        ai = request.agenda_item
        if ai is None:
            ai = proposal.__parent__
        diff_text = IDiffText(ai)
        paragraphs = diff_text.get_paragraphs()
        try:
            original = paragraphs[proposal.diff_text_para]
        except (TypeError, IndexError):
            # Simply abort
            return request.transform_text(proposal.text, tag_func=tag_func)
        text = ""
        if proposal.diff_text_leadin:
            text += tag_func(proposal.diff_text_leadin) + "\n\n"
        text += diff_text(original, proposal.text, brief=diff_brief)
        return nl2br(text).unescape()
Пример #2
0
def like_action(context, request, va, **kw):
    context_types = request.meeting.like_context_types
    workflow_states = request.meeting.like_workflow_states
    state = request.meeting.like_button_state
    success_threshold = request.meeting.like_success_threshold

    if state == LIKE_SETTING_HIDDEN:
        return
    if not context_types or context.type_name not in context_types:
        return
    if IProposal.providedBy(context):
        if workflow_states and context.get_workflow_state() not in workflow_states:
            return
    like = request.registry.getAdapter(context, IUserTags, name = 'like')
    try:
        has_like_perm = request._has_like_perm
    except AttributeError:
        request._has_like_perm = has_like_perm = _check_add_perm(like, request)
    response = {'context': context,
                'like': like,
                'has_like_perm': has_like_perm,
                'user_likes': request.authenticated_userid in like,
                'success': (success_threshold > 0) and (len(like) >= success_threshold)}
    if state == LIKE_SETTING_ACTIVE:
        template_name = 'voteit.core.plugins:templates/like_btn.pt'
    else:
        template_name = 'voteit.core.plugins:templates/like_btn_readonly.pt'
    return render(template_name, response, request=request)
Пример #3
0
def get_tags(object, default):
    """ We only use tags for Discussions and Proposals.
        Warning! An empty list doesn't update the catalog.
        If default is returned to an index, it will cause that index to remove index,
        which is the correct behaviour for the catalog.
    """
    if IDiscussionPost.providedBy(object) or IProposal.providedBy(object):
        return tuple(object.get_tags(default))
    return default
Пример #4
0
def get_tags(object, default):
    """ We only use tags for Discussions and Proposals.
        Warning! An empty list doesn't update the catalog.
        If default is returned to an index, it will cause that index to remove index,
        which is the correct behaviour for the catalog.
    """
    if IDiscussionPost.providedBy(object) or IProposal.providedBy(object):
        return tuple(object.get_tags(default))
    return default
Пример #5
0
def get_like_userids(object, default):
    """ Returns all userids who 'like' something.
        We only use like for Discussions and Proposals.
        Warning! An empty list doesn't update the catalog.
        If default is returned to an index, it will cause that index to remove index,
        which is the correct behaviour for the catalog.
    """
    if IDiscussionPost.providedBy(object) or IProposal.providedBy(object):
        user_tags = getAdapter(object, IUserTags)
        likes = user_tags.userids_for_tag('like')
        if likes:
            return likes
    return default
Пример #6
0
def get_like_userids(object, default):
    """ Returns all userids who 'like' something.
        We only use like for Discussions and Proposals.
        Warning! An empty list doesn't update the catalog.
        If default is returned to an index, it will cause that index to remove index,
        which is the correct behaviour for the catalog.
    """
    if IDiscussionPost.providedBy(object) or IProposal.providedBy(object):
        user_tags = getAdapter(object, IUserTags)
        likes = user_tags.userids_for_tag('like')
        if likes:
            return likes
    return default
Пример #7
0
 def __call__(self):
     """ Start the decision process.
         * Block proposals
         * Make all proposals that aren't marked with 'bifall yrkat' unhandled.
     """
     # context is the agenda item - block proposals
     self.context.proposal_block = True
     # Change all proposals that are published to unhandled, if they aren't marked as 'bifall yrkat'
     count = 0
     for obj in self.context.values():
         if IProposal.providedBy(obj) and obj.get_workflow_state(
         ) == 'published' and not getattr(obj, ATTR_NAME, False):
             unrestricted_wf_transition_to(obj, 'unhandled')
             count += 1
     self.flash_messages.add("{} förslag justerade".format(count))
     return HTTPFound(location=self.request.resource_url(self.context))
Пример #8
0
def evolve(root):
    """ Change the Proposals so title and text are separated.
        Old proposals used to have only a title field that could be really long.
        
        Also add portlets to all meetings.
    """
    from arche.utils import find_all_db_objects
    from arche.portlets import get_portlet_manager
    from voteit.core.models.meeting import add_default_portlets_meeting

    manager = get_portlet_manager(root)
    if not manager.get_portlets('right', 'meeting_list'):
        manager.add('right', 'meeting_list')

    for obj in find_all_db_objects(root):
        if IProposal.providedBy(obj):
            try:
                obj.text = obj.field_storage.pop('title')
            except KeyError:
                pass
        elif IMeeting.providedBy(obj):
            add_default_portlets_meeting(obj)
Пример #9
0
def render_proposal_text(request, proposal, tag_func=tags2links):
    """ Render a proposal as a diff or as the original text. """
    if not IProposal.providedBy(proposal):
        raise TypeError("%s is not a proposal" % proposal)
    if proposal.diff_text_para is None:
        #This is a regular proposal without the diff functions active
        return request.transform_text(proposal.text, tag_func=tag_func)
    else:
        ai = request.agenda_item
        if ai is None:
            ai = proposal.__parent__
        diff_text = IDiffText(ai)
        paragraphs = diff_text.get_paragraphs()
        try:
            original = paragraphs[proposal.diff_text_para]
        except (TypeError, IndexError):
            #Simply abort
            return request.transform_text(proposal.text, tag_func=tag_func)
        text = ""
        if proposal.diff_text_leadin:
            text += tag_func(proposal.diff_text_leadin) + "\n\n"
        text += diff_text(original, proposal.text, brief=True)
        return nl2br(text).unescape()
Пример #10
0
def _check_add_perm(adapter, request):
    if request.meeting is None:
        meeting = find_interface(adapter.context, IMeeting)
    else:
        meeting = request.meeting
    like_context_types = meeting.like_context_types
    like_workflow_states = meeting.like_workflow_states
    like_user_roles = meeting.like_user_roles
    user_meeting_roles = meeting.local_roles.get(request.authenticated_userid, ())

    # Check if context can be liked
    if not like_context_types or adapter.context.type_name not in like_context_types:
        return False

    # If proposal, check if workflow state can be liked
    if IProposal.providedBy(adapter.context):
        if like_workflow_states and adapter.context.get_workflow_state() not in like_workflow_states:
            return False

    # Lastly, check if user has a role that can like
    if like_user_roles and not like_user_roles.intersection(user_meeting_roles):
        return False

    return True
Пример #11
0
def get_aid_int(object, default):
    if IProposal.providedBy(object):
        return object.get_field_value('aid_int', default)
    return default
Пример #12
0
def get_aid(object, default):
    """ Objects automatic id. """
    if IProposal.providedBy(object):
        return object.get_field_value('aid', default)
    return default
Пример #13
0
def get_searchable_prop_or_disc(context, default):
    if IProposal.providedBy(context) or IDiscussionPost.providedBy(context):
        return context.text
    return default
Пример #14
0
def get_searchable_prop_or_disc(context, default):
    if IProposal.providedBy(context) or IDiscussionPost.providedBy(context):
        return context.text
    return default
Пример #15
0
def get_aid_int(obj, default):
    if IProposal.providedBy(obj):
        return obj.get_field_value('aid_int', default)
    return default
Пример #16
0
def get_aid(obj, default):
    """ Objects automatic id. """
    if IProposal.providedBy(obj):
        return obj.get_field_value('aid', default)
    return default