示例#1
0
文件: api.py 项目: mazz/kifu
def new_user(request):
    """Add a new user to the system manually."""
    rdict = request.params

    u = User()

    u.username = unicode(rdict.get('username'))
    u.email = unicode(rdict.get('email'))
    passwd = get_random_word(8)
    u.password = passwd
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    try:
        DBSession.add(u)
        DBSession.flush()
        # We need to return the password since the admin added the user
        # manually.  This is only time we should have/give the original
        # password.
        ret = dict(u)
        ret['random_pass'] = passwd
        return _api_response(request, ret)

    except IntegrityError, exc:
        # We might try to add a user that already exists.
        LOG.error(exc)
        request.response.status_int = 400
        return _api_response(request, {
            'error': 'Bad Request: User exists.',
        })
示例#2
0
文件: api.py 项目: raowl/initpyr
def new_user(request):
    """Add a new user to the system manually."""
    rdict = request.params

    u = User()

    u.username = unicode(rdict.get('username'))
    u.email = unicode(rdict.get('email'))
    passwd = get_random_word(8)
    u.password = passwd
    u.activated = True
    u.is_admin = False
    u.api_key = User.gen_api_key()

    try:
        DBSession.add(u)
        DBSession.flush()
        # We need to return the password since the admin added the user
        # manually.  This is only time we should have/give the original
        # password.
        ret = dict(u)
        ret['random_pass'] = passwd
        return _api_response(request, ret)

    except IntegrityError, exc:
        # We might try to add a user that already exists.
        LOG.error(exc)
        request.response.status_int = 400
        return _api_response(request, {
            'error': 'Bad Request: User exists.',
        })
示例#3
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from {{ cookiecutter.project_name }}.models import (
         Base,
         MyModel,
         )
     DBSession.configure(bind=engine)
示例#4
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from {{ cookiecutter.project_name }}.models import (
         Base,
         MyModel,
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
示例#5
0
文件: auth.py 项目: raowl/initpyr
    def invite(self, email):
        """Invite a user"""
        if not self.has_invites():
            return False
        if not email:
            raise ValueError('You must supply an email address to invite')
        else:
            # get this invite party started, create a new useracct
            new_user = UserMgr.signup_user(email, self.username)

            # decrement the invite counter
            self.invite_ct = self.invite_ct - 1
            DBSession.add(new_user)
            return new_user
示例#6
0
文件: auth.py 项目: raowl/initpyr
    def signup_user(email, signup_method):
        # Get this invite party started, create a new user acct.
        new_user = User()
        new_user.email = email
        new_user.username = email
        new_user.invited_by = signup_method
        new_user.api_key = User.gen_api_key()

        # they need to be deactivated
        new_user.reactivate('invite')

        # decrement the invite counter
        DBSession.add(new_user)
        return new_user
示例#7
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()  # 实例化
         self.status = True  # session异常的判断标记
     except Exception as e:
         print e.message
         self.status = False
示例#8
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()
         self.status = True
     except Exception as e:
         print e.message
         self.status = False
示例#9
0
 def __init__(self):
     """
     self.session 数据库连接会话
     self.status 判断数据库是否连接无异常
     """
     self.session, self.status = DBSession.get_session()
     pass
示例#10
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()
     except Exception as e:
         print "=====================message========================"
         print e.message
         print "=====================message========================"
示例#11
0
    def by_id(cls, id: str) -> Any:
        """
        Get the first entry in the database with the given id.
        """

        with DBSession() as db:
            return db.query(cls).filter(cls.id == id).first()
示例#12
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()
     except Exception as e:
         # raise e
         from WeiDian.common.loggers import generic_log
         generic_log(e)
         print(e.message)
示例#13
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()  # 初始化
         self.status = True  # session异常的判断标记
         self.slogs = SLogs()
     except Exception as e:
         print e.message
         self.status = False
def read_dummies(skip: int = 0, limit: int = 100) -> Any:
    """
    Retrieve dummies.
    """

    with DBSession() as db:
        dummies = db.query(models.Dummy).offset(skip).limit(limit).all()

    return dummies
示例#15
0
    def delete(self):
        """
        Hard delete the current object.
        """

        with DBSession() as db:
            db.delete(self)
            db.commit()

        return
示例#16
0
文件: auth.py 项目: x4rMa/kifu
    def signup_user(email, signup_method):
        # Get this invite party started, create a new user acct.

        exists = UserMgr.get(email=email)
        if exists:
            return exists
        else:
            new_user = User()
            new_user.email = email.lower()
            new_user.username = email.lower()
            new_user.invited_by = signup_method
            new_user.api_key = User.gen_api_key()

            # they need to be deactivated
            new_user.reactivate('signup')

            # decrement the invite counter
            DBSession.add(new_user)
            return new_user
示例#17
0
    def update(self, schema, **kwargs):
        """
        Updates the current object.
        """

        content = jsonable_encoder(schema)

        for key, value in content.items():
            setattr(self, key, value)

        with DBSession() as db:
            db.commit()

        return self
示例#18
0
    def create(cls, schema):
        """
        Creates an entry for the current table and returns it once in the database.
        """

        content = jsonable_encoder(schema)
        obj = cls(**content)

        with DBSession() as db:
            db.add(obj)
            db.commit()
            db.refresh(obj)

        return obj
示例#19
0
文件: views.py 项目: mazz/buildresty
 def get(self):
     return DBSession.query(Task).get(int(self.request.matchdict['id'])).to_json()
示例#20
0
文件: auth.py 项目: raowl/initpyr
 def activate(self):
     """Remove this activation"""
     DBSession.delete(self)
示例#21
0
文件: views.py 项目: mazz/buildresty
 def validate_post(self, request):
     name = request.json['name']
     num_existing = DBSession.query(Task).filter(Task.name==name).count()
     if num_existing > 0:
         request.errors.add(request.url, 'Non-unique task name.', 'There is already a task with this name.')
示例#22
0
def list_users(request):
    try:
        users = DBSession.query(User)
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
    return {'users': users}
示例#23
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()
     except Exception as e:
         print(e.message)
示例#24
0
文件: views.py 项目: mazz/buildresty
 def collection_post(self):
     # Adds a new task.
     task = self.request.json
     DBSession.add(Task.from_json(task))
示例#25
0
文件: views.py 项目: mazz/buildresty
 def collection_get(self):
     return {'tasks': [task.name for task in DBSession.query(Task)]}
示例#26
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
示例#27
0
文件: applog.py 项目: x4rMa/kifu
 def store(**kwargs):
     """Store a new log record to the db"""
     stored = AppLog(**kwargs)
     DBSession.add(stored)