コード例 #1
0
    def test_polymorphic_generator_relationships(self):
        db.create_all()

        dealer1 = Dealer(1)
        dealer2 = Dealer(2)

        org1 = Org(id=1)
        org2 = Org(id=2)
        company1 = Company(id=1, dealer=dealer1)

        rec1 = Records(buyer=org1, seller=dealer2, id=1)
        rec2 = Records(buyer=org1, seller=org2, id=2)
        rec3 = Records(buyer=dealer1, seller=dealer2, id=3)
        rec4 = Records(buyer=dealer1, seller=org1, id=4)
        rec5 = Records(buyer=org1, seller=company1, id=5)

        assert rec1.buyer_type == 'org'
        assert rec1.buyer_id == 1
        assert rec1.buyer is org1
        assert org1.buyer_records == [rec1, rec2, rec5]
        assert org1.seller_records == [rec4]
        assert rec5.seller is company1

        # The cache for Network backed model is properly invalidated
        assert rec3.buyer is dealer1
        rec3.buyer_id = 2
        assert rec3.buyer is not dealer2  # It is a new object so the identity check fails
        assert rec3.buyer == dealer2

        rec1.buyer_id = 2
        # NOTE: This is a bug. A solution might be to use SQLAlchemy events to update the object.
        # The problem is that setting the object will again update the fields which causes an infinite loop.
        assert rec1.buyer is org1

        # The opposite of it is true too and is a bug.
        # If the reference object gets modified and it is already set in the data model,
        # the values do not update.
        org1.id = 20
        assert rec2.buyer is org1
        assert rec2.buyer_id != org1.id

        db.session.add(org1)
        db.session.add(rec1)
        db.session.add(rec2)
        db.session.add(rec3)
        db.session.add(rec4)
        db.session.add(rec5)
        db.session.flush()  # Making sure that DB does not complain.
        db.session.rollback()
コード例 #2
0
def hregister():
    form = hRegistrationForm()
    # flow of control is from top to bottom; so the logic TO BE PASSED to temp.html is written first, SO THAT it can be passed  okay thanks
    if form.validate_on_submit():

        org = Org(name=form.name.data,
                  email=form.email.data,
                  password=form.password.data,
                  occasion=form.occasion.data,
                  location=form.location.data,
                  price=form.price.data,
                  contact=form.contact.data,
                  details=form.details.data,
                  accomodation=form.accomodation.data,
                  address=form.address.data,
                  requirement='h')

        db.session.add(org)
        db.session.commit()
        print("Org")
        print(org)
        print("validated")
        flash('You were successfully signed up')
        return redirect(url_for('afterreg'))

    return render_template('hall.html', title='Register', form=form)
コード例 #3
0
    def test_polymorphic_generator_one_relationship_readme_example(self):
        db.create_all()

        org1 = Org()
        dealer1 = LocalDealer()  # SQLAlchemy model
        dealer2 = Dealer.find(id=3)  # Network backed model
        db.session.add(org1)
        db.session.add(dealer1)
        # We flush to get the ID of org1 and dealer1
        db.session.flush()

        vehicle1 = Vehicle(source=org1)
        vehicle2 = Vehicle(source=dealer1)
        vehicle3 = Vehicle(source=org1)
        vehicle4 = Vehicle(source=org1)
        vehicle5 = Vehicle(source=dealer2)

        assert vehicle1.source == org1
        assert vehicle1.source_id == 1
        assert vehicle2.source_type == 'local_dealer'
        assert org1.vehicles == [vehicle1, vehicle3, vehicle4]
        assert vehicle5.source == dealer2
        assert vehicle5.source_type == 'dealer'

        db.session.flush()
        db.session.rollback()
コード例 #4
0
def load_orgs():
    import pandas as pd
    data = pd.read_excel('staff.xlsx',
                         names=['id', 'name', 'parent', 'head'],
                         header=None)
    for row in data.iterrows():
        idx, d = row
        parent = None if pd.isna(d['parent']) else int(d['parent'])
        head = None if pd.isna(d['head']) else d['head']
        if not parent:
            org = Org(name=d['name'], head=head, parent=parent)
        else:
            parent = Org.query.get(parent)
            org = Org(name=d['name'], head=head, parent=parent)
        db.session.add(org)
        db.session.commit()
コード例 #5
0
def gregister():
    form = RegistrationForm()
    if form.validate_on_submit():
        
        org= Org(name=form.name.data,email=form.email.data,password=form.password.data,utype=form.utype.data)
        print(org)
        db.session.add(org)
        db.session.commit()
        flash('You were successfully signed up')
        return redirect('/')
        
    return render_template('register.html', title='register', form=form)
コード例 #6
0
ファイル: parse.py プロジェクト: fangpeng/mygithub
def create_org(parent, name, seq):
    org = Org()
    org.parent = parent
    if not isinstance(name, unicode):
        name = force_unicode(name.strip().decode('gbk'))
    code,name = name.split(',',2)
    org.code = code.strip()
    org.name = name.strip()
    org.seq = seq
    org.category = org_categories[-1][0] #使用最后一个类别
    return org
コード例 #7
0
ファイル: loadModels.py プロジェクト: shanrgupta/cs373-wcdb
def populate_org(root):
    """
	Finds instances of Org in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
    for org in root.findall("Organization"):
        temp_org = Org()
        temp_org.org_ID = org.get("ID")
        temp_org.name = org.get("Name")
        if org.find("Kind") is not None:
            temp_org.kind = org.find("Kind").text
        if org.find("Location") is not None:
            temp_org.location = org.find("Location").text

        for crisis in org.iter("Crisis"):
            temp_relations = Relations()
            check = Relations.objects.filter(crisis_ID=crisis.get("ID"),
                                             org_ID=org.get("ID"))
            if len(check) == 0:
                temp_relations.populate(c_id=crisis.get("ID"),
                                        o_id=org.get("ID"))
                temp_relations.save()

        for person in org.iter("Person"):
            temp_relations = Relations()
            check = Relations.objects.filter(org_ID=org.get("ID"),
                                             person_ID=person.get("ID"))
            if len(check) == 0:
                temp_relations.populate(p_id=person.get("ID"),
                                        o_id=org.get("ID"))
                temp_relations.save()

        populate_li(org, org.get("ID"), "History")
        populate_li(org, org.get("ID"), "ContactInfo")

        populate_common(org, org.get("ID"), temp_org)
        temp_org.save()
コード例 #8
0
def decreg():
    form = dRegistrationForm()
    if form.validate_on_submit():

        org = Org(name=form.name.data,
                  email=form.email.data,
                  password=form.password.data,
                  requirement='d',
                  price=form.price.data,
                  details=form.details.data,
                  contact=form.contact.data)
        db.session.add(org)
        db.session.commit()
        print("validated")
        print(Org)
        flash('You were successfully signed up')
        return redirect(url_for('afterreg'))

    return render_template('dec.html', title='decregister', form=form)
コード例 #9
0
def partyplan():
    form = planRegistrationForm()
    print("hey")
    if form.validate_on_submit():
        print("hi")
        print("hiyo")
        plan = Org(name=form.name.data,
                   email=form.email.data,
                   password=form.password.data,
                   requirement='p',
                   special=form.special.data,
                   details=form.details.data,
                   contact=form.contact.data,
                   price=form.price.data)

        db.session.add(plan)
        db.session.commit()
        print("Org")
        print(plan)
        print("validated")
        flash('You were successfully signed up')
        return redirect(url_for('afterreg'))
    return render_template('partyplan.html', title='party', form=form)
コード例 #10
0
ファイル: loadModels.py プロジェクト: bblee1002/cs373-wcdb
def populate_org(root) :
	"""
	Finds instances of Org in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
	for org in root.findall("Organization") :
		temp_org          =                     Org()
		temp_org.org_ID   =             org.get("ID")
		temp_org.name     =           org.get("Name")
		if org.find("Kind") is not None :
			temp_org.kind     =     org.find("Kind").text
		if org.find("Location") is not None :
			temp_org.location = org.find("Location").text

		for crisis in org.iter("Crisis") :
			temp_relations = Relations()
			check = Relations.objects.filter(crisis_ID = crisis.get("ID"), org_ID = org.get("ID"))
			if len(check) == 0:
				temp_relations.populate(c_id = crisis.get("ID"), o_id = org.get("ID"))
				temp_relations.save()

		for person in org.iter("Person") :
			temp_relations = Relations()
			check = Relations.objects.filter(org_ID = org.get("ID"), person_ID = person.get("ID"))
			if len(check) == 0:
				temp_relations.populate(p_id = person.get("ID"), o_id = org.get("ID"))
				temp_relations.save()

		populate_li(org, org.get("ID"), "History")
		populate_li(org, org.get("ID"), "ContactInfo")

		populate_common(org, org.get("ID"), temp_org)
		temp_org.save()