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


Python Session.add方法代码示例

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


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

示例1: add_relationship

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
    def add_relationship(self, type_, related_package, comment=u''):
        '''Creates a new relationship between this package and a
        related_package. It leaves the caller to commit the change.'''
        import package_relationship
        from ckan import model
        if type_ in package_relationship.PackageRelationship.get_forward_types():
            subject = self
            object_ = related_package
        elif type_ in package_relationship.PackageRelationship.get_reverse_types():
            type_ = package_relationship.PackageRelationship.reverse_to_forward_type(type_)
            assert type_
            subject = related_package
            object_ = self
        else:
            raise KeyError, 'Package relationship type: %r' % type_

        rels = self.get_relationships(with_package=related_package,
                                      type=type_, active=False, direction="forward")
        if rels:
            rel = rels[0]
            if comment:
                rel.comment=comment
            if rel.state == model.State.DELETED:
                rel.undelete()
        else:
            rel = package_relationship.PackageRelationship(
                subject=subject,
                object=object_,
                type=type_,
                comment=comment)
        Session.add(rel)
        return rel
开发者ID:AdamJensen-dk,项目名称:ckan-drupal,代码行数:34,代码来源:package.py

示例2: install

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
def install():
    Base.metadata.create_all(Session().bind)

    data = [
        ("Chicago", "United States", ("60601", "60602", "60603", "60604")),
        ("Montreal", "Canada", ("H2S 3K9", "H2B 1V4", "H7G 2T8")),
        ("Edmonton", "Canada", ("T5J 1R9", "T5J 1Z4", "T5H 1P6")),
        ("New York", "United States", ("10001", "10002", "10003", "10004", "10005", "10006")),
        ("San Francisco", "United States", ("94102", "94103", "94104", "94105", "94107", "94108")),
    ]

    countries = {}
    all_post_codes = []
    for city, country, postcodes in data:
        try:
            country = countries[country]
        except KeyError:
            countries[country] = country = Country(country)

        city = City(city, country)
        pc = [PostalCode(code, city) for code in postcodes]
        Session.add_all(pc)
        all_post_codes.extend(pc)

    for i in xrange(1, 51):
        person = Person(
            "person %.2d" % i,
            Address(street="street %.2d" % i, postal_code=all_post_codes[random.randint(0, len(all_post_codes) - 1)]),
        )
        Session.add(person)

    Session.commit()

    # start the demo fresh
    Session.remove()
开发者ID:simplegeo,项目名称:sqlalchemy,代码行数:37,代码来源:fixture_data.py

示例3: len

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
    links = [a for a in rhscol.getiterator("a")]
    if len(links) != 3 or "Older" not in links[1].text or "Newer" not in links[2].text:
        print "Cant find older and newer links here, backing up"
        oldurl = page.url
        match = re.search("mbl_hs:(\d+),mbl_he:(\d+),mbl_rs:(\d+),mbl_re:(\d+)", oldurl)
        mbl_hs = int(match.group(1)) + 600
        mbl_he = int(match.group(2)) + 600
        mbl_rs = int(match.group(3)) + 600
        mbl_re = int(match.group(4)) + 600
        url = oldurl.replace(
            match.group(0),
            "mbl_hs:" + str(mbl_hs) + ",mbl_he:" + str(mbl_he) + ",mbl_rs:" + str(mbl_rs) + ",mbl_re:" + str(mbl_re),
        )
        lasturl = oldurl
        time.sleep(10)
        continue
    olderurl = u"http://www.google.com" + links[1].attrib["href"]
    newerurl = u"http://www.google.com" + links[2].attrib["href"]
    page = Page(url, html, numresults, olderurl, newerurl)
    Session.add(page)
    Session.commit()
    lasturl = url
    url = newerurl
    for rtdm in CSSSelector("span.rtdm")(doc):
        td, date = [text for text in rtdm.itertext()]
        day = datetime.strptime(date, "%b %d, %Y")
        if day > endtime:
            print "Quitting, " + str(day) + " > " + str(endtime)
            exit()
    time.sleep(10)
开发者ID:sp00,项目名称:google-pastime,代码行数:32,代码来源:run.py

示例4: Inkcut

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
class Inkcut(Application):
    """
    Inkcut application, creates inkcut.ui and controls job, material, 
    and device interaction.
    """
    
    def __init__(self):
        """Load initial application settings from database """
        Application.__init__(self)
        
        # setup the database session
        database = 'sqlite:///%s'%os.path.join(APP_DIR,config.get('Inkcut','database_dir'),config.get('Inkcut','database_name'))
        log.info("Database: %s"%database)
        engine = create_engine(database)
        Session.configure(bind=engine)
        self.session = Session()
        self.job = None
        self._flags = {'block_callbacks':True}
    
    # Builds the Inkcut user interface when Inkcut.run() is called
    def run(self, filename=None):
        builder = Gtk.Builder()
        builder.add_from_file(os.path.join(APP_DIR,'ui','inkcut.ui'))
        window = builder.get_object('inkcut')
            
        # Save any widgets needed later into groups
        self.add_widgets(builder,'job-dependent',['toolbutton3','toolbutton5','toolbutton6','box21','box9','box11','box3','box15','box25','box28','plot-order','box17','menu-file-print-preview','menu-file-print','menu-edit-undo','menu-edit-redo','gtk-zoom-fit','gtk-zoom-in','gtk-zoom-out','menu-file-save-as','menu-file-save'])
        self.add_widgets(builder,'inkcut',['inkcut','devices','statusbar','preview','scale-lock-box','scale-x-label','spinner'])
        self.add_widgets(builder,'graphic-properties',['graphic-width','graphic-height','graphic-scale-x','graphic-scale-y','graphic-scale-lock','graphic-rotation','graphic-rotate-to-save','graphic-weedline-enable','graphic-weedline-padding'])
        self.add_widgets(builder,'plot-properties',['plot-width','plot-height','plot-copies','plot-weedline-enable','plot-weedline-padding','plot-col-spacing','plot-row-spacing','plot-position-x','plot-position-y','plot-feed','plot-feed-distance'])
        self.add_widgets(builder,'material',['materials'])
        
        
        # Connect signals and invoke any UI setup
        builder.connect_signals(self)

        model = ['0 Degrees Clockwise','90 Degrees Clockwise','180 Degrees Clockwise','270 Degrees Clockwise']
        combobox = builder.get_object('graphic-rotation')
        self.set_model_from_list(combobox,model)
        combobox.set_active(0)

        model = ['One Copy at a Time','Best Tracking','Shortest Path']
        combobox = builder.get_object('plot-order')
        self.set_model_from_list(combobox,model)
        combobox.set_active(0)

        # Based on SQL Table: id, name, cost, width, length, margin_top, margin_right, margin_bottom, margin_left, velocity, force, color
        active = 0
        materials = Gtk.ListStore(int,str)
        for m in self.session.query(Material).all():
            materials.append([m.id,m.name])
            if m.id == int(config.get('Inkcut','default_device')):
                active = len(materials)
        combobox = self.get_widget('material','materials')
        combobox.set_model(materials)
        cell = Gtk.CellRendererText()
        combobox.pack_start(cell, True)
        combobox.add_attribute(cell, 'text', 1)  
        combobox.set_active(active)

        
        model = []
        device_active_index = 0
        for device in Device.get_printers():
            name = device.name
            if device.id == int(config.get('Inkcut','default_device')):
                name += " (default)"
                device_active_index = len(model)
            model.append(name)
            log.info(name) 
        combobox = builder.get_object('devices')
        self.set_model_from_list(combobox,model)
        combobox.set_active(device_active_index)
        
        
        
        # Init Accelerators
        accel_group = builder.get_object('accelgroup1')
        for action in builder.get_object('actiongroup1').list_actions():
            action.set_accel_group(accel_group)
            action.connect_accelerator()
        window.add_accel_group(accel_group)

        # Show the widgets
        self._update_sensitivity()
        window.show_all()
        self.flash("",indicator=False)
        
        # Fix!
        self._flags['block_callbacks']=False
        self.add_window(window,'inkcut')
        self.on_graphic_scale_lock_toggled(self.get_widget('graphic-properties','graphic-scale-lock'))
        # From command line arguments
        if filename is not None and os.path.isfile(filename):
            self.create_job(filename)
            
        Gtk.main()

    # ===================================== Plot Callbacks ===============================================
    @callback
#.........这里部分代码省略.........
开发者ID:pc-coholic,项目名称:Inkcut,代码行数:103,代码来源:inkcut.py

示例5: create

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
 def create(cls, id):
     f = Foo(id=id)
     Session.add(f)
     Session.commit()
     return f
开发者ID:marchon,项目名称:flylons,代码行数:7,代码来源:foo.py

示例6: CSSSelector

# 需要导入模块: from meta import Session [as 别名]
# 或者: from meta.Session import add [as 别名]
from tweet import Tweet
from meta import Session

numdupes = 0
for page in Session.query(Page).order_by(Page.id):
    doc = lxml.document_fromstring(page.html)
    rtr = CSSSelector('ol#rtr')(doc)
    if not rtr:
        continue
    for tweet in rtr[0].getchildren():
        twitterlink = CSSSelector('span.a')(tweet)
        rtdelta = int(CSSSelector('div.rtdelta')(tweet)[0].text)
        assert len(twitterlink) == 1 and twitterlink[0].text == 'Twitter'
        toclear = []
        c = twitterlink[0]
        while c is not None:
            toclear.append(c)
            c = c.getnext()
        for c in toclear:
            c.clear()
        text = lxml.tostring(tweet, encoding=unicode, method='text')
        when = page.hit - timedelta(seconds=rtdelta)
        t = Tweet(text, when)
        if Session.query(Tweet).filter(Tweet.md5==t.md5).first() is None:
            Session.add(t)
        else:
            numdupes = numdupes + 1
    
Session.commit()
print 'committed, there were ' + str(numdupes) + ' dupes'
开发者ID:drassi,项目名称:google-pastime,代码行数:32,代码来源:analyze.py


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