示例#1
0
    def __init__(self, db):
        db.create_all()
        admon = User('tomer', 'admon', '111')
        tomer = User(u'תומר', u'אדמון', '111')
        daniel = User('daniel', 'gaishuber', '311958201')
        illya = User('illya', 'yurkevich', '320880123')

        avoda = Party(
            u'העבודה',
            'https://www.am-1.org.il/wp-content/uploads/2015/03/%D7%94%D7%A2%D7%91%D7%95%D7%93%D7%94.-%D7%A6%D7%99%D7%9C%D7%95%D7%9D-%D7%99%D7%97%D7%A6.jpg'
        )
        likud = Party(
            u'הליכוד',
            'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Likud_Logo.svg/250px-Likud_Logo.svg.png'
        )
        lavan = Party(
            u'פתק לבן',
            'https://www.weberthai.com/fileadmin/user_upload/01_training-elements/02.4_others/02.5_color_cards/05_color_mosaic/images/1.jpg'
        )

        db.session.add(avoda)
        db.session.add(likud)
        db.session.add(lavan)
        db.session.add(admon)
        db.session.add(illya)
        db.session.add(tomer)
        db.session.add(daniel)
        db.session.commit()
示例#2
0
    def test_follow_posts(self):
        # create four users
        u1 = User({'username':'******', 'email':'*****@*****.**','password':'******'})
        u2 = User({'username':'******', 'email':'*****@*****.**','password':'******'})
        u3 = User({'username':'******', 'email':'*****@*****.**','password':'******'})
        u4 = User({'username':'******', 'email':'*****@*****.**','password':'******'})
        db.session.add_all([u1, u2, u3, u4])

        #create four parties
        p1 = Party({'title':'jawnboy with it','owner_id':1})
        p2 = Party({'title':'nicky6 with it','owner_id':2})
        p3 = Party({'title':'john with it','owner_id':3})
        p4 = Party({'title':'susan with it', 'owner_id':4})
        db.session.add_all([p1,p2,p3,p4])
        db.session.commit()

        #setup the followers
        u1.follow(u2) #jawnboy follows nicky6
        u1.follow(u4) #jawnboy follows susan
        u2.follow(u3) #nicky6 follows john
        u3.follow(u4) #mary follows david
        db.session.commit()

        #check the followed parties of each user
        f1 = u1.followed_parties().all()
        f2 = u2.followed_parties().all()
        f3 = u3.followed_parties().all()
        f4 = u4.followed_parties().all()

        #make sure they follow the write parties
        self.assertEqual(f1, [p4,p2,p1])
        self.assertEqual(f2, [p3,p2])
        self.assertEqual(f3, [p4,p3])
        self.assertEqual(f4, [p4])
示例#3
0
 def test_party_repr(self):
     """
     Test party representation representation
     """
     party = Party()
     self.assertEqual(
         party.__repr__(),
         '{Party : {"name": None, "hq": None, "leader": None, "abbrev": None}}'
     )
示例#4
0
 def insert_data_to_db(self):
     db.session.commit()
     testuser = User('test', 'user', '123')
     yarok = Party(u'עלה ירוק', 'https://pbs.twimg.com/profile_images/553476099775016960/8Ha40Qym_400x400.jpeg')
     avoda = Party(u'העבודה',
                   'https://www.am-1.org.il/wp-content/uploads/2015/03/%D7%94%D7%A2%D7%91%D7%95%D7%93%D7%94.-%D7%A6%D7%99%D7%9C%D7%95%D7%9D-%D7%99%D7%97%D7%A6.jpg')
     db.session.add(yarok)
     db.session.add(avoda)
     db.session.add(testuser)
     db.session.commit()
示例#5
0
 def populate(self):
     db.session.commit()
     valid_user = User(111111, 'firstName', 'lastName', False)
     valid_party = Party(u'עלה ירוק', 'static/images/yarok.jpeg', 0)
     db.session.add(valid_party)
     db.session.add(valid_user)
     db.session.commit()
示例#6
0
def create_user():
    data = request.get_json() or {}

    if 'email' in data:
        if User.query.filter_by(email=data['email']).first():
            return bad_request('Please use a different email address')
    elif 'phone_number' in data:
        if User.query.filter_by(
                phone_number=data['phone_number'].strip()).first():
            return bad_request('Please use a different phone number')
    else:
        return bad_request('Must include phone number or email')

    user = User()
    user.from_dict(data, new_user=True)

    party = Party()
    party.users.append(user)

    db.session.add(party)
    db.session.add(user)
    db.session.commit()
    response = jsonify(user.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_user', id=user.id)
    return response
示例#7
0
def get_parties(rows):
    parties = []
    index = 3
    while index < len(rows[2]) - 1:
        parties.append(Party(name=rows[2][index]))
        index += 4
    return parties
示例#8
0
def counter_contract(contract_id):
    contract = Contract.query.filter(Contract.id == contract_id).first_or_404()
    parent = contract if contract.parent_id is None else Contract.query.get(contract.parent_id)
    role = 'owner' if contract.owner_id == current_user.id else 'cparty'
    if 'counter' not in contract_transitions[contract.status][role]:
        flash('This action is not permitted')
        return redirect(url_for('index'))
    form = EditProposalForm()
    form.template_id.choices = [(t.id, t.title) for t in Template.query.order_by('title')]
    if form.validate_on_submit():
        proposal = Contract(template_id=form.template_id.data, params=form.params.data, memo=form.memo.data, status="draft", owner_id=current_user.id, parent_id=parent.id)
        db.session.add(proposal)
        db.session.flush()
        for p in contract.party:
            party = Party(contract_id=proposal.id, role=p.role, user_id=p.user_id)
            db.session.add(party)
        db.session.flush()
        description = 'Created a counter draft'
        alog = ActivityLog(contract_id=proposal.id, timestamp=datetime.now(), method='/contract/counter', description=description, user_id=current_user.id)
        db.session.add(alog)
        db.session.commit()
        flash('Draft edited.')
        return redirect(url_for('index'))
    form.template_id.data = contract.template_id
    form.params.data = contract.params
    return render_template('edit_draft.html', title='Edit a Draft Proposal', form=form, contract_id=contract_id, parties=contract.party, deal=parent.memo)
    def init_db(self):

        self.testUser = User('test', 'me',1234567800,0,0)
        self.party = Party('partyTest', 'https://www.am-1.org.il/wp-content/uploads/2015/03/%D7%94%D7%A2%D7%91%D7%95%D7%93%D7%94.-%D7%A6%D7%99%D7%9C%D7%95%D7%9D-%D7%99%D7%97%D7%A6.jpg', 0)

        db.session.add(self.testUser)
        db.session.add(self.party)
        db.session.commit()
示例#10
0
    def populate_db(self):
        db.session.commit()

        admon = User(123456, 'tomer', 'admon', False)
        max = User(1234567, 'max', 'zh', True)
        yarok = Party(u'עלה ירוק', 'static/images/yarok.jpeg', 0)
        db.session.add(yarok)
        db.session.add(admon)
        db.session.add(max)
        db.session.commit()
示例#11
0
 def insert_data_to_db(self):
     db.session.commit()
     watted = User('mohammed', 'watted', '345')
     avoda = Party(
         u'העבודה',
         'https://www.am-1.org.il/wp-content/uploads/2015/03/%D7%94%D7%A2%D7%91%D7%95%D7%93%D7%94.-%D7%A6%D7%99%D7%9C%D7%95%D7%9D-%D7%99%D7%97%D7%A6.jpg'
     )
     db.session.add(avoda)
     db.session.add(watted)
     db.session.commit()
示例#12
0
 def init_db(self):
     db.session.commit()
     u = User('lilo', 'siksik', '66')
     likud = Party(
         u'הליכוד',
         'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Likud_Logo.svg/250px-Likud_Logo.svg.png'
     )
     db.session.add(u)
     db.session.add(likud)
     db.session.commit()
示例#13
0
 def init_db(self):
     db.session.commit()
     u = User('illya', 'yurkevich', '123')
     likud = Party(
         u'הליכוד',
         'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Likud_Logo.svg/250px-Likud_Logo.svg.png'
     )
     db.session.add(u)
     db.session.add(likud)
     db.session.commit()
示例#14
0
 def init_db(self):
     db.session.commit()
     test = User('test', 'test', '123456789')
     likud = Party(
         u'הליכוד',
         'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Likud_Logo.svg/250px-Likud_Logo.svg.png'
     )
     db.session.add(test)
     db.session.add(likud)
     db.session.commit()
示例#15
0
def host_planit():
    """
    Creates a party.
    """
    form = PartyForm()
    print(request.get_json())
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        party = Party(
            name=form.data['name'],
            details=form.data['details'],
            location=form.data['location'],
            image_url=form.data['image_url'],
            host_id=form.data['host_id'],
            time=form.data['time'],
            starts_at=form.data['starts_at'],
        )
        db.session.add(party)
        db.session.commit()
        return party.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
示例#16
0
 def test_valid_user_selenium(self):
     self.valid_user = User(111111, 'firstName', 'lastName', False)
     self.valid_party = Party(u'עלה ירוק', 'static/images/yarok.jpeg', 0)
     self.first_name = self.driver.find_element_by_id('first_name')
     self.last_name = self.driver.find_element_by_id('last_name')
     self.id_num = self.driver.find_element_by_id('id_num')
     self.login_button = self.driver.find_element_by_id('login_button')
     self.first_name.send_keys(self.valid_user.first_name)
     self.last_name.send_keys(self.valid_user.last_name)
     self.id_num.send_keys(self.valid_user.id)
     self.login_button.submit()
     assert 'Home' in self.driver.title
示例#17
0
def start_a_party():
    form = StartAPartyForm()
    if form.validate_on_submit():
        party_data = {'owner_id': current_user.id, 'title': form.title.data}
        p = Party(party_data)
        db.session.add(p)
        db.session.commit()
        flash('Your party has been added')
        return redirect(url_for('start_a_party'))
    return render_template('start_a_party.html',
                           title='Start a Party',
                           form=form)
示例#18
0
def party():
    form = PartyForm()
    if form.validate_on_submit():
        party = Party(party=form.party.data.strip(), owner=current_user)
        try:
            db.session.add(party)
            db.session.commit()
            flash('Party created', 'success')
            return redirect(url_for('main.index'))
        except IntegrityError:
            db.session.rollback()
            flash('Party not created', 'warning')
    return render_template('references/ref.html', form=form, title='Party')
示例#19
0
def create_party():
    print("WE ARE HITTING THE START OF THE API ROUTE")
    form = PartyForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    party_mems = request.json.get("partyMembers")
    print("THIS IS PARTY_MEMS", party_mems)
    print("THIS IS FORM DATA", form.data)
    if form.validate_on_submit():
        party = Party(
            host_id=current_user.id,
            party_name=form.data['party_name'],
            party_size=form.data['party_size'],
            open_to_request=form.data['open_to_request']
        )
        for member in party_mems:
            new_member = User.query.filter_by(username = member).first()
            if new_member:
                party.party_members.append(new_member)
        db.session.add(party)
        db.session.commit()
        return {"party": party.to_dict()}
    return {"errors": "set errors here"}
示例#20
0
def create_draft():
    form = CreateProposalForm()
    form.template_id.choices = [(t.id, t.title) for t in Template.query.order_by('title')]
    if form.validate_on_submit():
        proposal = Contract(template_id=form.template_id.data, memo=form.memo.data, params=form.params.data, status="draft", owner_id=current_user.id)
        db.session.add(proposal)
        db.session.flush()
        for p in json.loads(form.parties.data):
            party = Party(contract_id=proposal.id, role=p['label'], user_id=p['user_id'])
            db.session.add(party)
        db.session.flush()
        description = 'Creation of a new draft'
        alog = ActivityLog(contract_id=proposal.id, timestamp=datetime.now(), method='/contract/new', description=description, user_id=current_user.id)
        db.session.add(alog)
        db.session.commit()
        flash('Draft saved.')
        return redirect(url_for('index'))
    contacts = User.query.all()
    return render_template('create_draft.html', title='Create a new Draft Proposal', form=form, contacts=contacts)
示例#21
0
def seed_users():
    faker = Faker()
    images = [
        'https://myplanits.s3-us-west-1.amazonaws.com/balloons-zoom-background.jpg',
        'https://myplanits.s3-us-west-1.amazonaws.com/0266554465.jpeg',
        'https://myplanits.s3-us-west-1.amazonaws.com/cute-planet-illustration_136610-17.jpg',
        'https://myplanits.s3-us-west-1.amazonaws.com/planit-favicon.png',
        'https://myplanits.s3-us-west-1.amazonaws.com/profile.png',
        'https://myplanits.s3-us-west-1.amazonaws.com/Screen+Shot+2021-03-08+at+4.58.09+PM.png',
    ]
    times = 0
    while times < 5:
        party = Party(first_name=faker.first_name(),
                      last_name=faker.last_name(),
                      email=images[times],
                      image_url=faker.image_url(),
                      password=(f'password{times}'))
        times = times + 1
        db.session.add(newUser)

    db.session.commit()
示例#22
0
 def test_valid_user_vote_selenium(self):
     self.valid_user = User(111111, 'firstName', 'lastName', False)
     self.valid_party = Party('yarok', 'static/images/yarok.jpeg', 0)
     self.first_name = self.driver.find_element_by_id('first_name')
     self.last_name = self.driver.find_element_by_id('last_name')
     self.id_num = self.driver.find_element_by_id('id_num')
     self.login_button = self.driver.find_element_by_id('login_button')
     self.first_name.send_keys(self.valid_user.first_name)
     self.last_name.send_keys(self.valid_user.last_name)
     self.id_num.send_keys(self.valid_user.id)
     self.login_button.submit()
     self.valid_party_thumb = WebDriverWait(self.driver, 15).until(
         EC.presence_of_element_located(
             (By.XPATH,
              '/html/body/div[2]/form/div[1]/div/label/div/div/img')))
     self.valid_party_thumb.click()
     self.vote_button = self.driver.find_element_by_id('button_vote')
     self.vote_button.send_keys(Keys.ENTER)
     self.vote_button_yes = WebDriverWait(self.driver, 15).until(
         EC.presence_of_element_located((By.ID, 'button_vote_yes')))
     self.vote_button_yes.submit()
     assert 'Flask Intro' in self.driver.title
示例#23
0
def create_party():
    """
    Route for creating parties
    """
    data = request.get_json()
    if data["id"] != os.environ.get('SECRET_CREATE_KEY'):
        current_app.logger.debug("Wrong identifictation: {}, key {}".format(
            data, os.environ.get('SECRET_CREATE_KEY')))
        return "Wrong identification", 401

    result = {
        "new": [],
        "existing": [],
    }
    respons = result, 200
    if isinstance(data, dict):
        try:
            for party_data in data["parties"]:
                current_app.logger.debug("POST data: {}".format(party_data))
                try:
                    existing_party = Party.query.filter_by(
                        email=party_data["email"]).one()
                    current_app.logger.debug(
                        "Excisting email found: {}".format(
                            existing_party.to_dict()))
                    result["existing"].append(existing_party.to_dict())
                except orm.exc.NoResultFound:
                    party = Party.create_party(party_data)
                    current_app.logger.info("Created party: {}".format(
                        party.to_dict()))
                    result["new"].append(party.to_dict())
            db.session.commit()
        except Exception as e:
            current_app.logger.error(str(e))
            return CONTACT_MSG, 500
    else:
        return "Submit data as dict", 406
    return respons
示例#24
0
def create():
    form = PartyForm()
    form.submit.label.text = "Create Party"
    form.members.choices = gen_party_members_choices()

    if form.validate_on_submit():
        members = Character.query.filter(Character.id.in_(
            form.members.data)).all()

        new_party = Party(name=form.name.data,
                          description=form.description.data,
                          dm_notes=form.dm_notes.data,
                          members=members)

        db.session.add(new_party)
        db.session.commit()

        flash("Party was created.", "success")
        return redirect(url_for("party.view", id=new_party.id))

    return render_template("party/create.html",
                           form=form,
                           title=page_title("Add Party"))
示例#25
0
# -*- coding: utf-8 -*-

from app.models import User, Party
from app import db

db.create_all()
db.session.commit()

admon = User('tomer', 'admon', 11)
tomer = User(u'תומר', u'אדמון', 22)
rom = User('rom', 'siksik', 33)
lilo = User('lilo', 'siksik', 66)

avoda = Party(
    u'העבודה',
    'https://www.am-1.org.il/wp-content/uploads/2015/03/%D7%94%D7%A2%D7%91%D7%95%D7%93%D7%94.-%D7%A6%D7%99%D7%9C%D7%95%D7%9D-%D7%99%D7%97%D7%A6.jpg'
)
likud = Party(
    u'הליכוד',
    'https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Likud_Logo.svg/250px-Likud_Logo.svg.png'
)
lavan = Party(
    u'פתק לבן',
    'https://www.weberthai.com/fileadmin/user_upload/01_training-elements/02.4_others/02.5_color_cards/05_color_mosaic/images/1.jpg'
)

db.session.add(avoda)
db.session.add(lilo)
db.session.add(rom)
db.session.add(likud)
db.session.add(lavan)
示例#26
0
def createParty():
    try:
        data = request.json

        party_id = data.get('party_id')
        date = data.get('date')
        start_time = data.get('start_time')
        end_time = data.get('end_time')
        party_name = data.get('party_name')
        location = data.get('location')
        host_id = data.get('host_id')
        voting = data.get('voting')
        reveal = data.get('reveal')
        voting_end = data.get('voting_end')

        if date:
            if start_time:
                start = datetime.strptime(f'{date} {start_time}',
                                          '%Y-%m-%d %H:%M')
            if end_time:
                end = datetime.strptime(f'{date} {end_time}', '%Y-%m-%d %H:%M')
            if start_time and end_time:
                if start_time > end_time:
                    end += timedelta(days=1)

        if party_id:
            party = Party.query.filter_by(party_id=party_id).first()
            if voting != None:
                party.voting = voting
                if voting_end:
                    party.voting_end = datetime.strptime(
                        f'{voting_end[0:10]} {voting_end[11:19]}',
                        '%Y-%m-%d %H:%M:%S')
            if reveal != None:
                party.reveal = reveal
            if voting != None or reveal != None:
                db.session.add(party)
                db.session.commit()

                return jsonify(
                    {'success': 'Voting/bottle reveal status changed.'})

        if None not in data.values() and "" not in data.values():
            # modify existing party - edit details, start/stop voting, reveal bottles
            if party_id:
                party.start = start
                party.end = end
                party.party_name = party_name
                party.location = location

            # create new party
            else:
                # set voting_end to after the party
                voting_end = start + timedelta(days=365)
                party_code = uuid.uuid4().hex[:6]
                party = Party(start=start,
                              end=end,
                              party_name=party_name,
                              location=location,
                              host_id=host_id,
                              voting_end=voting_end,
                              party_code=party_code)

            db.session.add(party)
            db.session.commit()

            return jsonify({'success': 'Party created/edited.'})
        else:
            return jsonify({'error': 'Error: All fields are required.'})
    except:
        return jsonify({'error': 'Error: Invalid parameters.'})
示例#27
0
def get_parties(rows):
	new_row = row_without_space(rows, 2)
	parties = []
	for i in new_row[7:]:
		parties.append(Party(name=i))
	return parties
示例#28
0
# -*- coding: utf-8 -*-

from app import db
from app.models import User, Party

db.create_all()
db.session.commit()

admon = User(123456, 'tomer', 'admon', False)
tomer = User(1234567, u'תומר', u'אדמון', False)
mark = User(12345621, 'Mark', 'Davydov', False)
max = User(12345631, 'Maxim', 'Zhuravsky', False)
edi = User(12345654, 'Eduard', 'Medvednic', True)

avoda = Party(u'העבודה', 'static/images/avoda.jpg', 0)
likud = Party(u'הליכוד', 'static/images/likud.png', 0)
lavan = Party(u'פתק לבן', 'static/images/white.jpg', 0)
yarok = Party(u'עלה ירוק', 'static/images/yarok.jpeg', 0)

db.session.add(avoda)
db.session.add(likud)
db.session.add(lavan)
db.session.add(yarok)
db.session.add(admon)
db.session.add(tomer)
db.session.add(mark)
db.session.add(max)
db.session.add(edi)
db.session.commit()
users = User.query.all()
示例#29
0
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

from app import models
db.init_app(app)

from flask import session
from app.models import Federal_Territory, Party, Constituency, Result, Federal_State
from read_file import read_csv

with app.app_context():
    db.drop_all()
    db.create_all()
    federal_territory = Federal_Territory()
    party = Party()

    federal_territories = read_csv(federal_territory)
    db.session.add(federal_territories)
    db.session.commit()


@app.route('/api/federal_states', methods=['GET'])
def federal_states():

    data = []
    federal_states = Federal_State.query.all()

    for fs in federal_states:
        data.append({'id': fs.id, 'name': fs.name})
示例#30
0
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ivote.settings')

import django
django.setup()
from app.models import Party

parties = [
    'Likud', 'Blue&White', 'Emet', 'Shas', 'JointList', 'Yemina', 'YB', 'Otzma'
]

print('Populating Party table')
for party in parties:
    p = Party(name=party)
    p.save()
print('done')