Example #1
0
def motion_add(request):
    """create a new motion.
    
    1. show new motion form
    2. save to database after user submit
    """
    
    # initialize the form to select all participants
    all_users = load_users()
    all_user_options = [(itm.id, itm.name) for itm in all_users]
    selected_users = [itm.id for itm in all_users]

    # add four blank options on new motion form
    form = Form(request, schema=MotionSchema, defaults=dict(participants = selected_users, 
                                                            options=["","","",""]))
    
    if form.validate():
        title = form.data.get("title")
        desc = form.data.get("desc")
        options = form.data.get("options")
        users = form.data.get("participants")

        add_motion(title, desc, options, users)

        return HTTPFound(location=route_path('motion_list', request))
        
    return dict(renderer=FormRenderer(form), all_user_options=all_user_options)
Example #2
0
    def test_load_users(self):
        from motionman.services.user import load_users

        #prepare data
        session = DBSession()

        user_1 = copy.deepcopy(self.user_orig)

        try:
            session.add(user_1)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()

        user_2 = copy.deepcopy(self.user_orig)
        user_2.name = u"test2"
        try:
            session.add(user_2)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()

        user_3 = copy.deepcopy(self.user_orig)
        user_3.name = u"test3"
        user_3.status = 0
        try:
            session.add(user_3)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()

        users = load_users()
        user1_found = False
        user2_found = False
        user3_found = False
        for user in users:
            if user.name == u'test1': user1_found = True
            if user.name == u'test2': user2_found = True
            if user.name == u'test3': user3_found = True

        self.assertTrue(user1_found)
        self.assertTrue(user2_found)
        self.assertFalse(user3_found)
Example #3
0
    def test_load_users(self):
        from motionman.services.user import load_users
        
        #prepare data
        session = DBSession()

        user_1 = copy.deepcopy(self.user_orig)

        try:
            session.add(user_1)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()
        
        user_2 = copy.deepcopy(self.user_orig)
        user_2.name = u"test2"
        try:
            session.add(user_2)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()
        
        user_3 = copy.deepcopy(self.user_orig)
        user_3.name = u"test3"
        user_3.status = 0
        try:
            session.add(user_3)
            session.flush()
            transaction.commit()
        except IntegrityError:
            transaction.abort()

        users = load_users()
        user1_found = False
        user2_found = False
        user3_found = False
        for user in users:
            if user.name == u'test1': user1_found = True
            if user.name == u'test2': user2_found = True
            if user.name == u'test3': user3_found = True
        
        self.assertTrue(user1_found)
        self.assertTrue(user2_found)
        self.assertFalse(user3_found)
Example #4
0
def user_list(request):
    users = load_users()
    return dict(users = users)