コード例 #1
0
 def addNewUser(cls,email,password,name):
     session = Session()
     new_user = User(Password=password)
     new_user.syncVersion = 0
     new_user.UserType = 3
     new_user.Closed = 0
     new_user.NtfActivityConfirm = 1
     new_user.NtfActivityCancel = 1
     new_user.NtfActivityChange = 1
     new_user.NtfActivityNew = 1
     new_user.Name = name
     new_user.Email = email
     new_user.CreatedDate = today()
     session.add(new_user)
     try:
         session.commit()
         from tools.MailTools import sendNewUserMail
         sendNewUserMail(email,name,password)
     except Exception as e:
         session.rollback()
         session.close()
         return Error(str(e))
     user = session.query(User).filter_by(Email=email).first()
     session.close()
     if user:
         return User(user.id,user.Password,user.Active,user.UserType,user.CompanyId)
コード例 #2
0
ファイル: main.py プロジェクト: alvarojbarros/dondefluir2
def set_payment():
    from db.Payment import Payment
    activityId = request.args.get('activityId')
    session = Session()
    record = session.query(Activity).filter_by(id=activityId).first()
    companyId = record.CompanyId
    session.close()
    session = Session()
    session.expire_on_commit = False
    record = Payment()
    record.UserId = current_user.id
    record.CompanyId = companyId
    record.ActivityId = activityId
    record.ResponseCode = request.args.get('x_cod_response')
    record.Response = request.args.get('x_response')
    record.Amount = request.args.get('x_amount')
    record.TransDate = now()
    record.Reference = request.args.get('x_id_invoice')
    record.Reason = request.args.get('x_response_reason_text')
    record.TransactionId = request.args.get('x_transaction_id')
    record.BankName = request.args.get('x_bank_name')
    record.AutorizationCode = request.args.get('x_approval_code')
    record.Currency = request.args.get('x_currency_code')
    record.beforeInsert()
    session.add(record)
    res = record.save(session)
    if res:
        return jsonify(result={'res':True,'id':record.id})
    else:
        return jsonify(result={'res':False,'Error':str(res)})
コード例 #3
0
ファイル: main.py プロジェクト: alvarojbarros/dondefluir2
def saveNewRecord(TableClass,fields):
    del fields['id']
    new_record = TableClass()
    getDetailDict(fields)
    session = Session()
    session.expire_on_commit = False
    new_record.fromJSON(fields)
    if not new_record.beforeInsert():
        return jsonify(result={'res': False, 'Error': 'Error en Campos'})
    res = new_record.check()
    if not res:
        return jsonify(result={'res': False, 'Error': str(res)})
    session.add(new_record)
    res = new_record.afterInsert()
    if not res:
        return jsonify(result={'res': False, 'Error': str(res)})
    try:
        session.commit()
    except Exception as e:
        session.rollback()
        session.close()
        return jsonify(result={'res': False, 'Error': str(e)})
    new_record.callAfterCommitInsert()
    RunJS = new_record.afterSaveJS()
    session.close()
    return jsonify(result={'res': True, 'record': new_record.toJSON(), 'RunJS': RunJS})
コード例 #4
0
 def addNewUser(cls,username,password):
     from sqlalchemy.orm import sessionmaker
     session = Session()
     new_user = User(username,password,0,None)
     new_user.syncVersion = 0
     new_user.UserType = 3
     session.add(new_user)
     try:
         session.commit()
     except:
         session.rollback()
     user = session.query(User).filter_by(id=username).first()
     session.close()
     if user:
         return User(user.id,user.Password,user.Active,user.UserType)
コード例 #5
0
ファイル: main.py プロジェクト: alvarojbarros/dondefluir2
def set_favorite():
    from db.UserFavorite import UserFavorite
    favId = request.args.get('favId')
    session = Session()
    session.expire_on_commit = False
    record = session.query(UserFavorite).filter_by(UserId=current_user.id,FavoriteId=favId).first()
    if not record:
        record = UserFavorite()
        record.UserId = current_user.id
        record.FavoriteId = favId
        record.CompanyId = current_user.CompanyId
        record.beforeInsert()
        record.Checked = True
        session.add(record)
    else:
        record.Checked = not record.Checked
    status = record.Checked
    res = record.save(session)
    if res:
        return jsonify(result={'res':True,'id':record.id,'Status': status})
    else:
        return jsonify(result={'res':False,'Error':str(res)})
コード例 #6
0
from sqlalchemy import Table, Column, Integer, String
from tools.dbconnect import engine,Session
from sqlalchemy.ext.declarative import declarative_base
import settings

Base = declarative_base()

class DBVersion(Base):
    __tablename__ = 'dbversion'
    id = Column(Integer, primary_key=True)
    Version = Column(Integer)

Base.metadata.create_all(engine)

session = Session()
record = session.query(DBVersion).first()
if not record:
    record = DBVersion()
    try:
        record.Version = max(settings.versions.keys())
    except:
        record.Version = 1
    session.add(record)
    session.commit()
session.close()