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


Python Session.commit方法代码示例

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


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

示例1: migrate_extras

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_extras():
    conn = Session.connection()

    statements = '''
    ALTER TABLE datarequests ADD COLUMN extras text;
    '''
    conn.execute(statements)
    Session.commit()
开发者ID:keitaroinc,项目名称:ckanext-datarequests,代码行数:10,代码来源:db.py

示例2: migrate_visibility

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_visibility():
    conn = Session.connection()

    statements = '''
    ALTER TABLE datarequests ADD COLUMN visibility integer;
    '''

    conn.execute(statements)
    Session.commit()
开发者ID:keitaroinc,项目名称:ckanext-datarequests,代码行数:11,代码来源:db.py

示例3: migrate_to_v0_6

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_to_v0_6():
    conn = Session.connection()
    
    statement = """
    ALTER TABLE external_catalog
        ADD COLUMN create_as_private BOOLEAN NOT NULL DEFAULT FALSE;
    """
    conn.execute(statement)
    Session.commit()
开发者ID:OpenDataNode,项目名称:ckanext-odn-ic2pc-sync,代码行数:11,代码来源:external_catalog.py

示例4: clean_harvest_log

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def clean_harvest_log(condition):
    Session.query(HarvestLog).filter(HarvestLog.created <= condition).delete(synchronize_session=False)
    try:
        Session.commit()
    except InvalidRequestError:
        Session.rollback()
        log.error("An error occurred while trying to clean-up the harvest log table")

    log.info("Harvest log table clean-up finished successfully")
开发者ID:ckan,项目名称:ckanext-harvest,代码行数:11,代码来源:__init__.py

示例5: migrate_to_v0_4

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_to_v0_4():
    conn = Session.connection()
    
    statement = """
    ALTER TABLE external_catalog
        ADD COLUMN ext_org_id text;
    """
    conn.execute(statement)
    Session.commit()
开发者ID:OpenDataNode,项目名称:ckanext-odn-ic2pc-sync,代码行数:11,代码来源:external_catalog.py

示例6: migrate_to_v0_3

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_to_v0_3():
    conn = Session.connection()
    
    statement = """
    ALTER TABLE external_catalog
        ADD COLUMN last_updated timestamp,
        ADD COLUMN status smallint not null default 0;
    """
    conn.execute(statement)
    Session.commit()
开发者ID:OpenDataNode,项目名称:ckanext-odn-ic2pc-sync,代码行数:12,代码来源:external_catalog.py

示例7: migrate_v3

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_v3():
    log.debug("Migrating harvest tables to v3. This may take a while...")
    conn = Session.connection()

    statement = """CREATE TABLE harvest_object_extra (
	id text NOT NULL,
	harvest_object_id text,
	"key" text,
	"value" text
);

ALTER TABLE harvest_object
	ADD COLUMN import_started timestamp without time zone,
	ADD COLUMN import_finished timestamp without time zone,
	ADD COLUMN "state" text,
	ADD COLUMN "report_status" text;

ALTER TABLE harvest_source
	ADD COLUMN frequency text,
    ADD COLUMN next_run timestamp without time zone;

ALTER TABLE harvest_job
    ADD COLUMN finished timestamp without time zone;

ALTER TABLE harvest_object_extra
	ADD CONSTRAINT harvest_object_extra_pkey PRIMARY KEY (id);

ALTER TABLE harvest_object_extra
	ADD CONSTRAINT harvest_object_extra_harvest_object_id_fkey FOREIGN KEY (harvest_object_id) REFERENCES harvest_object(id);

UPDATE harvest_object set state = 'COMPLETE' where package_id is not null;
UPDATE harvest_object set state = 'ERROR' where package_id is null;
UPDATE harvest_object set retry_times = 0;
UPDATE harvest_object set report_status = 'updated' where package_id is not null;
UPDATE harvest_object set report_status = 'errored' where package_id is null;
UPDATE harvest_source set frequency = 'MANUAL';

ALTER TABLE harvest_object DROP CONSTRAINT harvest_object_package_id_fkey;
ALTER TABLE harvest_object
    ADD CONSTRAINT harvest_object_package_id_fkey FOREIGN KEY (package_id) REFERENCES package(id) DEFERRABLE;

ALTER TABLE harvest_object_error
	ADD COLUMN line integer;

"""
    conn.execute(statement)
    Session.commit()
    log.info("Harvest tables migrated to v3")
开发者ID:ckan,项目名称:ckanext-harvest,代码行数:50,代码来源:__init__.py

示例8: migrate_v2

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
def migrate_v2():
    log.debug("Migrating harvest tables to v2. This may take a while...")
    conn = Session.connection()

    statements = """
    ALTER TABLE harvest_source ADD COLUMN title text;

    ALTER TABLE harvest_object ADD COLUMN current boolean;
    ALTER TABLE harvest_object ADD COLUMN harvest_source_id text;
    ALTER TABLE harvest_object ADD CONSTRAINT harvest_object_harvest_source_id_fkey FOREIGN KEY (harvest_source_id) REFERENCES harvest_source(id);

    UPDATE harvest_object o SET harvest_source_id = j.source_id FROM harvest_job j WHERE o.harvest_job_id = j.id;
    """
    conn.execute(statements)

    # Flag current harvest_objects
    guids = (
        Session.query(distinct(HarvestObject.guid))
        .join(Package)
        .filter(HarvestObject.package != None)
        .filter(Package.state == u"active")
    )

    update_statement = """
    UPDATE harvest_object
    SET current = TRUE
    WHERE id = (
        SELECT o.id
        FROM harvest_object o JOIN package p ON p.id = o.package_id
        WHERE o.package_id IS NOT null AND p.state = 'active'
            AND o.guid = '%s'
        ORDER BY metadata_modified_date DESC, fetch_finished DESC, gathered DESC
        LIMIT 1)
    """

    for guid in guids:
        conn.execute(update_statement % guid)

    conn.execute("UPDATE harvest_object SET current = FALSE WHERE current IS NOT TRUE")

    Session.commit()
    log.info("Harvest tables migrated to v2")
开发者ID:ckan,项目名称:ckanext-harvest,代码行数:44,代码来源:__init__.py

示例9: create

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
 def create(cls, **kwargs):
     instance = cls(**kwargs)
     Session.add(instance)
     Session.commit()
     return instance.as_dict()
开发者ID:memaldi,项目名称:ckanext-git,代码行数:7,代码来源:__init__.py

示例10: __call__

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
    def __call__(self, environ, start_response):
        if self.drupal_client is None:
            self.drupal_client = DrupalClient()

        # establish from the cookie whether ckan and drupal are signed in
        ckan_signed_in = [False]
        drupal_signed_in = [False]
        for k, v in environ.items():
            key = k.lower()
            if key  == 'http_cookie':
                ckan_signed_in[0] = is_ckan_signed_in(v)
                drupal_signed_in[0] = drupal_extract_cookie(v)
        ckan_signed_in = ckan_signed_in[0]
        drupal_signed_in = drupal_signed_in[0]

        environ['drupal.uid'] = None
        environ['drupal.publishers'] = None
        new_start_response = start_response
        if drupal_signed_in and not ckan_signed_in:
            # get info about the user from drupal and store in environ for
            # use by main CKAN app
            user_id = self.drupal_client.get_user_id_from_session_id(drupal_signed_in)
            res = self.drupal_client.get_user_properties(user_id)
            environ['drupal.uid'] = res['uid']
            environ['drupal.publishers'] = res['publishers']
            environ['drupal.name'] = res['name']

            from ckan import model
            from ckan.model.meta import Session

            def munge(username):
                username.lower().replace(' ', '_')
                return username

            # Add the new Drupal user if they don't already exist.
            query = Session.query(model.User).filter_by(name=unicode(environ['drupal.uid']))
            if not query.count():
                user = model.User(
                    name=munge(unicode(environ['drupal.uid'])), 
                    fullname=unicode(environ['drupal.name']), 
                    about=u'Drupal auto-generated user',
                )
                Session.add(user)
                Session.commit()
            else:
                user = query.one()

            # We want to store values in the user's cookie, so
            # prepare the response header with this value,
            # using auth_tkt to sign it.
            new_header = environ['repoze.who.plugins']['auth_tkt'].remember(
                environ,
                {
                    'repoze.who.userid': environ['drupal.uid'],
                    'tokens': '',
                    'userdata': '',
                }
            )
            # e.g. new_header = [('Set-Cookie', 'bob=ab48fe; Path=/;')]
            cookie_template = new_header[0][1].split('; ')

            cookie_string = ''
            for name, value in [
                ('ckan_apikey', user.apikey),
                ('ckan_display_name', user.fullname),
                ('ckan_user', user.name),
            ]: 
                cookie_string += '; %s="%s"'%(name, value)
                new_cookie = cookie_template[:]
                new_cookie[0] = '%s="%s"'%(name, value)
                new_header.append(('Set-Cookie', str('; '.join(new_cookie))))

            # Also need these cookies to work too:

            # ckan_apikey
            # Value	"3a51edc6-6461-46b8-bfe2-57445cbdeb2b"
            # Host	catalogue.dev.dataco.coi.gov.uk
            # Path	/
            # Secure	No
            # Expires	At End Of Session
            # 
            # 
            # Name	ckan_display_name
            # Value	"James Gardner"
            # Host	catalogue.dev.dataco.coi.gov.uk
            # Path	/
            # Secure	No
            # Expires	At End Of Session
            # 
            # 
            # Name	ckan_user
            # Value	"4466"
            # Host	catalogue.dev.dataco.coi.gov.uk
            # Path	/
            # Secure	No
            # Expires	At End Of Session


            # @@@ Need to add the headers to the request too so that the rest of the stack can sign the user in.

#.........这里部分代码省略.........
开发者ID:icmurray,项目名称:ckanext-dgu,代码行数:103,代码来源:middleware.py

示例11: _do_wordpress_login

# 需要导入模块: from ckan.model.meta import Session [as 别名]
# 或者: from ckan.model.meta.Session import commit [as 别名]
    def _do_wordpress_login(self, environ, wordpress_session_id, new_headers):
        '''Given a WordPress cookie\'s session ID, check it with WordPress, create/modify
        the equivalent CKAN user with properties copied from WordPress and log the
        person in with auth_tkt and its cookie.
        '''
        if self.wordpress_client is None:
            self.wordpress_client = WordPressClient(environ)
        else:
            # Warning! These must be called, or the user data will quite often be wrong.
            # self.wordpress_client may sometimes be a properly set up object with wrong data.
            self.wordpress_client.reset_data()
            self.wordpress_client.update_cookies(environ)

        # ask wp for the wordpress_user_id for this session
        wordpress_user_id = self.wordpress_client.get_user_id()
        if not wordpress_user_id:
            log.error('WordPress said the session ID found in the cookie is not valid.')
            return

        # ask wp about this user
        user_properties = self.wordpress_client.get_user_properties()

        # see if user already exists in CKAN
        ckan_user_name = WordPressUserMapping.wordpress_id_to_ckan_user_name(wordpress_user_id)

        log.debug('_do_wordpress_login ->')
        log.debug(str(wordpress_session_id))
        log.debug(str(wordpress_user_id))
        log.debug(str(ckan_user_name))
        log.debug('<- _do_wordpress_login')

        from ckan import model
        from ckan.model.meta import Session
        query = Session.query(model.User).filter_by(name=unicode(ckan_user_name))
        if not query.count():
            # need to add this user to CKAN
            #raise Exception('Got this userdata:' + str(user_properties))
            # http://stackoverflow.com/questions/1697815/how-do-you-convert-a-python-time-struct-time-object-into-a-datetime-object
            def convertSQLDateTimeToDatetime(value):
                return datetime.datetime.fromtimestamp(time.mktime(time.strptime(value, '%Y-%m-%d %H:%M:%S')))

            date_created = convertSQLDateTimeToDatetime(user_properties['data']['user_registered'])
            user = model.User(
                name=ckan_user_name,
                fullname=unicode(user_properties['data']['display_name']),  # NB may change in WordPress db
                about=u'User account imported from WordPress system.',
                email=user_properties['data']['user_email'], # NB may change in WordPress db
                created=date_created,
            )
            Session.add(user)
            Session.commit()
            log.debug('WordPress user added to CKAN as: %s', user.name)
        else:
            user = query.one()
            log.debug('WordPress user found in CKAN: %s for ckan_user_name: %s', user.name, ckan_user_name)

        self.set_roles(ckan_user_name, user_properties['roles'])

        # There is a chance that on this request we needed to get authtkt
        # to log-out. This would have created headers like this:
        #   'Set-Cookie', 'auth_tkt="INVALID"...'
        # but since we are about to login again, which will create a header
        # setting that same cookie, we need to get rid of the invalidation
        # header first.
        new_headers[:] = [(key, value) for (key, value) in new_headers \
                            if (not (key=='Set-Cookie' and value.startswith('auth_tkt="INVALID"')))]
        #log.debug('Headers reduced to: %r', new_headers)

        # Ask auth_tkt to remember this user so that subsequent requests
        # will be authenticated by auth_tkt.
        # auth_tkt cookie template needs to also go in the response.
        identity = {'repoze.who.userid': str(ckan_user_name),
                    'tokens': '',
                    'userdata': wordpress_session_id}
        headers = environ['repoze.who.plugins']['hri_auth_tkt'].remember(environ, identity)
        if headers:
            new_headers.extend(headers)

        # Tell app during this request that the user is logged in
        environ['REMOTE_USER'] = user.name
        log.debug('Set REMOTE_USER = %r', user.name)
开发者ID:Helsingin-kaupungin-tietokeskus,项目名称:ckanext-hrifi,代码行数:83,代码来源:wordpress_auth.py


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