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


Python Session.flush方法代码示例

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


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

示例1: finish

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [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

示例2: createAccount

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [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,代码来源:

示例3: _newLink

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [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

示例4: set

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
 def set(self, value, _sa_initiator=None):
     key = self.keyfunc(value)
     if key is None:
         session = Session()
         session.flush()
         key = self.keyfunc(value)
     self.__setitem__(key, value, _sa_initiator)
开发者ID:hexsprite,项目名称:plock,代码行数:9,代码来源:components.py

示例5: syncPloneQuestions

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [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

示例6: asDict

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
 def asDict(self, data):
     """For all students already in DB, update details"""
     mtool = getToolByName(self.context, 'portal_membership')
     for dbStudent in Session.query(db.Student).all():
         mb = mtool.getMemberById(dbStudent.userName)
         dbStudent.eMail = mb.getProperty('email')
     Session.flush()
     return dict(success=True)
开发者ID:tutor-web,项目名称:tutorweb.quizdb,代码行数:10,代码来源:student.py

示例7: removeClassSubscriptions

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
def removeClassSubscriptions(ploneClassPath):
    """
    Remove any subscriptions for the class we're removing
    """
    dbSub = (Session.query(db.Subscription)
             .filter_by(plonePath=ploneClassPath)
             .delete())
    Session.flush()
开发者ID:tutor-web,项目名称:tutorweb.quizdb,代码行数:10,代码来源:plone.py

示例8: addAccount

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

示例9: test_not_empty_search

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
    def test_not_empty_search(self):
        session = Session()
        session.add(Organization(name=u"Vin sur vin", language="fr"))
        session.flush()

        browser = Browser(self.app)
        #testURL = self.folder_fr.absolute_url()
        testURL = self.portal.absolute_url()
        browser.open(testURL)
开发者ID:CIRB,项目名称:cirb.organizations,代码行数:11,代码来源:test_forms.py

示例10: createSurvey

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [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)
    session.flush()
    return (session, survey)
开发者ID:,项目名称:,代码行数:11,代码来源:

示例11: BuildSurveyTreeTests

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
class BuildSurveyTreeTests(DatabaseTests):
    def setUp(self):
        from z3c.saconfig import Session
        super(BuildSurveyTreeTests, self).setUp()
        self.session = Session()
        account = model.Account(loginname=u"jane", password=u"secret")
        self.session.add(account)
        self.survey = model.SurveySession(title=u"Survey", zodb_path="survey",
                account=account)
        self.session.add(self.survey)
        self.session.flush()

    def test_empty_profile_no_question(self):
        BuildSurveyTree({}, dbsession=self.survey)
        self.assertTrue(not self.survey.hasTree())

    def test_empty_profile_with_risk(self):
        BuildSurveyTree({'one': createRisk("13")}, dbsession=self.survey)
        self.assertTrue(self.survey.hasTree())
        children = self.survey.children().all()
        self.assertEqual(len(children), 1)
        self.assertEqual(children[0].zodb_path, '13')
        self.assertEqual(children[0].children().count(), 0)

    def test_empty_profile_with_container(self):
        BuildSurveyTree({'one': createContainer("13")}, dbsession=self.survey)
        self.assertTrue(self.survey.hasTree())
        children = self.survey.children().all()
        self.assertEqual(len(children), 1)
        self.assertEqual(children[0].zodb_path, '13')
        self.assertEqual(children[0].children().count(), 0)

    def test_empty_profile_with_profile_question(self):
        BuildSurveyTree({'one': createContainer("13", True)},
                dbsession=self.survey)
        self.assertTrue(not self.survey.hasTree())

    def test_profile_without_answers(self):
        BuildSurveyTree({'one': createContainer("13", True)},
                        profile={"13": []}, dbsession=self.survey)
        self.assertTrue(not self.survey.hasTree())

    def test_profile_with_multiple_answers(self):
        BuildSurveyTree({'one': createContainer("13", True)},
                        profile={"13": ["one", "two"]}, dbsession=self.survey)
        self.assertTrue(self.survey.hasTree())
        children = self.survey.children().all()
        self.assertEqual(len(children), 1)
        self.assertEqual(children[0].zodb_path, '13')
        self.assertEqual(children[0].profile_index, -1)
        grandchildren = children[0].children().all()
        self.assertEqual(len(grandchildren), 2)
        self.assertEqual(grandchildren[0].title, 'one')
        self.assertEqual(grandchildren[0].profile_index, 0)
        self.assertEqual(grandchildren[1].title, 'two')
        self.assertEqual(grandchildren[1].profile_index, 1)
开发者ID:pombredanne,项目名称:Euphorie,代码行数:58,代码来源:test_profile.py

示例12: add_test_organisations_in_db

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
def add_test_organisations_in_db(logger):
    # TODO check if table exists
    engine = component.getUtility(IEngineFactory, name="gscetterbeek")()
    ORMBase.metadata.create_all(engine)

    session = Session()
    if len(session.query(Organization).all()) < 1:

        addr = Address(street='avenue des arts', num='21', post_code='1000', municipality='Bruxelles')
        cat = Category(music=True, welcome=True, other="god")
        incharge = InCharge(title="Sir", first_name="Benoit", second_name="Suttor")
        contact_addr = Address(street='contact street', num='7', post_code='1001', municipality='Brux')
        contact = Contact(title="Monsieur", first_name="James", second_name="Bond", phone="007/11.11.11", fax="00", email="[email protected]", address=contact_addr)
        addinfo = AdditionalInformation(objectif="objectifs de l'association", comments="mon comm")
        # TODO add logo
        orga = Organization(name='CIRB', 
                address=addr, 
                person_incharge=incharge,
                person_contact=contact, 
                category=cat,
                additionalinfo=addinfo,
                status=u"asbl", 
                language=u"fr", 
                website="http://www.cirb.irisnet.be",
                x="150041",
                y="170633")
        addr2 = Address(street='kunststraat', num='21', post_code='1000', municipality='Brussel')
        cat2 = Category(music=True, welcome=True, other="god")
        incharge2 = InCharge(title="Sir", first_name="Benoit", second_name="Suttor")
        contact_addr2 = Address(street='contact street', num='7', post_code='1000', municipality='Brux')
        contact2 = Contact(title="double zero", first_name="Bond", second_name="James", phone="007/11.11.11", fax="00", email="[email protected]", address=contact_addr2)
        addinfo2 = AdditionalInformation(objectif="objectifs de l'association", comments="mon comm")

        orga2 = Organization(name='CIBG', 
                address=addr2, 
                person_incharge=incharge2,
                person_contact=contact2, 
                category=cat2, 
                additionalinfo=addinfo2,
                status=u"asbl", 
                language=u"nl", 
                website="http://www.cibg.irisnet.be",
                x="150041",
                y="170633")

        session.add(orga)
        session.add(orga2)
        session.flush()

        assoc = Association(association_type = "lang")
        assoc.translated_id = orga2.organization_id
        assoc.canonical_id = orga.organization_id 
        session.add(assoc)
        transaction.commit()
    else:
        logger.info('There are already some organizations in DB.')
开发者ID:CIRB,项目名称:gscetterbeek.policy,代码行数:58,代码来源:setuphandlers.py

示例13: createSurveySession

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
def createSurveySession():
    sqlsession = Session()
    account = model.Account(loginname=u"jane", password=u"secret")
    sqlsession.add(account)
    session = model.SurveySession(
        title=u"Session",
        zodb_path="ict/software-development", account=account)
    sqlsession.add(session)
    sqlsession.flush()
    return session
开发者ID:euphorie,项目名称:osha.oira,代码行数:12,代码来源:test_status.py

示例14: handle_update

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
 def handle_update(self):
     data, errors = self.extractData()
     if errors:
         return FAILURE
     session = Session()
     from fernlehrgang.models import Kursteilnehmer
     ktn_id, flg_id = data.get('fernlehrgang_id').split(',')
     ktn = session.query(Kursteilnehmer).get(ktn_id)
     ktn.status = data.get('status')
     ktn.branche = data.get('branche')
     ktn.gespraech = data.get('gespraech')
     ktn.un_klasse = data.get('un_klasse')
     ktn.erstell_datum = data.get('erstell_datum')
     session.flush()
开发者ID:novareto,项目名称:fernlehrgang,代码行数:16,代码来源:teilnehmer.py

示例15: addTranslation

# 需要导入模块: from z3c.saconfig import Session [as 别名]
# 或者: from z3c.saconfig.Session import flush [as 别名]
 def addTranslation(self, language):
     organization = Organization(address=Address(), category=Category(),
                                 person_incharge=InCharge(), person_contact=Contact(),
                                 additionalinfo=AdditionalInformation())
     organization.person_contact.address = Address()
     organization.name = self._organization.name
     organization.language = language
     session = Session()
     session.add(organization)
     session.flush()
     canonical_id = self.getId()
     assoc = Association(association_type="lang")
     assoc.translated_id = organization.organization_id
     assoc.canonical_id = canonical_id
     session.add(assoc)
     session.flush()
开发者ID:CIRB,项目名称:cirb.organizations,代码行数:18,代码来源:traversal.py


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