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


Python Session.add方法代码示例

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


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

示例1: test_browser_get

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_browser_get(self):
     import datetime
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.api.authentication import generate_token
     from tno.euphorie.model import DutchCompany
     from Products.Five.testbrowser import Browser
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='secret')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     survey_session.dutch_company = DutchCompany(
             title=u'Acme B.V.',
             employees='40h',
             email='[email protected]',
             submit_date=datetime.date(2012, 6, 6))
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.handleErrors = False
     browser.open(
             'http://nohost/plone/client/api/users/1/sessions/1/'
             'report-actionplan')
     self.assertEqual(browser.headers['Content-Type'], 'application/rtf')
     self.assertTrue('Bedrijfsnaam' in browser.contents)
开发者ID:euphorie,项目名称:tno.euphorie,代码行数:35,代码来源:test_api.py

示例2: testEnumerateUsers_NoInexactMatch

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def testEnumerateUsers_NoInexactMatch(self):
     session = Session()
     account = model.Account(loginname='john', password=u'jane')
     session.add(account)
     plugin = EuphorieAccountPlugin('plugin')
     self.assertEqual(
             plugin.enumerateUsers(login='john', exact_match=False), [])
开发者ID:,项目名称:,代码行数:9,代码来源:

示例3: test_add

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
    def test_add(self):
        session = Session()
        session.add(Organization(name=u"Vin", language="fr"))
        self.assertEqual(len(session.query(Organization).all()), 1)

        orga = session.query(Organization).first()
        self.assertEqual(orga.name, u"Vin")
开发者ID:CIRB,项目名称:cirb.organizations,代码行数:9,代码来源:test_ormbase.py

示例4: test_get_no_company_data_present

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
    def test_get_no_company_data_present(self):
        import datetime
        import json
        from z3c.saconfig import Session
        from euphorie.client.model import SurveySession
        from euphorie.content.tests.utils import BASIC_SURVEY
        from euphorie.client.tests.utils import addAccount
        from euphorie.client.tests.utils import addSurvey
        from euphorie.client.api.authentication import generate_token
        from Products.Five.testbrowser import Browser

        self.loginAsPortalOwner()
        addSurvey(self.portal, BASIC_SURVEY)
        account = addAccount(password="secret")
        survey_session = SurveySession(
            title=u"Dummy session",
            created=datetime.datetime(2012, 4, 22, 23, 5, 12),
            modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
            zodb_path="nl/ict/software-development",
            account=account,
        )
        Session.add(survey_session)
        browser = Browser()
        browser.addHeader("X-Euphorie-Token", generate_token(account))
        browser.open("http://nohost/plone/client/api/users/1/sessions/1/company")
        self.assertEqual(browser.headers["Content-Type"], "application/json")
        response = json.loads(browser.contents)
        self.assertEqual(response["type"], "company")
开发者ID:euphorie,项目名称:Euphorie,代码行数:30,代码来源:test_company.py

示例5: __init__

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
    def __init__(self, data):
        
        session = Session()
        context = Mail()
        context.parsing_date = datetime.now()
        mail = message_from_string(data)
        
        for name, adapter in component.getAdapters((context,), interfaces.IFieldMapper):
            adapter.parse(mail)
        
        for part in mail.mailparts:
            type = part.type
            adapter = component.queryAdapter(context, interface=interfaces.IContentMapper, name=type)
            if adapter is None:
                adapter = component.getAdapter(context, interface=interfaces.IContentMapper, name='default')
            adapter.parse(part)
        
        backuppath = local_configuration['backup'].get('backup', '')
        if os.path.isdir(backuppath):
            name = time.strftime('%Y%m%d%H%M')
            path = os.path.join(backuppath, '%s.mail' % name)
            counter = 0
            while os.path.isfile(path):
                path = os.path.join(backuppath, '%s_%s.mail' % (name, counter,))
                counter += 1
            context.original_path = os.path.abspath(path)
            with open(path, 'w') as f:
                f.write(data)
            f.close()

        context.hash = hashlib.md5(data).hexdigest()

        session.add(context)
        transaction.commit()
        session.close()
开发者ID:mailcone,项目名称:mailcone-google-svn-dump,代码行数:37,代码来源:parser.py

示例6: createAccount

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def createAccount(self, login="john", password=u"jane"):
     from euphorie.client.model import Account
     session = Session()
     account = Account(loginname=login, password=password)
     session.add(account)
     session.flush()
     return account
开发者ID:,项目名称:,代码行数:9,代码来源:

示例7: syncPloneQuestions

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
def syncPloneQuestions(dbLec, lectureObj):
    """Ensure database has same questions as Plone"""
    # Get all plone questions, turn it into a dict by path
    if getattr(lectureObj, 'isAlias', False):
        lectureObj = lectureObj._target
    listing = lectureObj.portal_catalog.unrestrictedSearchResults(
        path={'query': '/'.join(lectureObj.getPhysicalPath()), 'depth': 1},
        object_provides=IQuestion.__identifier__
    )

    # Sort questions into a dict by path
    ploneQns = _ploneQuestionDict(listing)

    # Get all questions currently in the database
    for dbQn in (Session.query(db.Question).filter(db.Question.lectures.contains(dbLec))):
        qn = ploneQns.get(dbQn.plonePath, None)
        if qn is not None:
            # Question still there (or returned), update
            dbQn.active = True
            dbQn.correctChoices = json.dumps(qn['correctChoices'])
            dbQn.incorrectChoices = json.dumps(qn['incorrectChoices'])
            dbQn.lastUpdate = qn['lastUpdate']
            # Dont add this question later
            del ploneQns[dbQn.plonePath]
        elif dbQn.active and not(dbQn.plonePath.startswith(dbLec.plonePath)):
            # Remove slave symlink question from lecture
            dbQn.lectures = [l for l in dbQn.lectures if l != dbLec]
            dbQn.active = len(dbQn.lectures) > 0
            dbQn.lastUpdate = datetime.datetime.utcnow()
        elif dbQn.active:
            # Remove question from all lectures and mark as inactive
            dbQn.lectures = []
            dbQn.active = False
            dbQn.lastUpdate = datetime.datetime.utcnow()
        else:
            # No question & already removed from DB
            pass

    # Insert any remaining questions
    for (path, qn) in ploneQns.iteritems():
        try:
            # If question already exists, add it to this lecture.
            dbQn = Session.query(db.Question).filter(db.Question.plonePath == path).one()
            dbQn.lectures.append(dbLec)
            dbQn.active = True
        except NoResultFound:
            Session.add(db.Question(
                plonePath=path,
                qnType=qn['qnType'],
                lastUpdate=qn['lastUpdate'],
                correctChoices=json.dumps(qn['correctChoices']),
                incorrectChoices=json.dumps(qn['incorrectChoices']),
                timesAnswered=qn['timesAnswered'],
                timesCorrect=qn['timesCorrect'],
                lectures=[dbLec],
            ))

    dbLec.lastUpdate = datetime.datetime.utcnow()
    Session.flush()
    return True
开发者ID:tutor-web,项目名称:tutorweb.quizdb,代码行数:62,代码来源:plone.py

示例8: test_get

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_get(self):
     import datetime
     import json
     from z3c.saconfig import Session
     from euphorie.client.model import Company
     from euphorie.client.model import SurveySession
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     from euphorie.client.api.authentication import generate_token
     from Products.Five.testbrowser import Browser
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='secret')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account,
             company=Company(country='nl',
                             employees='1-9',
                             referer='other'))
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.open(
             'http://nohost/plone/client/api/users/1/sessions/1/company')
     self.assertEqual(browser.headers['Content-Type'], 'application/json')
     response = json.loads(browser.contents)
     self.assertEqual(response['type'], 'company')
开发者ID:pombredanne,项目名称:Euphorie,代码行数:33,代码来源:test_company.py

示例9: test_browser

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_browser(self):
     import datetime
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     account = addAccount(password='secret')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.handleErrors = False
     browser.open('http://nohost/plone/client/api/users/1/'
                     'sessions/1/report-timeline')
     self.assertEqual(
             browser.headers['Content-Type'],
             'application/vnd.openxmlformats-'
                                     'officedocument.spreadsheetml.sheet')
开发者ID:euphorie,项目名称:Euphorie,代码行数:29,代码来源:test_session.py

示例10: finish

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
    def finish(self):
        self.applySteps(self.context)
        sqlalsession = Session()
        sqlalsession.flush()
        organization = self.session["organization"]
        canonical_id = self.session["canonical_id"]
        if organization.organization_id:
            sqlalsession.merge(organization)
        else:
            sqlalsession.add(organization)
            if canonical_id:
                # flush required for organization.organization_id creation
                sqlalsession.flush()
                assoc = Association(association_type="lang")
                assoc.translated_id = organization.organization_id
                assoc.canonical_id = canonical_id
                sqlalsession.add(assoc)

        from cirb.organizations.traversal import OrganizationWrapper

        # transaction.commit()
        self.request.SESSION.clear()
        orga_page = "{0}/organizations_manage".format(self.context.absolute_url())
        if isinstance(self.context, OrganizationWrapper):
            orga_page = "{0}/organizations_manage".format(self.context.__parent__.__parent__.absolute_url())
        self.request.response.redirect(orga_page)
开发者ID:CIRB,项目名称:cirb.organizations,代码行数:28,代码来源:organizationsform.py

示例11: test_with_introduction

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_with_introduction(self):
     import datetime
     import json
     from z3c.saconfig import Session
     from euphorie.client.model import SurveySession
     from euphorie.client.api.authentication import generate_token
     from euphorie.content.tests.utils import BASIC_SURVEY
     from euphorie.client.tests.utils import addAccount
     from euphorie.client.tests.utils import addSurvey
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     survey = self.portal.client['nl']['ict']['software-development']
     survey.introduction = u'<p>Fancy intro.</p>'
     account = addAccount(password='secret')
     survey_session = SurveySession(
             title=u'Dummy session',
             created=datetime.datetime(2012, 4, 22, 23, 5, 12),
             modified=datetime.datetime(2012, 4, 23, 11, 50, 30),
             zodb_path='nl/ict/software-development',
             account=account)
     Session.add(survey_session)
     browser = Browser()
     browser.addHeader('X-Euphorie-Token', generate_token(account))
     browser.open('http://nohost/plone/client/api/users/1/sessions/1')
     self.assertEqual(browser.headers['Content-Type'], 'application/json')
     response = json.loads(browser.contents)
     self.assertTrue('introduction' in response)
     self.assertEqual(response['introduction'], u'<p>Fancy intro.</p>')
开发者ID:euphorie,项目名称:Euphorie,代码行数:30,代码来源:test_session.py

示例12: _newLink

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
    def _newLink(self, vestigings_sleutel, webservice):
        session = Session()
        # Check if there is an account from another regelhulp for the same
        # vestiging.
        account = session.query(model.Account)\
            .filter(model.Account.loginname == vestigings_sleutel)\
            .first()
        if account is None:
            # Create a new account
            account = model.Account(
                    loginname=vestigings_sleutel,
                    password=None)
            session.add(account)
            session.flush()  # Make sure account.id is set
        log.info('Created new OD account %s for %s', account.loginname, self.url())

        # Login with the account
        newSecurityManager(None, account)
        pas = getToolByName(self.context, 'acl_users')
        pas.updateCredentials(self.request, self.response, account.loginname, None)

        # And start a new survey
        survey = aq_inner(self.context)
        ss = SessionManager.start(title=survey.Title(), survey=survey)
        Session.add(OdLink(
            session=ss,
            vestigings_sleutel=vestigings_sleutel,
            webservice=webservice))
        v_url = urlparse.urlsplit(survey.absolute_url() + '/od-new').path
        trigger_extra_pageview(self.request, v_url)
        self.request.response.redirect('%s/start' % survey.absolute_url())
开发者ID:euphorie,项目名称:tno.euphorie,代码行数:33,代码来源:od.py

示例13: test_authenticate_login_valid_login

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_authenticate_login_valid_login(self):
     session = Session()
     account = model.Account(loginname='john', password=u'jane')
     session.add(account)
     plugin = EuphorieAccountPlugin('plugin')
     credentials = {'login': 'john', 'password': u'jane'}
     self.assertTrue(plugin._authenticate_login(credentials) is not None)
开发者ID:,项目名称:,代码行数:9,代码来源:

示例14: test_sessions_ordering

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
 def test_sessions_ordering(self):
     import datetime
     from euphorie.content.tests.utils import BASIC_SURVEY
     from z3c.saconfig import Session
     from AccessControl.SecurityManagement import newSecurityManager
     from ..model import Account
     from ..model import SurveySession
     self.loginAsPortalOwner()
     addSurvey(self.portal, BASIC_SURVEY)
     session = Session()
     account = Account(loginname='johny',
             sessions=[
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'One',
                     modified=datetime.datetime(2012, 12, 10)),
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'Three',
                     modified=datetime.datetime(2012, 12, 12)),
                 SurveySession(zodb_path='nl/ict/software-development',
                     title=u'Two',
                     modified=datetime.datetime(2012, 12, 11))])
     session.add(account)
     newSecurityManager(None, account)
     view = self.View(self.portal.client['nl'], None)
     self.assertEqual(
             [s['title'] for s in view.sessions()],
             [u'Three', u'Two', 'One'])
开发者ID:pombredanne,项目名称:Euphorie,代码行数:29,代码来源:test_functional_country.py

示例15: createSurvey

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import add [as 别名]
def createSurvey():
    session = Session()
    account = model.Account(loginname=u"jane", password=u"secret")
    session.add(account)
    survey = model.SurveySession(title=u"Session", zodb_path="survey",
            account=account)
    session.add(survey)
    return (session, survey)
开发者ID:,项目名称:,代码行数:10,代码来源:


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