Exemplo n.º 1
0
def user_update(user):
    web.update(
        "users",
        where='id=$id',
        credentials=user.password,
        vars=user.copy(),
    )
Exemplo n.º 2
0
Arquivo: node.py Projeto: keizo/kulu
def _prepared(node, raw=False):
    if node.cache and not raw:
        cached = pickle.loads(node.cache)
        
        # override the user info in cached, since when the user updates their
        # profile, it will not update the node cache
        cached.name = node.name
        cached.picture = node.picture
        return cached
    
    # Proceed to build the node from scratch.
    
    # Merge data created by node modules.
    node = _node_load(node)
    
    # Apply filters or other preperations.
    if not raw:
        node = _node_prepare(node)
    
        # Cache all that work so we never have to do it until something changes.
        pickled = pickle.dumps(node)
        if node.cache_nid:
            web.update('cache_node',where='nid=$node.nid AND vid=$node.vid',
                created=time.time(), cache=pickled)
        else:
            web.insert('cache_node',nid=node.nid,vid=node.vid,
                created=time.time(),cache=pickled)
    
    return node
Exemplo n.º 3
0
def updaterecent(userid, threadid):
    """ updates the user's 'recent_threads' column with the new thread that they just visited
    
        returns the updated thread list.
        
        TOOD refactor this, it's a prety ugly implementation of recent threads.
    """
    threadlist = people.getperson(userid).recent_threads
    recent = []
    
    if threadlist:
        recent = threadlist.split(' ')    
    if threadid in recent:
        recent.remove(threadid)
        
    recent.insert(0, threadid)
    
    print recent
    
    text = recent.pop(0) # take care of the fence post.
    for r in recent:
        text += ' ' + r

    web.update('people', where='id=%s' % web.sqlquote(userid), recent_threads=text)
    return 'threads'
Exemplo n.º 4
0
Arquivo: util.py Projeto: keizo/kulu
 def __setitem__(self, key, values):
     #make values a storage object if it's not...
     #there is probably a cleaner way to do this
     if issubclass(values,dict) is not True:
         values = web.storify({key:values})
         
     if self.has_key(key):
         web.update(self.table,where=self.index+'=$key',vars=locals(),**web.storify(values,**self[key]))
     else:
         web.insert(self.table,**web.storify({self.index:key},**values))
     dict.__setitem__(self,key,values)
Exemplo n.º 5
0
def store_infos(infos, extra_db_entries):
  print " %s" % (infos)
  #web.debug(" %s" % (infos))
  simple_infos = infos.copy()
  multiple_infos = {}
  for imv in config.have_many_values:
    try:
      del simple_infos[imv]
      multiple_infos[imv] = infos[imv]
    except KeyError:
      pass
  #checking for file renaming with sha
  possiblePrevFiles = web.query("select id, filename, batch from images where sha ='"+infos['sha']+"'")
  updatingFile = False
  if len(possiblePrevFiles) == 1:
    #file found in db
    print "INFO duplicate found : "+infos['filename']
    prevFile = possiblePrevFiles[0]
    file_id = prevFile.id
    simple_infos['batch'] = prevFile.batch
    try:
      extra_db_entries.remove(prevFile.filename)
      web.update('images', 'id = %s' % file_id, None, **simple_infos)
      updatingFile = True
    except ValueError:
      #raise with .remove when the filename do not match
      print "WARNING duplicate sha accross fileset, creating new entry"
  else:
    if len(possiblePrevFiles) > 1:
      #more than one file with this sha... 
      print "INFO sha present multiple time for file : "+infos["filename"]
    file_id = web.insert('images', True, **simple_infos)

  for index in multiple_infos.keys():
    #store the value in its table
    for value in multiple_infos[index]:
      try:
        value_id = web.insert(index+'s', True, **{"value" : value})
        #debuginsert(index+'s', False, **{"value" : value})
      except: 
        #TODO should be IntegrityError for mysql but not sure how best integrate that without breaking the DB abstraction...
        #but if the error wasn't an IntegrityError then the next line should fail
        value_id = web.query('select id from %ss where value = "%s"' % (index, value))[0].id
      #store the relationship between the value and the file
      try:
        web.insert("images_"+index+'s', False, **{index+"_id": value_id, "image_id" : file_id})
      except Exception, inst:
        #if we are update a file we might raise some integrity error here
        if updatingFile:
          pass
        else:
          raise inst
Exemplo n.º 6
0
def datasource_update(datasource, project, user):
    return web.update("datasources", where='id=$id',
        type=datasource.type,
        adapter=datasource.adapter,
        url=datasource.url,
        frequency=datasource.frequency,
        description=datasource.description,
        vars={'id': datasource.id},
    )
Exemplo n.º 7
0
def comment_order_update(comment):
    return web.update(
        "notes",
        where='id=$id',
        ord=comment.ord,
        vars={
            'id': comment.id,
        },
    )
Exemplo n.º 8
0
def comment_update(comment, point, user):
    return web.update("notes", where='id=$id', 
                        text=comment.text,
#	                 location_id=point.id,
#		         user_id=user.id,
#		         origin=comment.origin,
                        type=comment.get("type", "comment"),
#                        ranking=0,
                        vars={'id': comment.id},
                        )
Exemplo n.º 9
0
def datasource_update(datasource, project, user):
    return web.update(
        "datasources",
        where='id=$id',
        type=datasource.type,
        adapter=datasource.adapter,
        url=datasource.url,
        frequency=datasource.frequency,
        description=datasource.description,
        vars={'id': datasource.id},
    )
Exemplo n.º 10
0
def trigger_update(trigger, project, user):
    return web.update("triggers", where='id=$id', 
                      trigger_condition=trigger.trigger_condition,
                      trigger_action=trigger.trigger_action,
                      adapter=trigger.adapter,
                      url=trigger.url,
                      description=trigger.description,
                      user_id=user.id, 
		      project_id=project.id,
                      vars={'id': trigger.id},
                      )
Exemplo n.º 11
0
def comment_update(comment, point, user):
    return web.update(
        "notes",
        where='id=$id',
        text=comment.text,
        #	                 location_id=point.id,
        #		         user_id=user.id,
        #		         origin=comment.origin,
        type=comment.get("type", "comment"),
        #                        ranking=0,
        vars={'id': comment.id},
    )
Exemplo n.º 12
0
def trigger_update(trigger, project, user):
    return web.update(
        "triggers",
        where='id=$id',
        trigger_condition=trigger.trigger_condition,
        trigger_action=trigger.trigger_action,
        adapter=trigger.adapter,
        url=trigger.url,
        description=trigger.description,
        user_id=user.id,
        project_id=project.id,
        vars={'id': trigger.id},
    )
Exemplo n.º 13
0
Arquivo: node.py Projeto: keizo/kulu
 def POST(self, nid):
     page = self.page
     node = mod.node.load(nid)
     if node is None:
         pagenotfound()
     else:
         self._checkaccess(node)
         form = _form_node(node.type, page.user.roles.keys())
         
         if form.validates():
             data = form.d
             node.time_now = int(time.time())
             node.uid = page.user.uid
             node = web.storify(data, **node)
             
             # TODO: update all publishing options in 'node' table
             web.update('node', where='nid=$node.nid AND vid=$node.vid',
                 vid=(node.vid+1), vars=locals())
             # Do module specific updates.
             if hasattr(mod[node.type], 'node_update'):
                 mod[node.type].node_update(node)
                 
             web.redirect('/node/'+str(node.nid))
Exemplo n.º 14
0
 def persist(self, obj):
     
     if obj._pm_state_ in [ 'persisted', 'proxy' ]: return
     self._persist_one_relation(obj)
     
     _pm_var_ = {}
     #with web.transaction():
     if obj._pm_state_ == 'New':
         self._run_fixture(obj, 'save')
         for f in obj._pm_fields_:
             _pm_var_[f[0]] = getattr(obj, f[0])            
         del _pm_var_[obj._pm_id_column_]
         self.syslog.debug("insert:" + web.insert(obj._pm_db_table_, _test=True, **_pm_var_))
         new_id = web.insert(obj._pm_db_table_, **_pm_var_)
         setattr(obj, obj._pm_id_column_, new_id)
         obj._pm_updated_field_ = set()
         #??
         obj._pm_state_ = 'persisted'
         self._persist_list_relation(obj)
         
     elif obj._pm_updated_field_:
         self._run_fixture(obj, 'update')
         for f in obj._pm_updated_field_:
             _pm_var_[f] = getattr(obj, f)
             
         sql = web.update(obj._pm_db_table_,
                    where="%s = $id" % obj._pm_id_column_,
                    vars={'id':getattr(obj, obj._pm_id_column_)},
                    _test=True,
                    **_pm_var_)
         self.syslog.debug("update:" + sql)                      
         web.update(obj._pm_db_table_,
                    where="%s = $id" % obj._pm_id_column_,
                    vars={'id':getattr(obj, obj._pm_id_column_)},
                    **_pm_var_)
         
     obj._pm_state_ = 'persisted'
Exemplo n.º 15
0
Arquivo: mro.py Projeto: benhoyt/mro
    def update(self, key_name=None, _test=False):
        """ Update row (only changed fields). Primary key is used unless
            another key_name is specified.

            >>> u = UserTest(id=5)
            >>> u.username = '******'
            >>> print u.update(_test=True)
            UPDATE users SET username = '******' WHERE id = 5
        """
        changed = self._changed_values()
        if key_name is None:
            key_name = self._primary_key
        if key_name in changed:
            del changed[key_name]
        return web.update(self._table, where='%s = $key' % key_name, vars={'key': getattr(self, key_name)}, _test=_test, **changed)
Exemplo n.º 16
0
    def store(self, id_, client_ip, data, old_id=False):
        '''takes
            client_ip - client ip
            id_ - string
            data - Storage
            old_id - if the id regenerates after every request'''
        do_insert = True

        if not old_id:
            old_id = id_

        if len(list(web.select(web.config.handler_parameters.db_table,
                vars={'id': old_id},
                what='id',
                where='id = $id'))) == 1:
            do_insert = False

        web.transact()

        now = int(time.time())
        try:
            if do_insert:
                web.db.insert(web.config.handler_parameters.db_table,
                    seqname=False, id=id_, ip=client_ip, touched=now,
                    created=now, data=pickle.dumps(data, 0))
            else:
                web.update(web.config.handler_parameters.db_table,
                    where='id = $old_id',
                    vars={'old_id': old_id},
                    id=id_, ip=client_ip, touched=now,
                    data=pickle.dumps(data, 0))
            web.commit()

        except Exception, inst:
            web.rollback()
            raise inst
Exemplo n.º 17
0
Arquivo: util.py Projeto: keizo/kulu
 def __setitem__(self, key, value):
     if self.has_key(key):
         web.update(self.table,where=self.key_field+'=$key',vars=locals(),**{self.value_field:value})
     else:
         web.insert(self.table,**{self.key_field:key,self.value_field:value})
     dict.__setitem__(self,key,value)
Exemplo n.º 18
0
Arquivo: db.py Projeto: 10sr/jottit
def change_public_url(url):
    url = url.strip()
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', public_url=url, vars=locals())
    jt.site.public_url = url
    jt.site.url = utils.site_url(jt.site)
Exemplo n.º 19
0
Arquivo: db.py Projeto: 10sr/jottit
def change_pwd_token():
    d = auth.digest(auth.isodate()+jt.site.password)
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', change_pwd_token=d, vars=locals())
    return d
Exemplo n.º 20
0
Arquivo: db.py Projeto: 10sr/jottit
def recover_password(password):
    pwd_d = auth.digest(password)
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', change_pwd_token=None, password=pwd_d, vars=locals())
    jt.site.password = pwd_d
Exemplo n.º 21
0
Arquivo: db.py Projeto: 10sr/jottit
def undelete_page(page_id, name):
    # we also update the name in case the user
    # deletes "foo" and re-creates it as "Foo",
    web.update('pages', where='id=$page_id', deleted=False, name=name, vars=locals())
Exemplo n.º 22
0
def user_update(user):
    web.update("users", where='id=$id',
                credentials=user.password,
                vars=user.copy(),
    )
Exemplo n.º 23
0
 def POST(self, id):
     i = web.input()
     web.update("bookmarks", "id = " + id, title=i.title, url=i.url, tags=i.tags)
     web.seeother("../")
Exemplo n.º 24
0
def execution(result):
    # 获取起止日期
    result = result.split('~')
    date_begin = result[0]
    date_end = result[-1]
    date_end = datetime.datetime.strptime(date_end, "%Y-%m-%d")

    # 获取所有选中日期
    day_range = []
    date = datetime.datetime.strptime(date_begin, "%Y-%m-%d")
    while date <= date_end:
        day_range.append(date.strftime("%Y-%m-%d"))
        date = date + datetime.timedelta(days=1)
    # download the raw data
    date = datetime.datetime.strptime(date_begin, "%Y-%m-%d")
    web.update(date.strftime("%Y-%m-%d"))

    while (date + datetime.timedelta(days=7)) <= date_end:
        date = date + datetime.timedelta(days=7)
        web.update(date.strftime("%Y-%m-%d"))

    # 删除选中日期以外的文件
    path = '../Download/'
    word = 'BusLocation'
    Bus_dir = web.search_dir(path, word)
    for i in Bus_dir:
        web.del_file(i, day_range)
    word = 'Session'
    Session_dir = web.search_dir(path, word)
    for i in Session_dir:
        web.del_file(i, day_range)

    # service recognition
    word = 'BusLocation'
    Bus_dir = web.search_dir(path, word)
    for filedir_bus in Bus_dir:
        #### Modify folderpath ####
        aggregate.aggregate(filedir_bus)

    # ridership analysis
    database = "ridership"
    user = "******"
    password = "******"
    host = "localhost"
    port = "5432"
    ridership.ridership(database, user, password, host, port)

    # round trip time
    folderpath = '../output'
    database = "RTT"
    extractMobilityInfo.run_RTT(folderpath)
    upload.RTT_upload(database, user, password, host, port)

    # interarrival
    database = "inter_arrival"
    mobilityInterval.run_interarrival(folderpath)
    upload.inter_arrival_upload(database, user, password, host, port)

    web.clean()
    print('COMPLETED!')
    return
Exemplo n.º 25
0
Arquivo: db.py Projeto: 10sr/jottit
def claim_site(password, email, security):
    pwd_d = auth.digest(password)
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', password=pwd_d, email=email, security=security, vars=locals())
Exemplo n.º 26
0
Arquivo: db.py Projeto: 10sr/jottit
def update_design(title_font, subtitle_font, headings_font, content_font, header_color, title_color, subtitle_color, title_size, subtitle_size, headings_size, content_size, hue, brightness):
    epoch = int(time.time())
    site_id = jt.site.id
    design = get_design()
    web.update('designs', where='site_id=$site_id', title_font=title_font, subtitle_font=subtitle_font, headings_font=headings_font, content_font=content_font, header_color=header_color, title_color=title_color, subtitle_color=subtitle_color, title_size=title_size, subtitle_size=subtitle_size, headings_size=headings_size, content_size=content_size, hue=hue, brightness=brightness, vars=locals())
Exemplo n.º 27
0
Arquivo: db.py Projeto: 10sr/jottit
def hide_primer():
    site_id = jt.site.id
    web.update('sites', where="id=$site_id", show_primer="f", vars=locals())
Exemplo n.º 28
0
Arquivo: db.py Projeto: 10sr/jottit
def set_caret_pos(page_id, caret_pos, scroll_pos):
    scroll_pos, caret_pos = web.intget(scroll_pos, 0), web.intget(caret_pos, 0)
    web.update('pages', where='id=$page_id', caret_pos=caret_pos, scroll_pos=scroll_pos, vars=locals())
Exemplo n.º 29
0
        atm = sensor.get_atm()
        tmp = sensor.get_tmp()
        hum = sensor.get_hum()
        lux = sensor.get_lux()

        log.debug("atm:" + str(atm))
        log.debug("tmp:" + str(tmp))
        log.debug("hum:" + str(hum))
        log.debug("lux:" + str(lux))

        d = datetime.datetime.today()
        log.debug("today:%s" % (d))

        utc_now = datetime.datetime.utcnow()
        log.debug("utcnow:%s" % (utc_now))

        xively_test.set_time(utc_now)
        xively_test.set_value(atm, tmp, hum, lux)
        xively_test.update()

        web.set_time(utc_now)
        web.set_value(atm, tmp, hum, lux)
        web.update()
    else:
        log.error("sensor update fail")

    log.info("Finish main.py")


# end of main.py
Exemplo n.º 30
0
 def POST(self, id):
     i = web.input()
     web.update('bookmarks', 'id = '+id, title=i.title, url=i.url, tags=i.tags)
     web.seeother('../')
Exemplo n.º 31
0
Arquivo: db.py Projeto: 10sr/jottit
def delete_site():
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', deleted=True, public_url='', vars=locals())
Exemplo n.º 32
0
Arquivo: db.py Projeto: 10sr/jottit
def new_revision(page_id, revision, content, changes):
    trimmed = content.strip()
    revision_id = web.insert('revisions', revision=revision, ip=web.ctx.ip, page_id=page_id, content=content, changes=changes)
    created = web.select('revisions', where='id=$revision_id', vars=locals())[0].created
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', updated=created, vars=locals())
Exemplo n.º 33
0
Arquivo: db.py Projeto: 10sr/jottit
def delete_page(page_id):
    latest = get_revision(page_id)
    content = ''
    changes = '<em>Page deleted.</em>'
    new_revision(page_id, latest.revision+1, content, changes)
    web.update('pages', where='id=$page_id', deleted=True, vars=locals())
Exemplo n.º 34
0
def comment_order_update(comment):
    return web.update("notes", where='id=$id', 
                        ord=comment.ord,
                        vars={'id': comment.id,},
                        )
Exemplo n.º 35
0
Arquivo: db.py Projeto: 10sr/jottit
def new_draft(page_id, content):
    exists = web.select('drafts', where='page_id=$page_id', vars=locals())
    if exists:
        web.update('drafts', where='page_id=$page_id', content=content, vars=locals())
    else:
        web.insert('drafts', page_id=page_id, content=content)
Exemplo n.º 36
0
def update():
    sites = web.select('sites')
    for s in sites:
        id = s.id
        pwd_d = digest(s.password)
        web.update('sites', where='id=$id', password=pwd_d, vars=locals())
Exemplo n.º 37
0
Arquivo: db.py Projeto: 10sr/jottit
def update_site(title, subtitle, email, security):
    site_id = jt.site.id
    web.update('sites', where='id=$site_id', title=title, subtitle=subtitle, email=email,
            security=security, vars=locals())
    jt.site.update({'title': title, 'subtitle': subtitle, 'email': email, 'security': security})