示例#1
0
 def test_insert(self):
     #print("VOTATION TEST")
     v = Votation( \
         votation_description = 'Votation automated test ' + str(random.randint(0,500)) , \
         description_url = "" , \
         votation_type = votation_dao.TYPE_DRAW , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,1,15) , \
         votation_status = 2 , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(v) )
     self.assertGreater(v.votation_id,0)
     v1 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertIsNotNone(v1)
     self.assertIsNotNone(v1.promoter_user)
     self.assertEqual(v.votation_id, v1.votation_id)
     self.assertEqual(v.votation_description, v1.votation_description)
     self.assertEqual(v.votation_type, v1.votation_type)
     self.assertEqual(v.promoter_user.user_id, v1.promoter_user.user_id)
     self.assertEqual(v.begin_date, v1.begin_date)
     self.assertEqual(v.end_date, v1.end_date)
     votation_dao.delete_votation_by_id(v.votation_id)
     v1 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertIsNone(v1)
示例#2
0
文件: index.py 项目: cbelli/spritz
def votation_detail(votation_id):
    v = votation_dao.load_votation_by_id(votation_id)
    if v.votation_type == votation_dao.TYPE_MAJORITY_JUDGMENT:
        return votation_detail_maj_jud(v)
    # if v.votation_type == votation_dao.TYPE_DRAW:
    #     return votation_detail_draw(v)
    if v.votation_type == votation_dao.TYPE_SIMPLE_MAJORITY:
        return votation_detail_simple(v)
示例#3
0
文件: index.py 项目: cbelli/spritz
def update_end_date(votation_id):
    v = votation_dao.load_votation_by_id(votation_id)
    if current_user.u.user_id == v.promoter_user.user_id:
        end_date = request.args.get('end_date')
        end_time = request.args.get('end_time')
        if end_date and end_time:
            votation_bo.update_end_date(votation_id, end_date + " " + end_time)
            return "OK"
    return "KO"
示例#4
0
文件: index.py 项目: cbelli/spritz
def vote_(votation_id):
    v = votation_dao.load_votation_by_id(votation_id)
    if votation_dao.votation_timing(v) != 0:
        return redirect('/votation_detail/' + str(votation_id))
    if voter_dao.is_voter(votation_id, current_user.u.user_id) == False:
        return redirect('/votation_detail/' + str(votation_id))
    if v.votation_type == votation_dao.TYPE_MAJORITY_JUDGMENT:
        return votemajjud(v)
    if v.votation_type == votation_dao.TYPE_SIMPLE_MAJORITY:
        return votesimplemaj(v)
示例#5
0
文件: index.py 项目: cbelli/spritz
def add_voters():
    votation_id = request.form['votation_id']
    v = votation_dao.load_votation_by_id(votation_id)
    if v.promoter_user.user_id == current_user.u.user_id:
        list_voters = request.form['list_voters']
        ar = voter_dao.split_string_remove_dup(list_voters)
        n = voter_bo.insert_voters_array(votation_id, ar)
        return render_template('thank_you_template.html', \
        pagetitle=_("Voter"), \
        message=(_("{} voters being added").format(n),MSG_OK))
    if v.promoter_user.user_id != current_user.u.user_id:
        return render_template('thank_you_template.html', \
            pagetitle=_("Voters"), \
            message=(_("Sorry, only the owner of this election can add voters"),MSG_KO))
示例#6
0
def is_voter(votation_id, user_id):
    """Have you the right to vote?"""
    result = False
    v = votation_dao.load_votation_by_id(votation_id)
    if not v:
        return False
    #if votation_id == v.promoter_user.user_id: NO GOOD
    #return True
    if v.list_voters == 0:
        return True
    n = db.session.query(Voter).filter(Voter.votation_id == votation_id,
                                       Voter.user_id == user_id).count()
    if n == 1:
        result = True
    return result
示例#7
0
 def test_update_end_date(self):
     v = Votation( \
         votation_description = 'Update end date test ' + str(random.randint(0,500)) , \
         description_url = '' , \
         votation_type = votation_dao.TYPE_SIMPLE_MAJORITY , \
         promoter_user_id = 1 , \
         begin_date = datetime(2018,1,1) , \
         end_date = datetime(2018,2,1) , \
         votation_status = votation_dao.STATUS_WAIT_FOR_CAND_AND_GUAR , \
         list_voters = 0)
     self.assertTrue( votation_dao.insert_votation_dto(v) )
     new_end_date = datetime(2019,12,31,8,34)
     votation_bo.update_end_date(v.votation_id, new_end_date)
     v2 = votation_dao.load_votation_by_id(v.votation_id)
     self.assertEqual(new_end_date, v2.end_date)
     votation_bo.deltree_votation_by_id(v.votation_id)
示例#8
0
def validate_dto(o):
    """Validate data for writing in DB. Returns error code, 0 on success"""
    result = 0
    if result == 0:
        if o.u.user_id == None:
            result = 1
    if result == 0:
        if o.votation_id == None:
            result = 2
    if result == 0:
        u = user.load_user_by_id(o.u.user_id)
        if u == None:
            result = 3
    if result == 0:
        u = votation_dao.load_votation_by_id(o.votation_id)
        if u == None:
            result = 4
    if result == 0:
        if check_for_duplicate(o):
            result = 5
    return result