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


Python User.sql_load_by_username方法代码示例

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


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

示例1: create_thread

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def create_thread( self, user_id ):
    """
    Create a new forum thread with a blank post, and give the thread a default name. Then redirect
    to that new thread.

    @type user_id: unicode or NoneType
    @param user_id: id of current logged-in user (if any)
    @rtype dict
    @return { 'redirect': new_notebook_url }
    @raise Access_error: the current user doesn't have access to create a post
    @raise Validation_error: one of the arguments is invalid
    """
    if user_id is None:
      raise Access_error()

    user = self.__database.load( User, user_id )
    if user is None or not user.username or user.username == "anonymous":
      raise Access_error()

    anonymous = self.__database.select_one( User, User.sql_load_by_username( u"anonymous" ), use_cache = True )
    if anonymous is None:
      raise Access_error()

    # for now, crappy hard-coding to prevent just anyone from creating a blog thread
    if self.__name == u"blog" and user.username != u"witten":
      raise Access_error()

    # create the new notebook thread
    thread_id = self.__database.next_id( Notebook, commit = False )
    thread = Notebook.create( thread_id, self.DEFAULT_THREAD_NAME, user_id = user.object_id )
    self.__database.save( thread, commit = False )

    # associate the forum tag with the new notebook thread
    tag = self.__database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )
    self.__database.execute(
      anonymous.sql_save_notebook_tag( thread_id, tag.object_id, value = self.__name ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.__database.execute(
      anonymous.sql_save_notebook( thread_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )

    # create a blank post in which the user can  start off the thread
    note_id = self.__database.next_id( Notebook, commit = False )
    note = Note.create( note_id, u"<h3>", notebook_id = thread_id, startup = True, rank = 0, user_id = user_id )
    self.__database.save( note, commit = False )

    self.__database.commit()

    if self.__name == "blog":
      return dict(
        redirect = u"/blog/%s" % thread_id,
      )

    return dict(
      redirect = u"/forums/%s/%s" % ( self.__name, thread_id ),
    )
开发者ID:osborne6,项目名称:luminotes,代码行数:62,代码来源:Forums.py

示例2: index

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def index( self, start = 0, count = 50, note_id = None, user_id = None ):
    """
    Provide the information necessary to display the current threads within a forum.

    @type start: integer or NoneType
    @param start: index of first forum thread to display (optional, defaults to 0)
    @type count: integer or NoneType
    @param count: how many forum threads to display (optional, defaults to quite a few)
    @type note_id: unicode or NoneType
    @param note_id: id of thread to redirect to (optional, legacy support for old URLs)
    @type user_id: unicode or NoneType
    @param user_id: id of the current user
    @rtype: unicode
    @return: rendered HTML page
    """
    if note_id:
      return dict( redirect = os.path.join( cherrypy.request.path, note_id ) )

    result = self.__users.current( user_id )
    parents = [ notebook for notebook in result[ u"notebooks" ] if notebook.trash_id and not notebook.deleted ]
    if len( parents ) > 0:
      result[ "first_notebook" ] = parents[ 0 ]
    else:
      result[ "first_notebook" ] = None

    anonymous = self.__database.select_one( User, User.sql_load_by_username( u"anonymous" ), use_cache = True )
    if anonymous is None:
      raise Access_error()

    # load a slice of the list of the threads in this forum, excluding those with a default name
    threads = self.__database.select_many(
      Notebook,
      anonymous.sql_load_notebooks(
        parents_only = False, undeleted_only = True, tag_name = u"forum", tag_value = self.__name,
        exclude_notebook_name = self.DEFAULT_THREAD_NAME, reverse = True,
        start = start, count = count,
      )
    )

    # if there are no matching threads, then this forum doesn't exist
    if len( threads ) == 0:
      raise cherrypy.NotFound

    # count the total number of threads in this forum, excluding those with a default name
    total_thread_count = self.__database.select_one(
      int,
      anonymous.sql_count_notebooks(
        parents_only = False, undeleted_only = True, tag_name = u"forum", tag_value = self.__name,
        exclude_notebook_name = self.DEFAULT_THREAD_NAME,
      )
    )

    result[ "forum_name" ] = self.__name
    result[ "threads" ] = threads
    result[ "start" ] = start
    result[ "count" ] = count
    result[ "total_thread_count" ] = total_thread_count
    return result
开发者ID:osborne6,项目名称:luminotes,代码行数:60,代码来源:Forums.py

示例3: make_thread

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def make_thread( self ):
    title = u"Welcome to the Luminotes %s forum!" % self.forum_name

    # create a notebook thread to go in the forum
    notebook_id = self.database.next_id( Notebook, commit = False )
    thread_notebook = Notebook.create(
      notebook_id,
      title,
    )
    self.database.save( thread_notebook, commit = False )

    anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )

    # add a single welcome note to the new thread
    note_id = self.database.next_id( Note, commit = False )
    note = Note.create(
      note_id,
      u"""
      <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion
      forum, so please keep that in mind when posting. And have fun.
      """ % ( title, self.forum_name ),
      notebook_id,
      startup = True,
      rank = 0,
      user_id = anonymous.object_id,
      creation = datetime.now(),
    )
    self.database.save( note, commit = False )

    # load the forum tag, or create one if it doesn't exist
    tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )
    if not tag:
      tag_id = self.database.next_id( Tag, commit = False )
      tag = Tag.create(
        tag_id,
        notebook_id = None, # this tag is not in the namespace of a single notebook
        user_id = anonymous.object_id,
        name = u"forum",
        description = u"discussion forum threads"
      )
      self.database.save( tag, commit = False )

    # associate the forum tag with the previously created notebook thread, and set that
    # association's value to forum_name
    self.database.execute(
      anonymous.sql_save_notebook_tag( notebook_id, tag.object_id, value = self.forum_name ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.database.execute(
      anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )
开发者ID:osborne6,项目名称:luminotes,代码行数:56,代码来源:make_forum_thread.py

示例4: default

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def default( self, note_title, invite_id = None, after_login = None, plan = None, yearly = False, user_id = None ):
    """
    Convenience method for accessing a note in the main notebook by name rather than by note id.

    @type note_title: unicode
    @param note_title: title of the note to return
    @type invite_id: unicode
    @param invite_id: id of the invite used to get to this note (optional)
    @type after_login: unicode
    @param after_login: URL to redirect to after login (optional, must start with "/")
    @type plan: int
    @param plan: rate plan index (optional, defaults to None)
    @type yearly: bool
    @param yearly: True for yearly plan, False for monthly (optional, defaults to False)
    @rtype: unicode
    @return: rendered HTML page
    """
    # if the user is logged in and not using https, and they request the sign up or login note, then
    # redirect to the https version of the page (if available)
    https_url = self.__settings[u"luminotes.https_url"]
    https_proxy_ip = self.__settings[u"luminotes.https_proxy_ip"]
    
    if note_title in ( u"sign_up", u"login" ) and https_url and cherrypy.request.remote_addr != https_proxy_ip:
      if invite_id:
        return dict( redirect = u"%s/%s?invite_id=%s" % ( https_url, note_title, invite_id ) )
      if after_login:
        return dict( redirect = u"%s/%s?after_login=%s" % ( https_url, note_title, after_login ) )
      if plan:
        return dict( redirect = u"%s/%s?plan=%s&yearly=%s" % ( https_url, note_title, plan, yearly ) )
      else:
        return dict( redirect = u"%s/%s" % ( https_url, note_title ) )

    anonymous = self.__database.select_one( User, User.sql_load_by_username( u"anonymous" ) )
    if anonymous:
      main_notebook = self.__database.select_one( Notebook, anonymous.sql_load_notebooks( undeleted_only = True ) )

    result = self.__users.current( user_id = user_id )

    note_title = note_title.replace( u"_", " " )
    note = self.__database.select_one( Note, main_notebook.sql_load_note_by_title( note_title ) )
    if not note:
      raise cherrypy.NotFound

    result.update( self.__notebooks.contents( main_notebook.object_id, user_id = user_id, note_id = note.object_id ) )
    if invite_id:
      result[ "invite_id" ] = invite_id
    if after_login and after_login.startswith( u"/" ):
      result[ "after_login" ] = after_login
    if plan:
      result[ "signup_plan" ] = plan
      result[ "signup_yearly" ] = yearly

    return result
开发者ID:osborne6,项目名称:luminotes,代码行数:55,代码来源:Root.py

示例5: convert_post

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def convert_post( self, note ):
    # create a notebook thread to go in the forum
    notebook_id = self.database.next_id( Notebook, commit = False )
    thread_notebook = Notebook.create(
      notebook_id,
      note.title,
    )
    self.database.save( thread_notebook, commit = False )

    anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )

    # move the given note into the newly created notebook thread
    note.notebook_id = notebook_id
    note.startup = True
    note.rank = 0
    self.database.save( note, commit = False )

    # load the forum tag
    forum_tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )

    # associate the forum tag with the previously created notebook thread, and set that
    # association's value to the forum name
    self.database.execute(
      anonymous.sql_save_notebook_tag( notebook_id, forum_tag.object_id, value = u"blog" ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.database.execute(
      anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )

    blog_user = self.database.select_one( User, User.sql_load_by_username( self.blog_username ) )

    self.database.execute(
      blog_user.sql_save_notebook( notebook_id, read_write = True, owner = True ),
      commit = False,
    )
开发者ID:osborne6,项目名称:luminotes,代码行数:41,代码来源:convert_blog_to_forum.py

示例6: index

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def index( self, user_id ):
    """
    Provide the information necessary to display the web site's front page, potentially performing
    a redirect to the https version of the page or the user's first notebook.
    """
    https_url = self.__settings[u"luminotes.https_url"]
    https_proxy_ip = self.__settings[u"luminotes.https_proxy_ip"]

    # if the server is configured to auto-login a particular user, log that user in and redirect to
    # their first notebook
    auto_login_username = self.__settings[u"luminotes.auto_login_username"]
    if auto_login_username:
      user = self.__database.select_one( User, User.sql_load_by_username( auto_login_username ), use_cache = True )

      if user and user.username:
        first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
        if first_notebook:
          return dict(
            redirect = u"/notebooks/%s" % first_notebook.object_id,
            authenticated = user,
          )

    # if the user is logged in and the HTTP request has no referrer, then redirect to the user's
    # first notebook
    if user_id:
      referer = cherrypy.request.headerMap.get( u"Referer" )
      if not referer:
        user = self.__database.load( User, user_id )

        if user and user.username:
          first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
          if first_notebook:
            return dict( redirect = u"%s/notebooks/%s" % ( https_url, first_notebook.object_id ) )
      
      # if the user is logged in and not using https, then redirect to the https version of the page (if available)
      if https_url and cherrypy.request.remote_addr != https_proxy_ip:
        return dict( redirect = u"%s/" % https_url )

    result = self.__users.current( user_id )
    parents = [ notebook for notebook in result[ u"notebooks" ] if notebook.trash_id and not notebook.deleted ]
    if len( parents ) > 0:
      result[ "first_notebook" ] = parents[ 0 ]
    else:
      result[ "first_notebook" ] = None

    return result
开发者ID:osborne6,项目名称:luminotes,代码行数:48,代码来源:Root.py

示例7: load_original_blog_notebook

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
  def load_original_blog_notebook( self ):
    anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )

    from controller.Users import Users
    users = Users(
      self.database,
      self.settings[ u"global" ].get( u"luminotes.http_url", u"" ),
      self.settings[ u"global" ].get( u"luminotes.https_url", u"" ),
      self.settings[ u"global" ].get( u"luminotes.support_email", u"" ),
      self.settings[ u"global" ].get( u"luminotes.payment_email", u"" ),
      self.settings[ u"global" ].get( u"luminotes.rate_plans", [] ),
      self.settings[ u"global" ].get( u"luminotes.download_products", [] ),
    )

    result = users.current( anonymous.object_id ) 
    blog_notebooks = [ nb for nb in result[ "notebooks" ] if nb.name == u"Luminotes blog" ]

    return blog_notebooks[ 0 ]
开发者ID:osborne6,项目名称:luminotes,代码行数:20,代码来源:convert_blog_to_forum.py

示例8: update_main_notebook

# 需要导入模块: from model.User import User [as 别名]
# 或者: from model.User.User import sql_load_by_username [as 别名]
    def update_main_notebook(self):
        anonymous = self.database.select_one(User, User.sql_load_by_username(u"anonymous"))
        main_notebook = self.database.select_one(Notebook, anonymous.sql_load_notebooks())

        # get the id for each note
        note_ids = {}
        for (filename, startup) in self.NOTE_FILES:
            title = filename.replace(u".html", u"")
            note = self.database.select_one(Note, main_notebook.sql_load_note_by_title(title))

            if note is not None:
                note_ids[filename] = note.object_id

        # update all of the notes in the main notebook
        for (filename, startup) in self.NOTE_FILES:
            title = filename.replace(u".html", u"")
            note = self.database.select_one(Note, main_notebook.sql_load_note_by_title(title))
            self.update_note(filename, startup, main_notebook, note_ids, note)

        if main_notebook.name != u"Luminotes":
            main_notebook.name = u"Luminotes"
            self.database.save(main_notebook, commit=False)
开发者ID:vijo,项目名称:luminotes,代码行数:24,代码来源:updatedb.py


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