當前位置: 首頁>>代碼示例>>Python>>正文


Python DBSession.add方法代碼示例

本文整理匯總了Python中bproject.models.models.DBSession.add方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.add方法的具體用法?Python DBSession.add怎麽用?Python DBSession.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bproject.models.models.DBSession的用法示例。


在下文中一共展示了DBSession.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: edit

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def edit(self, idx = None, name = None):
     """ Lets to change name of existing group """
     log.debug("edit")
     response = Return()
     # Look for already existing record
     org = self.get(name = name)
     if org is None:
         # Group found
         if idx != None and name != None:
             group = self.get(idx = idx)
             old_name = group.name
             group.id = idx
             group.name = name
             group.dt = helpers.dtnow()
             DBSession.add(group)
             #response.data = group
             DBSession.flush()
             response.success()
             response.msg = "Successfully changed from {0} to {1}".format(old_name, name)
             log.info(response.msg)
             self.history.add(static.options.groups, static.actions.edit, response.msg)
         else:
             response.nodata()
             log.error(response.msg)
     else:
         # Group exist - name have to be unique
         response.msg = "Group already exists - not unique group name: {0}".format(name)
         log.error(response.msg)
     return response
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:31,代碼來源:groupsfacade.py

示例2: modify

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def modify(self, identifier, new_user):
     log.debug("modify")
     result = Return()
     try:
         if identifier and new_user:
             result = self.validate_existing(new_user)
             if result.status:
                 user = self.by_identifier(identifier)
                 if user:
                     user.name = new_user.get("name")
                     user.lastname = new_user.get("lastname")
                     user.email = new_user.get("email")
                     user.dt = helpers.dtnow()
                     DBSession.add(user)
                     result.data = self.get_details(user)
                     DBSession.flush()
                     result.success()
                     self.history.add(static.options.users, static.actions.edit, "User: {0} modified".format(user.name))
                 else:
                     result.notfound()
         else:
             result.nodata()
         log.info(result.msg)
     except Exception as ex:
         log.exception(ex)
         result.exception()
     return result
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:29,代碼來源:usersfacade.py

示例3: changepassword

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def changepassword(self, identifier, old, new, rpt):
     log.debug("change password")
     result = Return()
     try:
         if identifier and old and new and rpt:
             if new == rpt:
                 account = self.by_identifier(identifier)
                 if account:
                     if self.encryptor.compare(old, account.password, account.salt):
                         account.salt = self.encryptor.salt()
                         account.password = self.encryptor.encode(new, account.salt)
                         account.dt = helpers.dtnow()
                         DBSession.add(account)
                         result.success()
                         result.data = new
                     else:
                         result.msg = "Incorrect password"
                 else:
                     result.notfound(identifier)
             else:
                 result.msg = "Passwords are not equal"
         else:
             result.nodata()
         log.info(result.msg)
     except Exception as ex:
         log.exception(ex)
         result.exception()
     return result
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:30,代碼來源:accountfacade.py

示例4: setgroups

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def setgroups(self, identifier, jsongroups):
     log.debug("setgroups")
     groups = []
     account = self.by_identifier(identifier)
     for json in jsongroups:
         g = json.get("group")
         if json.get("assigned"):
             group = self.groups.get(idx = g.get("id"))
             groups.append(group)
     account.dt = helpers.dtnow()
     account.groups = groups
     DBSession.add(account)
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:14,代碼來源:accountfacade.py

示例5: edit_entry

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def edit_entry(self, idx, entry):
     log.debug("edit-entry")
     original = self.get_entry_by_id(idx)
     if original:
         original.name = entry.name
         original.value = entry.value
         original.type = entry.type
         original.dt = datetime.now()
         DBSession.add(original)
         DBSession.flush()
         return True
     return False
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:14,代碼來源:settingsfacade.py

示例6: update

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def update(self, place = None):
     log.debug("places_update")
     if place:
         try:
             DBSession.add(place)
             log.info("Place {0} removed")
             return True
         except Exception as ex:
             log.exception(ex)
     else: 
         log.error("Place obj is empty")
     return False
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:14,代碼來源:placesfacade.py

示例7: edit_category

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def edit_category(self, idx, category):
     """ Updates existing cateogry by id """
     log.debug("categories-edit")
     original = self.get_category_by_id(idx)
     if original is not None:
         original.name = category.name
         original.code = category.code
         original.options = category.options
         original.dt = datetime.now()
         DBSession.add(original)
         DBSession.flush()
         return original
     else:
         return None
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:16,代碼來源:settingsfacade.py

示例8: add

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add(self, name, permissions = ""):
     log.debug("add")
     response = Return()
     group = None
     if name is None:
         response.nodata()
         log.error(response.msg)
     else:
         try:
             if not(self.get(name = name)):
                 group = Group(name = name)
                 group.permissions = permissions
                 group.id = DBSession.add(group)
                 response.data = group
                 DBSession.flush()
                 response.success()
                 response.msg = "Group {0} has been added".format(name)
                 log.info(response.msg)
                 self.history.add(static.options.groups, static.actions.add, response.msg)
             else:
                 response.msg = "Group {0} already exists".format(name)
                 log.error(response.msg)
         except Exception as ex:
             log.exception(ex)
             response.exception()
     return response
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:28,代碼來源:groupsfacade.py

示例9: add_category

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add_category(self, category):
     """ Inserts new category """
     log.debug("categories-add")
     category.dt = datetime.now()
     category.id = DBSession.add(category)
     DBSession.flush()
     return category
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:9,代碼來源:settingsfacade.py

示例10: add_new

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add_new(self, history):
     log.debug("add_new")
     response = Return()
     try:
         if history:
             history.date = history.date if history.date else helpers.dtnow()
             DBSession.add(history)
             DBSession.flush()
             response.success()
             log.info("History item {0}:{1} has been added".format(history.option, history.action))
         else:
             log.error(msg)
             response.nodata()
     except Exception as ex:
         log.exception(ex)
         response.exception()
     return response
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:19,代碼來源:historyfacade.py

示例11: add_login_info

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add_login_info(self, request, account):
     log.debug("add_login_info")
     result = Return()
     try:
         if account:
             info = LoginInfo()
             if request:
                 info.agent = request.user_agent
                 info.local = str(request.accept_language)
             account.logininfo.append(info)
             DBSession.add(account)
             result.success()
         else:
             result.nodata()
         log.info(result.msg)
     except Exception as ex:
         log.exception(ex)
         result.exception()
     return result
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:21,代碼來源:accountfacade.py

示例12: add_entry

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add_entry(self, entry, category):
     log.debug("entries-add")
     catEntry = self.get_category_by_id(category)
     entry.dt = datetime.now()
     catEntry.entries.append(entry)
     data = DBSession.add(catEntry)
     entry = self.get_entry_by_code(entry.code)
     log.info("New id: {0}".format(data))
     DBSession.flush()
     return entry
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:12,代碼來源:settingsfacade.py

示例13: change_status

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def change_status(self, identifier, status):
     log.debug("change_status")
     result = Return()
     try:
         if identifier:
             account = self.by_identifier(identifier)
             if account:
                 account.status = status
                 account.dt = helpers.dtnow()
                 DBSession.add(account)
                 DBSession.flush()
                 result.success()
             else:
                 result.notfound()
         else:
             result.nodata()
         log.info(result.msg)
     except Exception as ex:
         log.exception(ex)
         result.exception()
     return result
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:23,代碼來源:accountfacade.py

示例14: resetpassword

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def resetpassword(self, identifier):
     log.debug("reset password")
     result = Return()
     try:
         if identifier:
             account = self.by_identifier(identifier)
             if account:
                 new = "1234abcd"
                 account.salt = self.encryptor.salt()
                 account.password = self.encryptor.encode(text = new, salt = account.salt)
                 account.dt = helpers.dtnow()
                 DBSession.add(account)
                 log.info("Password has been reset")
                 result.success()
                 result.data = new
             else:
                 result.notfound(identifier)
         else:
             result.nodata()
         log.info(result.msg)
     except Exception as ex:
         log.exception(ex)
         result.exception()
     return result
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:26,代碼來源:accountfacade.py

示例15: add

# 需要導入模塊: from bproject.models.models import DBSession [as 別名]
# 或者: from bproject.models.models.DBSession import add [as 別名]
 def add(self, user = None):
     log.debug("add")
     response = Return()
     try:
         if user:
             user.id = DBSession.add(user)
             response.data = user
             DBSession.flush()
             msg = "User {0} has been added".format(user.name)
             log.info(msg)
             response.success()
             self.history.add(static.options.users, static.actions.add, msg)
         else:
             response.nodata()
     except Exception as ex:
         log.exception(ex)
         response.exception()
     return response
開發者ID:bartoszp32,項目名稱:BProject,代碼行數:20,代碼來源:usersfacade.py


注:本文中的bproject.models.models.DBSession.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。