Пример #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("config_uri",
                        help="Paster ini file to load settings from")
    parser.add_argument("meeting_from", help="From-meeting")
    parser.add_argument("meeting_to", help="To-meeting")
    args = parser.parse_args()
    env = bootstrap(args.config_uri)
    root = env['root']
    meeting_from = root[args.meeting_from]
    meeting_to = root[args.meeting_to]
    print "Creating a copy of delegations"
    print "------------------------------"
    print "From: %s" % args.meeting_from
    print "To:   %s" % args.meeting_to
    print "------------------------------"

    new_delegations = IMeetingDelegations(meeting_to)
    for from_delegation in IMeetingDelegations(meeting_from).values():
        new_name = new_delegations.new()
        delegation = new_delegations[new_name]
        print "found %s" % from_delegation.title
        delegation.title = from_delegation.title
    transaction.commit()
    env['closer']()
Пример #2
0
def evolve(root):
    from voteit.core.models.interfaces import IMeeting
    from BTrees.OOBTree import OOSet
    from sfs_ga.interfaces import IMeetingDelegations

    for obj in root.values():
        if not IMeeting.providedBy(obj):
            continue
        delegations = IMeetingDelegations(obj)
        for delegation in delegations.values():
            for attr in ('pn_leaders', 'pn_members'):
                if not hasattr(delegation, attr):
                    setattr(delegation, attr, OOSet())
Пример #3
0
def _get_delegation_title(userid, request):
    try:
        cached_delegation_titles = request._cached_delegation_titles
    except AttributeError:
        cached_delegation_titles = request._cached_delegation_titles = {}
    try:
        return request._cached_delegation_titles[userid]
    except KeyError:
        delegations = IMeetingDelegations(request.meeting, None)
        if delegations is not None:
            delegation = delegations.get_delegation_for(userid)
            if delegation:
                cached_delegation_titles[userid] = delegation.title
            else:
                cached_delegation_titles[userid] = ""
    return cached_delegation_titles[userid]
Пример #4
0
class DelegationPNValidator(object):

    def __init__(self, meeting, delegation_name, type_attr):
        self.meeting = meeting
        self.delegations = IMeetingDelegations(meeting)
        self.delegation = self.delegations[delegation_name]
        self.type_attr = type_attr
        self.pn_attr = "pn_" + type_attr
        #Just as a safeguard
        assert hasattr(self.delegation, self.type_attr)
        assert hasattr(self.delegation, self.pn_attr)

    def __call__(self, node, value):
        other_delegations = [v for (k, v) in self.delegations.items() if k != self.delegation.name]
        already_used_pns = set()
        for delegation in other_delegations:
            already_used_pns.update(getattr(delegation, self.pn_attr, ()))
        duplicate = already_used_pns & set(value)
        if duplicate:
            msg = "Följande nummer har redan använts i andra delegationer: "
            msg += ", ".join([str(x) for x in duplicate])
            raise colander.Invalid(node, msg)
        pns = IParticipantNumbers(self.meeting)
        for pn in value:
            userid = pns.number_to_userid.get(pn, None)
            if userid:
                for delegation in other_delegations:
                    if userid in getattr(delegation, self.type_attr):
                        msg = "Deltagarnummer %r mappar till '%s' som redan är med i delegationen '%s'"\
                            % (pn, userid, delegation.title)
                        raise colander.Invalid(node, msg)
Пример #5
0
 def __init__(self, meeting, delegation_name, type_attr):
     self.meeting = meeting
     self.delegations = IMeetingDelegations(meeting)
     self.delegation = self.delegations[delegation_name]
     self.type_attr = type_attr
     self.pn_attr = "pn_" + type_attr
     #Just as a safeguard
     assert hasattr(self.delegation, self.type_attr)
     assert hasattr(self.delegation, self.pn_attr)
Пример #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("config_uri", help = "Paster ini file to load settings from")
    parser.add_argument("meeting_from", help = "From-meeting")
    parser.add_argument("meeting_to", help = "To-meeting")
    args = parser.parse_args()
    env = bootstrap(args.config_uri)
    root = env['root']
    meeting_from = root[args.meeting_from]
    meeting_to = root[args.meeting_to]
    print "Creating a copy of delegations"
    print "------------------------------"
    print "From: %s" % args.meeting_from
    print "To:   %s" % args.meeting_to
    print "------------------------------"
    
    new_delegations = IMeetingDelegations(meeting_to)
    for from_delegation in IMeetingDelegations(meeting_from).values():
        new_name = new_delegations.new()
        delegation = new_delegations[new_name]
        print "found %s" % from_delegation.title
        delegation.title = from_delegation.title
    transaction.commit()
    env['closer']()
Пример #7
0
 def test_meeting_delegations(self):
     meeting = _active_poll_fixture(self.config)
     request = testing.DummyRequest()
     request.meeting = meeting
     obj = self._cut(meeting, request)
     self.failUnless(IMeetingDelegations.providedBy(obj.meeting_delegations))