Exemplo n.º 1
0
    def GET(self, id=None):
        super(Personen, self).check_login()
        if self.user_allowed:
            if id is None:
                if User.logged_in_user.data["rolle"] == "leitung":
                    person = Person.find(None, 100000)
                else:
                    person = Person.find(
                        {"besitzerId": User.logged_in_user.data["id"]}, 100000)
            else:
                if User.logged_in_user.data["rolle"] == "leitung":
                    person = Person.find({"id": id})
                else:
                    person = Person.find({
                        "id":
                        id,
                        "besitzerId":
                        User.logged_in_user.data["id"]
                    })

            return json.dumps({
                "success":
                True,
                "personen":
                ModelAbstract.get_data_of_objects(person)
            })

        return json.dumps({
            "success": False,
            "message": "Aktion nicht erlaubt!"
        })
Exemplo n.º 2
0
    def POST(self, marke, typ, baujahr, hubraum, leistung, beschreibung,
             kennzeichen, fahrerId, beifahrerId, mechanikerId):
        super(Fahrzeuge, self).check_login()
        if self.user_allowed:
            fahrzeug = Fahrzeug()
            fahrzeug.data["benutzerId"] = User.logged_in_user.data["id"]
            fahrzeug.data["marke"] = marke
            fahrzeug.data["baujahr"] = baujahr
            fahrzeug.data["hubraum"] = hubraum
            fahrzeug.data["leistung"] = leistung
            fahrzeug.data["beschreibung"] = beschreibung
            fahrzeug.data["kennzeichen"] = kennzeichen

            ### Müssen noch auf Korrektheit ueberprueft werden
            fahrzeugklasse = Fahrzeugklasse.find({"id": typ})
            if fahrzeugklasse is None and len(typ) > 0:
                return json.dumps({
                    "success": False,
                    "message": "Fahrzeugklasse existiert nicht!"
                })
            fahrzeug.data["typ"] = typ

            fahrer = Person.find({"id": fahrerId})
            if fahrer is None and len(fahrerId) > 0:
                return json.dumps({
                    "success": False,
                    "message": "Fahrer existiert nicht!"
                })
            fahrzeug.data["fahrerId"] = fahrerId

            beifahrer = Person.find({"id": beifahrerId})
            if beifahrer is None and len(beifahrerId) > 0:
                return json.dumps({
                    "success": False,
                    "message": "Beifahrer existiert nicht!"
                })
            fahrzeug.data["beifahrerId"] = beifahrerId

            mechaniker = Person.find({"id": mechanikerId})
            if mechaniker is None and len(mechanikerId) > 0:
                return json.dumps({
                    "success": False,
                    "message": "Mechaniker existiert nicht!"
                })
            fahrzeug.data["mechanikerId"] = mechanikerId

            if fahrzeug.save():
                return json.dumps({"success": True, "data": fahrzeug.data})
            else:
                return json.dumps({
                    "success": False,
                    "messages": fahrzeug.required_fields_empty
                })

        return json.dumps({
            "success": False,
            "message": "Aktion nicht erlaubt!"
        })
Exemplo n.º 3
0
 def delete(self, person_id):
     try:
         # Added the [0] place since the objects function returns an array of the objects
         name = Person.objects(_id=person_id)[0].name
         print(name)
         if Person.objects(_id=person_id).delete():
             print('Deleted')
             return jsonify({'response': f'User {name} is deleted'})
     except Exception as e:
         return jsonify({'response': 'An error has occurred'})
Exemplo n.º 4
0
def approval_new():
    """添加审批单
    
    使用 WTForm 来创建表单并验证和获取表单内容
    """
    print('nimei')
    form = ApprovalForm()
    list_subject = [(1, u'公务卡消费'), (2, u'非公务卡消费')]
    form.cost_type.choices = list_subject
    form.subject.choices = Subject.get_subjects()
    print 'nimeimei'
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()
        
        form_list = [form.cost_type, approval.agent_id, form.max_money, approval.id, form.subject]
        invoices = Invoice.find_relation(form_list)
        if invoices[1] == None:
            approval_index = Approval.query.get(approval.id)
            approval_index.invoice_count = invoices[0]
            approval_index.subject_list += (' '+dict(Subject.get_subjects())[form.subject])
            approval_index.status = 'Printed'
            approval.save()
            flash(u'组合成功')
            return redirect('/approval/%d' % int(approval.id))
        return redirect('/approval/%d/chioce' % int(approval.id), incoices) 
    
        
#     if request.method == 'POST' and form.validate():
#         approval = Approval()
#         approval.agent_id = Person.judge(form.agent.data)
#         approval.payee_id = Person.judge(form.payee.data)
#         form.populate_obj(approval)
#         if request.files[form.picture.name]:
#             try:
#                 pic = Picture(request.files[form.picture.name])
#                 db.session.add(pic)
#                 pic.save()
#                 approval.picture_id = pic.id
#             except:
#                 flash(u'图片保存失败', 'error')
#         db.session.add(approval)
#         approval.save()
#         print 'nimei',approval.id
#         flash(u'成功添加审批单')
#         return redirect('/approval/%d' % int(approval.id))
    return render_template('/approval/edit.html', form = form, title=u'添加审批单')
Exemplo n.º 5
0
 def importbill_save(bills_list, bill_id):
     """HTML账单导入之后经过解析,将所得数据(bills_list)保存到对应的数据库中,此方法被(bill)bill_new视图方法调用
     """
     cur_list = {'USD':10, 'EUR':11, 'GBP':12, 'CNY':1, 'HK':14, 'MOP':15}
     person_id = Person.judge(bills_list[0][2][0][3])
     
     bills_list = bills_list[1][1:-1]
     try:
         for account in bills_list:
             acc = Account()
             acc.funder_id = person_id
             acc.bill_id = bill_id
             acc.is_submit = True
             acc.enter_date = account[0][0]
             acc.card_no = account[2][0]
             acc.trade_abstract = account[3][0]
             acc.transaction_place = account[4][0]
             money_transaction = str(account[5][0]).split('/')
             money_enter = str(account[6][0]).split('/')
             print money_transaction[1]
             acc.transaction_money = float(money_transaction[0])
             acc.currency = money_transaction[1]
             acc.enter_money = float(money_enter[0])
             acc.china_yuan = acc.transaction_money*float(str(cur_list[money_transaction[1]]))
             db.session.add(acc)
             acc.save()
     except:
         return flash(u'保存账单条目失败', 'error')
     return flash(u'保存账单条目成功')
Exemplo n.º 6
0
    def PUT(self, id, vorname, nachname, fuehrerschein):
        super(Personen, self).check_login()
        if self.user_allowed:
            person = Person.find({"id": id})

            if person is None:
                return json.dumps({
                    "success": False,
                    "messages": "Fahrzeugklasse nicht vorhanden!"
                })

            person.data["vorname"] = vorname
            person.data["nachname"] = nachname
            person.data["fuehrerschein"] = fuehrerschein

            if person.save():
                return json.dumps({"success": True, "data": person.data})
            else:
                return json.dumps({
                    "success": False,
                    "messages": person.required_fields_empty
                })

        return json.dumps({
            "success": False,
            "message": "Aktion nicht erlaubt!"
        })
Exemplo n.º 7
0
def person_new():
    """添加个人
    """
    form = PersonForm(request.form)
    if request.method == 'POST' and form.validate():
        ren = Person()
        """新建一个对象"""
        form.populate_obj(ren)
        """用 WTForm 自带的方法把表单数据转换成对象里面的属性"""
        db.session.add(ren)
        """对于新建操作,需要调用 add() 来添加这个对象"""
        ren.save()
        """用对象本身实现的 save() 方法来实际写入数据库"""
        flash(u'成功添加个人 %s' % ren.name)
        return redirect('/person/%d' % int(ren.id))
    return render_template('/person/edit.html', form=form, title=u'添加个人')
Exemplo n.º 8
0
    def after_find(self):
        fahrzeug = Fahrzeug.find({"id": self.data["fahrzeugId"]})

        if fahrzeug is not None:
            self.data["fahrzeug"] = fahrzeug.data

            fahrer = Person.find({"id": self.data["fahrzeug"]["fahrerId"]})
            beifahrer = Person.find(
                {"id": self.data["fahrzeug"]["beifahrerId"]})
            mechaniker = Person.find(
                {"id": self.data["fahrzeug"]["mechanikerId"]})

            if fahrer is not None:
                self.data["fahrer"] = fahrer.data

            if beifahrer is not None:
                self.data["beifahrer"] = beifahrer.data

            if mechaniker is not None:
                self.data["mechaniker"] = mechaniker.data
Exemplo n.º 9
0
	def POST(
			self,
			vorname,
			nachname,
			fuehrerschein
	):
		super(Personen, self).check_login()
		if self.user_allowed:
			person = Person()
			person.data["besitzerId"] = User.logged_in_user.data["id"]
			person.data["vorname"] = vorname
			person.data["nachname"] = nachname
			person.data["fuehrerschein"] = fuehrerschein

			if person.save():
				return json.dumps({
					"success": True,
					"data": person.data
				})
			else:
				return json.dumps({
					"success": False,
					"messages": person.required_fields_empty
				})

		return json.dumps({
			"success": False,
			"message": "Aktion nicht erlaubt!"
		})
Exemplo n.º 10
0
	def GET(self, id=None):
		super(Personen, self).check_login()
		if self.user_allowed:
			if id is None:
				if User.logged_in_user.data["rolle"] == "leitung":
					person = Person.find(None, 100000)
				else:
					person = Person.find({"besitzerId": User.logged_in_user.data["id"]}, 100000)
			else:
				if User.logged_in_user.data["rolle"] == "leitung":
					person = Person.find({"id": id})
				else:
					person = Person.find({"id": id, "besitzerId": User.logged_in_user.data["id"]})

			return json.dumps({
				"success": True,
				"personen": ModelAbstract.get_data_of_objects(person)
			})

		return json.dumps({
			"success": False,
			"message": "Aktion nicht erlaubt!"
		})
Exemplo n.º 11
0
	def post(self):
		firstName = self.request.get('firstName')
		middleName = self.request.get('middleName')
		lastName = self.request.get('lastName')
		dateOfBirth = str(self.request.get('dateOfBirth'))

		if(dateOfBirth):
			dob = datetime.strptime(dateOfBirth, '%Y-%m-%d').date() #Dates are of type: 2014-03-22
		else:
			dob = None

		person = Person(firstName = firstName, middleName = middleName, lastName = lastName, dateOfBirth = dob)
		person_key = person.put()

		session = get_current_session()
		session['person_key'] = person_key

		session['firstName'] = firstName
		session['middleName'] = middleName
		session['lastName'] = lastName
		session['dateOfBirth'] = dateOfBirth

		self.redirect('/addContact')
Exemplo n.º 12
0
def post_events():
    """
    This is the summary defined in yaml file
    First line is the summary
    All following lines until the hyphens is added to description
    the format of the first lines until 3 hyphens will be not yaml compliant
    but everything below the 3 hyphens should be.
    ---
    tags:
      - person
    parameters:
      - in: query
        name: first_name
        type: string
        required: true
        description: "The first name of the Person"
      - in: query
        name: last_name
        type: string
        required: true
        description: "The last name of the Person"
      - in: query
        name: email
        type: string
        required: true
        description: "The email of the Person"
      - in: query
        name: aliases
        type: array
        items:
          type: string
        description: "Any aliases the person may have"
    responses:
      200:
        description: Many Event items
        schema:
          type: array
          items:
            $ref: "#/definitions/Event"
    """
    person = {
        'first_name': request.args.get('first_name'),
        'last_name': request.args.get('last_name'),
        'email': request.args.get('email'),
        'aliases': request.args.get('aliases').split(',')
    }
    document = Person.deserialize(person)
    document.save()
    return 'magic'
Exemplo n.º 13
0
def account_new():
    """添加账单条目
    """
    form = AccountForm(request.form)
    if request.method == 'POST' and form.validate():
        account = Account()
        form.populate_obj(account)
        account.funder_id = Person.judge(form.funder.data)
        account.china_yuan = form.transaction_money.data*account.get_forex(form.currency.data)
        db.session.add(account)
        account.save()
        print 'ni'
        flash(u'成功添加账单条目')
        return redirect('/account/%d' % int(account.id))

    return render_template('/account/edit.html', form=form, title=u'添加账单条目')
Exemplo n.º 14
0
def person_index():
    """个人列表
    """
    rank = request.args.get('rank', 'id')
    search = request.args.get('search', '')
    order = request.args.get('order', 'asc')
    
    page, per_page, offset = get_page_items()
  
    people = Person.find(search=search, order=order, rank=rank)
     
    pagination = get_pagination(page=page, total=people.count())
    
    return render_template('/person/index.html', 
                           people=people.offset(offset).limit(per_page), 
                           pagination=pagination ,
                           search=search,order=order)
Exemplo n.º 15
0
def account_edit(id):
    """编辑账单条目
    
    和添加类似,参加 Person 的实现
    """
    account = Account.query.get(id)
    form = AccountForm(request.form, obj=account)
    if account.funder_id:
        form.funder.data = account.funders.name
    
    if request.method == 'POST' and form.validate():
        form.populate_obj(account)
        account.funder_id = Person.judge(form.funder.data)
        account.china_yuan = form.enter_money.data*account.get_forex(form.currency.data)
        account.save()
        flash(u'成功更新账单条目信息')
        return redirect('/account/%d' % id)
    return render_template('/account/edit.html', form=form, title=u'编辑账单条目')
Exemplo n.º 16
0
def get_person():
    """
    This is the summary defined in yaml file
    First line is the summary
    All following lines until the hyphens is added to description
    the format of the first lines until 3 hyphens will be not yaml compliant
    but everything below the 3 hyphens should be.
    ---
    tags:
      - person
    parameters:
      - in: query
        name: search
        type: string
        required: true
        description: "The search terms--will find matching names, emails, and aliases"
      - in: query
        name: offset
        type: integer
        default: "0"
        minimum: 0
        description: "The number of items to skip"
      - in: query
        name: count
        type: integer
        default: 1
        minimum: 1
        description: "The number of items to retrieve"
    responses:
      200:
        description: Many Person items
        schema:
          type: array
          items:
            $ref: "#/definitions/Person"
    """
    search = request.args.get('search')
    offset = int(request.args.get('offset') or 0)
    count = int(request.args.get('count') or 1)
    results = [
        Person.serialize(person) for person in Person.objects.skip(
            offset).limit(count).search_text(search)
    ]
    return jsonify(results)
Exemplo n.º 17
0
    def DELETE(self, id):
        super(Personen, self).check_login()
        if self.user_allowed:
            person = Person.find({"id": id})

            if person is None:
                return json.dumps({
                    "success": False,
                    "messages": "Fahrzeugklasse nicht vorhanden!"
                })

            person.delete()

            return json.dumps({"success": True})

        return json.dumps({
            "success": False,
            "message": "Aktion nicht erlaubt!"
        })
Exemplo n.º 18
0
    def post(self):
        try:
            data = api.payload
            if Person(name=data['name'],
                      sex=Sex(_id=data['sex']),
                      address=[
                          Address(number=data['number'],
                                  street=data['street'],
                                  city=data['city'],
                                  eircode=data['eircode'])
                      ]).save():

                return jsonify({'status': 'Successfully added'})

        except Exception as e:
            return jsonify({
                'status':
                'Error on registration, please check with your admin'
            })
Exemplo n.º 19
0
	def DELETE(self, id):
		super(Personen, self).check_login()
		if self.user_allowed:
			person = Person.find({"id": id})

			if person is None:
				return json.dumps({
					"success": False,
					"messages": "Fahrzeugklasse nicht vorhanden!"
				})

			person.delete()

			return json.dumps({
				"success": True
			})

		return json.dumps({
			"success": False,
			"message": "Aktion nicht erlaubt!"
		})
Exemplo n.º 20
0
    def POST(self, vorname, nachname, fuehrerschein):
        super(Personen, self).check_login()
        if self.user_allowed:
            person = Person()
            person.data["besitzerId"] = User.logged_in_user.data["id"]
            person.data["vorname"] = vorname
            person.data["nachname"] = nachname
            person.data["fuehrerschein"] = fuehrerschein

            if person.save():
                return json.dumps({"success": True, "data": person.data})
            else:
                return json.dumps({
                    "success": False,
                    "messages": person.required_fields_empty
                })

        return json.dumps({
            "success": False,
            "message": "Aktion nicht erlaubt!"
        })
Exemplo n.º 21
0
	def PUT(
			self,
			id,
			vorname,
			nachname,
			fuehrerschein
	):
		super(Personen, self).check_login()
		if self.user_allowed:
			person = Person.find({"id": id})

			if person is None:
				return json.dumps({
					"success": False,
					"messages": "Fahrzeugklasse nicht vorhanden!"
				})

			person.data["vorname"] = vorname
			person.data["nachname"] = nachname
			person.data["fuehrerschein"] = fuehrerschein

			if person.save():
				return json.dumps({
					"success": True,
					"data": person.data
				})
			else:
				return json.dumps({
					"success": False,
					"messages": person.required_fields_empty
				})

		return json.dumps({
			"success": False,
			"message": "Aktion nicht erlaubt!"
		})
Exemplo n.º 22
0
 def put(self, person_id):
     data = api.payload
     # Convert String to ObjectID.
     data['sex'] = ObjectId(data['sex'])
     Person.objects(_id=person_id).update(**data)
     return jsonify(Person.objects(_id=data['_id']))
Exemplo n.º 23
0
    """
<<<<<<< HEAD
    print('nimei')
    form = ApprovalForm()
    list_subject = [(1, u'公务卡消费'), (2, u'非公务卡消费')]
    form.cost_type.choices = list_subject
    form.subject.choices = Subject.get_subjects()
    print 'nimeimei'
=======
    form = ApprovalForm(request.form)
    form.status.choices = Approval.get_status()
    form.approval_type.choices = Approval.get_approval_type()
>>>>>>> 797deb1d9a238a9098207cfc01bab6963414987f
    if request.method == 'POST' and form.validate():
        approval = Approval()
        approval.agent_id = Person.judge(form.agent.data)
        approval.payee_id = Person.judge(form.payee.data)
<<<<<<< HEAD
        approval.subject_list = dict(Subject.get_subjects())[form.subject]
        db.session.add(approval)
        approval.save()
        
        form_list = [form.cost_type, approval.agent_id, form.max_money, approval.id, form.subject]
        invoices = Invoice.find_relation(form_list)
        if invoices[1] == None:
            approval_index = Approval.query.get(approval.id)
            approval_index.invoice_count = invoices[0]
            approval_index.subject_list += (' '+dict(Subject.get_subjects())[form.subject])
            approval_index.status = 'Printed'
            approval.save()
            flash(u'组合成功')
Exemplo n.º 24
0
	def POST(
			self,
			marke,
			typ,
			baujahr,
			hubraum,
			leistung,
			beschreibung,
			kennzeichen,
			fahrerId,
			beifahrerId,
			mechanikerId
	):
		super(Fahrzeuge, self).check_login()
		if self.user_allowed:
			fahrzeug = Fahrzeug()
			fahrzeug.data["benutzerId"] = User.logged_in_user.data["id"]
			fahrzeug.data["marke"] = marke
			fahrzeug.data["baujahr"] = baujahr
			fahrzeug.data["hubraum"] = hubraum
			fahrzeug.data["leistung"] = leistung
			fahrzeug.data["beschreibung"] = beschreibung
			fahrzeug.data["kennzeichen"] = kennzeichen

			### Müssen noch auf Korrektheit ueberprueft werden
			fahrzeugklasse = Fahrzeugklasse.find({"id": typ})
			if fahrzeugklasse is None and len(typ) > 0:
				return json.dumps({
					"success": False,
					"message": "Fahrzeugklasse existiert nicht!"
				})
			fahrzeug.data["typ"] = typ

			fahrer = Person.find({"id": fahrerId})
			if fahrer is None and len(fahrerId) > 0:
				return json.dumps({
					"success": False,
					"message": "Fahrer existiert nicht!"
				})
			fahrzeug.data["fahrerId"] = fahrerId

			beifahrer = Person.find({"id": beifahrerId})
			if beifahrer is None and len(beifahrerId) > 0:
				return json.dumps({
					"success": False,
					"message": "Beifahrer existiert nicht!"
				})
			fahrzeug.data["beifahrerId"] = beifahrerId

			mechaniker = Person.find({"id": mechanikerId})
			if mechaniker is None and len(mechanikerId) > 0:
				return json.dumps({
					"success": False,
					"message": "Mechaniker existiert nicht!"
				})
			fahrzeug.data["mechanikerId"] = mechanikerId

			if fahrzeug.save():
				return json.dumps({
					"success": True,
					"data": fahrzeug.data
				})
			else:
				return json.dumps({
					"success": False,
					"messages": fahrzeug.required_fields_empty
				})

		return json.dumps({
			"success": False,
			"message": "Aktion nicht erlaubt!"
		})