当前位置: 首页>>代码示例>>Python>>正文


Python Session.query方法代码示例

本文整理汇总了Python中np.model.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在np.model.Session的用法示例。


在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: confirmPersonCandidate

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
def confirmPersonCandidate(ticket):
    'Move changes from the PersonCandidate table into the Person table'
    # Query
    candidate = Session.query(model.PersonCandidate).filter(model.PersonCandidate.ticket==ticket).filter(model.PersonCandidate.when_expired>=datetime.datetime.utcnow()).first()
    # If the ticket exists,
    if candidate:
        # If the person exists,
        if candidate.person_id:
            # Update person
            person = Session.query(model.Person).get(candidate.person_id)
            person.username = candidate.username
            person.password_hash = candidate.password_hash
            person.nickname = candidate.nickname
            person.email = candidate.email
            person.email_sms = candidate.email_sms
            # Reset rejection_count
            person.rejection_count = 0
        # If the person does not exist,
        else:
            # Add person
            Session.add(model.Person(candidate.username, candidate.password_hash, candidate.nickname, candidate.email, candidate.email_sms))
        # Delete ticket
        Session.delete(candidate)
        # Commit
        Session.commit()
    # Return
    return candidate
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:29,代码来源:people.py

示例2: saveResult

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
def saveResult(outgoingMessage):
    'Save result in local database'
    # Unpack result from outgoing message
    outgoingPack = pickle.loads(outgoingMessage.body)
    scenarioID, scenarioOutput, scenarioData, scenarioStatus = outgoingPack
    print 'Consuming scenario %s' % scenarioID
    # Load scenario from local database
    scenario = Session.query(model.Scenario).get(scenarioID)
    # If the scenario does not exist,
    if not scenario:
        print 'Scenario %s does not exist' % scenarioID
        return
    # Get folder
    scenarioFolder = scenario.getFolder()
    # Save data
    if scenarioData:
        scenarioPath = scenarioFolder + '.zip'
        open(scenarioPath, 'wb').write(scenarioData)
        store.unzipData(scenarioFolder, scenarioData)
    # Save output
    scenario.output = scenarioOutput
    scenario.status = scenarioStatus
    Session.commit()
    # Post to callback
    scenario.postCallback()
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:27,代码来源:consumer.py

示例3: check

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def check(self, scenarioID):
     # Initialize
     personID = h.getPersonID()
     # Load
     scenario = Session.query(model.Scenario).filter(model.Scenario.id==scenarioID).filter(model.getScopeFilter(personID)).first()
     # Return
     return dict(isOk=0 if not scenario or scenario.isQueued() else 1)
开发者ID:fparaggio,项目名称:networkplanner,代码行数:9,代码来源:scenarios.py

示例4: update

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def update(self, id):
     'PUT /scenarios/id: Update an existing item'
     # Initialize
     personID = h.getPersonID()
     # Load
     scenario = Session.query(model.Scenario).filter(model.Scenario.id==id).first()
     # If the scenario doesn't exist,
     if not scenario:
         return dict(isOk=0, message='Scenario %s does not exist' % id)
     # If the user is not the owner,
     if personID != scenario.owner_id:
         return dict(isOk=0, message='You are not the owner of scenario %s' % id)
     # Load
     scenarioName = request.params.get('scenarioName', '').strip()
     if not scenarioName:
         return dict(isOk=0, message='Please enter a scenario name')
     try:
         scenarioScope = int(request.params.get('scenarioScope'))
     except ValueError:
         return dict(isOk=0, message='Scenario scope must be an integer')
     if scenarioScope not in [model.scopePrivate, model.scopePublic]:
         return dict(isOk=0, message='Scenario scope can either be %s=private or %s=public' % (model.scopePrivate, model.scopePublic))
     # Update
     scenario.name = scenarioName
     scenario.scope = scenarioScope
     # Commit
     Session.commit()
     # Return
     return dict(isOk=1)
开发者ID:fparaggio,项目名称:networkplanner,代码行数:31,代码来源:scenarios.py

示例5: feedback

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def feedback(self):
     'Send feedback'
     # Load
     text = request.POST.get('text', '').strip()
     # If there is text,
     if text:
         # Initialize
         personID = h.getPersonID()
         headerByValue = {}
         # If the person is logged in,
         if personID:
             # Load
             person = Session.query(model.Person).get(personID)
             nickname = person.nickname
             headerByValue['reply-to'] = email.utils.formataddr((nickname, person.email))
         # If th person is not logged in,
         else:
             nickname = 'Anonymous'
         # Send it
         subject = '[%s] Feedback from %s' % (parameter.SITE_NAME, nickname)
         try:
             smtp.sendMessage(
                 config['safe']['mail support'], 
                 config['safe']['mail support'], subject, text, headerByValue)
         except:
             return dict(isOk=0, message='Error sending message')
         # Return
         return dict(isOk=1)
     # Return
     return dict(isOk=0)
开发者ID:fparaggio,项目名称:networkplanner,代码行数:32,代码来源:scenarios.py

示例6: kill

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def kill(self, jobID, host):
     'Attempt to kill the job'
     job = Session.query(model.Job).filter(model.Job.pid == jobID and model.Job.host == host).first()
     if (not job) or (job.end_time) or (not h.isAdmin()):
         return dict(isOk=0)
     else:
         job.kill()
     return dict(isOk=1)
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:10,代码来源:jobs.py

示例7: log

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def log(self, jobID, host):
     'Show the log for the job'
     job = Session.query(model.Job).filter(model.Job.pid == jobID and model.Job.host == host).first()
     filepath = job.log_filename 
     file_size = os.path.getsize(filepath)
     headers = [('Content-Type', 'text/plain'), ('Content-Length', str(file_size))]
     fapp = FileApp(filepath, headers=headers)
     return fapp(request.environ, self.start_response)
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:10,代码来源:jobs.py

示例8: index

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def index(self):
     "Show processors that have updated in the last hour"
     c.processors = (
         Session.query(model.Processor)
         .filter(model.Processor.when_updated > datetime.datetime.utcnow() - datetime.timedelta(days=1))
         .order_by(model.Processor.when_updated.desc())
         .all()
     )
     return render("/processors/index.mako")
开发者ID:aarabi,项目名称:networkplanner,代码行数:11,代码来源:processors.py

示例9: _to_python

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def _to_python(self, value, person):
     "Check whether the value is unique"
     # If the person is new or the value changed,
     if not person or getattr(person, self.fieldName) != value:
         # Make sure the value is unique
         if Session.query(model.Person).filter(getattr(model.Person, self.fieldName) == value).first():
             # Raise
             raise formencode.Invalid(self.errorMessage, value, person)
     # Return
     return value
开发者ID:fparaggio,项目名称:networkplanner,代码行数:12,代码来源:people.py

示例10: update_

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def update_(self):
     "Send update confirmation email"
     # Load
     personID = h.getPersonID()
     # If the person is not logged in,
     if not personID:
         return dict(isOk=0)
     # Prepare
     person = Session.query(model.Person).get(personID)
     # Return
     return changeAccount(dict(request.POST), "update", "/people/confirm.mako", person)
开发者ID:fparaggio,项目名称:networkplanner,代码行数:13,代码来源:people.py

示例11: extractConfigurationByName

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
def extractConfigurationByName(valueByName, scenarioFolder):
    # Initialize
    configuration = {}
    # For each value,
    for key, value in valueByName.iteritems():
        # Parse key
        keyTerms = variable_store.parseKey(key)
        # If the key is compound,
        if len(keyTerms) > 1:
            # Extract
            modelType, section, option = keyTerms
            # If the value already exists, then it must have been overridden
            if modelType in configuration:
                if section in configuration[modelType]:
                    if option in configuration[modelType][section]:
                        continue
            # If we have a hidden field,
            if option.endswith('_h'):
                # If the hidden field was overridden, skip this and wait until we find the real value
                if int(value) == 0:
                    continue
                # Remove suffix
                option = option[:-2]
                # Prepare
                sourceScenario = Session.query(model.Scenario).get(value)
                relativePath = sourceScenario.input['%s configuration' % modelType][section][option]
                # If the old scenario did not specify a file here,
                if not relativePath:
                    value = ''
                else:
                    # Prepare
                    sourcePath = os.path.join(sourceScenario.getFolder(), relativePath)
                    # Copy source in case it is deleted
                    store.makeFolderSafely(os.path.join(scenarioFolder, os.path.dirname(relativePath)))
                    targetPath = os.path.join(scenarioFolder, relativePath)
                    shutil.copyfile(sourcePath, targetPath)
                    value = relativePath
            # If the user wants to use a new file and the value is an upload,
            elif hasattr(value, 'file'):
                # Prepare
                relativePath = os.path.join(modelType, section, option + os.path.splitext(value.filename)[1])
                # Save it
                store.makeFolderSafely(os.path.join(scenarioFolder, os.path.dirname(relativePath)))
                targetPath = os.path.join(scenarioFolder, relativePath)
                shutil.copyfileobj(value.file, open(targetPath, 'wb'))
                value = relativePath
            # Store
            if modelType not in configuration:
                configuration[modelType] = {}
            if section not in configuration[modelType]:
                configuration[modelType][section] = {}
            configuration[modelType][section][option] = value
    # Return
    return configuration
开发者ID:fparaggio,项目名称:networkplanner,代码行数:56,代码来源:scenarios.py

示例12: update

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def update(self):
     "Update processor information"
     # Load
     ip = h.getRemoteIP()
     processor = Session.query(model.Processor).filter(model.Processor.ip == ip).first()
     # If the processor doesn't exist,
     if not processor:
         processor = model.Processor(ip)
         Session.add(processor)
     # Update
     processor.when_updated = datetime.datetime.utcnow()
     Session.commit()
开发者ID:aarabi,项目名称:networkplanner,代码行数:14,代码来源:processors.py

示例13: delete

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def delete(self, id):
     'DELETE /scenarios/id: Delete an existing item'
     # Initialize
     personID = h.getPersonID()
     # Load
     scenario = Session.query(model.Scenario).filter(model.Scenario.id==id).first()
     # If the scenario doesn't exist,
     if not scenario:
         return dict(isOk=0, message='Scenario %s does not exist' % id)
     # If the user is not the owner,
     if personID != scenario.owner_id:
         return dict(isOk=0, message='You are not the owner of scenario %s' % id)
     # Delete
     Session.delete(scenario)
     Session.commit()
     # Return
     return dict(isOk=1)
开发者ID:fparaggio,项目名称:networkplanner,代码行数:19,代码来源:scenarios.py

示例14: reset

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def reset(self):
     'Reset password'
     # Get email
     email = request.POST.get('email')
     # Try to load the person
     person = Session.query(model.Person).filter(model.Person.email==email).first()
     # If the email is not in our database,
     if not person: 
         return dict(isOk=0)
     # Reset account
     c.password = store.makeRandomAlphaNumericString(parameter.PASSWORD_LENGTH_AVERAGE)
     return changeAccount(dict(
         username=person.username,
         password=c.password,
         nickname=person.nickname,
         email=person.email,
         email_sms=person.email_sms,
     ), 'reset', '/people/confirm.mako', person)
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:20,代码来源:people.py

示例15: update

# 需要导入模块: from np.model import Session [as 别名]
# 或者: from np.model.Session import query [as 别名]
 def update(self):
     'Show account update page'
     # Load
     personID = h.getPersonID()
     # If the person is not logged in,
     if not personID:
         # Return
         return redirect(url('person_login', targetURL=h.encodeURL('/')))
     # Render
     c.isNew = False
     person = Session.query(model.Person).get(personID)
     # Return
     return formencode.htmlfill.render(render('/people/change.mako'), {
         'username': person.username,
         'nickname': person.nickname,
         'email': person.email,
         'email_sms': person.email_sms,
     })
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:20,代码来源:people.py


注:本文中的np.model.Session.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。