Example #1
0
 def updateEmployee(self, employeeId, employeeData):
     try:
         print("empl update:", employeeData, get_current_time)
         EMPLOYEE_DATA.query.filter(
             db.or_(EMPLOYEE_DATA.id == employeeId)).update({
                 "fixed_ctc":
                 employeeData["fixed_ctc"],
                 "var_ctc":
                 employeeData["var_ctc"],
                 "joining_bonus":
                 employeeData["joining_bonus"],
                 "relocation_charges":
                 employeeData["relocation_charges"],
                 "var_ctc_frequency":
                 employeeData["var_ctc_frequency"],
                 "buyout":
                 employeeData["buyout"],
                 "updated_date":
                 get_current_time()
             })
         db.session.commit()
         return Response.make_success_resp(msg="employee updated!")
     except Exception as e:
         return Response.make_error_resp(msg="Something went wrong",
                                         type=e.args,
                                         code=500)
Example #2
0
def filter_description(form):

    q9 = filter_tags(form)

    if form.text.data:
        if form.simple_search.data:
            search_for = '%' + escape(form.text.data) + '%'
            q10 = q9.filter(
                db.or_(Expense.description.ilike(search_for, escape='/'),
                       Expense.comments.ilike(search_for,
                                              escape='/'))).order_by(
                                                  Expense.date.desc())
        else:
            exp_objects = q9.search(form.text.data, limit=50).all()
            # Following code is needed because the search method does not
            # support pagination. Also the whoosh results order needs to be
            # preserved.
            exp_ids = []
            for exp in exp_objects:
                exp_ids.append(exp.id)
            if exp_ids:
                ordering = case(
                    {id: index
                     for index, id in enumerate(exp_ids)},
                    value=Expense.id)
            else:
                ordering = None
            q10 = Expense.query.filter(Expense.id.in_(exp_ids)) \
                .order_by(ordering)
    else:
        q10 = q9.order_by(Expense.date.desc())

    return q10
Example #3
0
    def authenticate(cls, email, password):
        user = User.query.filter(db.or_(User.email == email)).first()

        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated
Example #4
0
    def authenticate(cls, email, password):
        user = User.query.filter(db.or_(User.email == email)).first()

        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False
        return user, authenticated
Example #5
0
 def deleteEmployee(self, employeeId):
     try:
         print('delete ', employeeId)
         EMPLOYEE_DATA.query.filter(
             db.or_(EMPLOYEE_DATA.id == employeeId)).delete()
         db.session.commit()
         return True
     except:
         return False
Example #6
0
 def getEmployee(self, employeeId):
     try:
         employee = EMPLOYEE_DATA.query.filter(
             db.or_(EMPLOYEE_DATA.id == employeeId)).first()
         return Response.make_data_resp(self.map_as_dict(employee))
     except Exception as e:
         return Response.make_error_resp(msg="Something went wrong",
                                         type=e.args,
                                         code=500)
Example #7
0
 def authenticate(cls, username, password):
    user = cls.query.filter(db.or_(AdminUser.username == username)).first() 
    
    if user:
       authenticated = user.check_password(password)
    else:
       authenticated = False
    
    return user, authenticated
Example #8
0
    def authenticate(cls, identifier, password):
        """ 认证用户 用户名或邮箱登录"""
        user = cls.query.filter(
            db.or_(cls.username == identifier,
                   cls.email == identifier)).first()
        if not user or not user.verify_passwork(password):
            raise AuthenticationError(403, 'authentication failed')

        return user
Example #9
0
    def authenticate(cls, username, password):
        user = cls.query.filter(db.or_(AdminUser.username == username)).first()

        if user:
            authenticated = user.check_password(password)
        else:
            authenticated = False

        return user, authenticated
Example #10
0
File: user.py Project: zhuhj89/DRMS
def authenticate(login, password):

    user = User.query.filter(db.or_(User.nickname==login,
                              User.email==login)).first()

    if user:
        authenticated = user.check_password(password)
    else:
        authenticated = False

    return user, authenticated
Example #11
0
    def validate_schema(self, data):
        """
        检查数据
        """

        instance = self.context.get('instance', None)
        user = User.query.filter(
            db.or_(User.username == data.get('username'),
                   User.email == data.get('email'))).first()
        if user is None:
            return

        # 创建用户时调用
        if instance is None:
            field = 'username' if user.username == data['username'] else 'email'
            raise ValidationError('{} user already exist'.format(
                user.username))
Example #12
0
def related_expenses(page):

    budget_id = request.args.get('budget_id', type=int)
    budget_page = request.args.get('budget_page', type=int)

    curr_year = datetime.utcnow().year

    E = Expense

    expense_subq = db.session.query(
        E.id,
        E.date,
        E.description,
        E.budget_id
    ) \
        .filter(
            E.user_id == current_user.id,
            db.extract('year', E.date) == curr_year
    ).subquery()

    budget_subq = db.session.query(Budget).filter(
        Budget.user_id == current_user.id).subquery()

    expenses = db.session.query(expense_subq) \
        .select_from(budget_subq) \
        .join(
            expense_subq,
            db.or_((db.func.lower(budget_subq.c.item) ==
                    db.func.lower(expense_subq.c.description)),
                   budget_subq.c.id == expense_subq.c.budget_id)
    ) \
        .filter(budget_subq.c.id == budget_id) \
        .order_by(expense_subq.c.date.desc()) \
        .paginate(page, current_app.config['ITEMS_PER_PAGE'], False)

    page_ids = [item.id for item in expenses.items]
    expenses.items = E.query.filter(E.id.in_(page_ids)) \
        .order_by(E.date.desc()).all()

    return render_template('budget/expenses.html',
                           title='Related expenses',
                           budget_id=budget_id,
                           budget_page=budget_page,
                           expenses=expenses)
Example #13
0
def edit_expense(id):

    args = request.args
    exp = Expense.query.get(id)

    if current_user.id != exp.user_id:
        abort(403)

    tags = ','.join([t.tagname for t in exp.tags])

    form = ExpenseForm(obj=exp,
                       pay_mode=exp.mode_id,
                       estimate_entry=exp.budget_id,
                       taglist=tags)
    modes = PaymentMode.query.filter_by(user_id=current_user.id)
    form.pay_mode.choices = [(m.id, m.mode) for m in modes]
    estimates = Budget.query.filter(
        Budget.user_id == current_user.id,
        db.or_(Budget.active.is_(True), Budget.id == exp.budget_id))
    if exp.budget_id:
        select_prompt = []
    else:
        select_prompt = [('', 'Choose one')]
    form.estimate_entry.choices = (select_prompt + [(e.id, e.item)
                                                    for e in estimates])

    if form.validate_on_submit():
        form.populate_obj(exp)
        exp.mode_id = int(form.pay_mode.data)
        exp.budget_id = (int(form.estimate_entry.data)
                         if form.estimate_entry.data else None)
        exp.tags = []
        exp.set_tags(form.taglist.data)
        db.session.commit()
        flash('The expense was updated.', 'success')
        return redirect(url_for('expense.get_expense', id=id, **args))

    return render_template('expense/edit.html',
                           title='Edit expense',
                           form=form,
                           heading='Edit expense',
                           id=id,
                           **args)
Example #14
0
    def authenticate(cls, login, password):
        user = cls.query.filter(
            db.or_(User.username == login, User.email == login)).first()
        authenticated = user.check_password(password) if user else False

        return user, authenticated
Example #15
0
    def authenticate(cls, login, password):
        user = cls.query.filter(db.or_(User.username == login, User.email == login)).first()
        authenticated = user.check_password(password) if user else False

        return user, authenticated
Example #16
0
File: user.py Project: zhuhj89/DRMS
def search(key):
    query = User.query.filter(db.or_(User.email==key,
                               User.nickname.ilike('%'+key+'%'),
                               User.nickname.ilike('%'+key+'%')))
    return query
Example #17
0
 def has_ended(cls):
     """Return True if the event has ended."""
     return db.and_(
         db.or_(cls.published, cls.published == False),
         cls.end_datetime <= datetime.now(),
     )