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


Python model.Session类代码示例

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


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

示例1: update

 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,代码行数:29,代码来源:scenarios.py

示例2: saveResult

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,代码行数:25,代码来源:consumer.py

示例3: update

 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,代码行数:12,代码来源:processors.py

示例4: confirmPersonCandidate

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,代码行数:27,代码来源:people.py

示例5: check

 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,代码行数:7,代码来源:scenarios.py

示例6: feedback

 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,代码行数:30,代码来源:scenarios.py

示例7: delete

 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,代码行数:17,代码来源:scenarios.py

示例8: log

 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,代码行数:8,代码来源:jobs.py

示例9: kill

 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,代码行数:8,代码来源:jobs.py

示例10: index

 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,代码行数:9,代码来源:processors.py

示例11: _to_python

 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,代码行数:10,代码来源:people.py

示例12: extractConfigurationByName

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,代码行数:54,代码来源:scenarios.py

示例13: update_

 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,代码行数:11,代码来源:people.py

示例14: login_

 def login_(self):
     'Process login credentials'
     # Check username
     username = str(request.POST.get('username', ''))
     person = Session.query(model.Person).filter_by(username=username).first()
     # If the username does not exist,
     if not person:
         return dict(isOk=0)
     # Check password
     password_hash = model.hashString(str(request.POST.get('password', '')))
     # If the password is incorrect,
     if password_hash != StringIO.StringIO(person.password_hash).read():
         # Increase and return rejection_count without a requery
         rejection_count = person.rejection_count = person.rejection_count + 1
         Session.commit()
         return dict(isOk=0, rejection_count=rejection_count)
     # If there have been too many rejections,
     if person.rejection_count >= parameter.REJECTION_LIMIT:
         # Expect recaptcha response
         recaptchaChallenge = request.POST.get('recaptcha_challenge_field', '')
         recaptchaResponse = request.POST.get('recaptcha_response_field', '')
         recaptchaKey = config['safe']['recaptcha']['private']
         # Validate
         result = captcha.submit(recaptchaChallenge, recaptchaResponse, recaptchaKey, h.getRemoteIP())
         # If the response is not valid,
         if not result.is_valid:
             return dict(isOk=0, rejection_count=person.rejection_count)
     # Get minutesOffset from UTC
     minutesOffset = h.getMinutesOffset()
     # Save session
     session['minutesOffset'] = minutesOffset
     session['personID'] = person.id
     session['nickname'] = person.nickname
     session['role'] = person.role
     session.save()
     # Save person
     person.minutes_offset = minutesOffset
     person.rejection_count = 0
     Session.commit()
     # Return
     return dict(isOk=1)
开发者ID:AlphaStaxLLC,项目名称:networkplanner,代码行数:41,代码来源:people.py

示例15: update

 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,代码行数:18,代码来源:people.py


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