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


Python Category.all方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
 def post(self):
     user = users.get_current_user()
     
     if user == None:
         self.redirect("/")
         return 
     
     # get category information
     category = self.request.get('category') 
     item = self.request.get('newItem')
     if item != "":
         cs = Category.all()
         cs.filter('user =', user.email()) # get user category
         cs.filter('category =', category) # get category
         c = cs.get()
         if c != None:
             items = Item.all()
             items.filter('item =', item)
             items.ancestor(c.key())
             if items.get() == None:
                 newItem = Item(item = item, win = 0, lose = 0, rate = 0, parent = c.key()) # post a new item
                 newItem.put() # save 
             else:
                 errorMessage = "Item %s already exists!" % item
                 self.redirect("/manageCategory?category=%s&error=%s" % (category, errorMessage))
                 return 
     
     self.redirect("/manageCategory?category=%s" % category)
开发者ID:freedomd,项目名称:Head2Head,代码行数:30,代码来源:item.py

示例2: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def post(self):
        user = users.get_current_user()
        
        if user == None:
            self.redirect("/")
            return 
        
        # get category information
        category = self.request.get('newCategory') 
        if category != "":
            # check if exists
            c = Category.all()
            c.filter('user =', user.email()) # get user category
            c.filter('category =', category) # check
            if c.get() == None:# does not exist
                newCat = Category() # post a new category
                newCat.category = category
                newCat.user = user.email()
                newCat.username = user.nickname()
                newCat.put() # save 
            else:
                errorMessage = "Category %s already exists!" % category
                self.redirect("/category?error=%s" % errorMessage)
                return 

        self.redirect("/category")
开发者ID:freedomd,项目名称:Head2Head,代码行数:28,代码来源:category.py

示例3: get

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def get(self):  
        user = users.get_current_user()
        
        if user:
            login = True
            url = users.create_logout_url(self.request.uri)
        else:
            login = False
            url = users.create_login_url(self.request.uri)
            self.redirect("/")
            return 
        
        creator = self.request.get('creator')
        category = self.request.get('category') 
        cats = Category.all()
        cats.filter('user =', creator) # get user category
        cats.filter('category =', category) # get category
        c = cats.get()
        
        if c == None:
            self.redirect("/")
            return
        
        items = Item.all()
        items.ancestor(c.key()) # get all the items of c
        itemList = []
        for item in items.run():
            itemList.append(item.item)
        
        if len(itemList) > 1:
            length = len(itemList)
            i = random.randint(0, length - 1)
            j = random.randint(0, length - 1)
            while i == j:
                j = random.randint(0, length - 1)

            choice1 = itemList[i]
            choice2 = itemList[j]
            error = None
        else:
            choice1 = None
            choice2 = None
            error = "Options not enough!"
        
        template_values = {
            'user': user,
            'login': login, 
            'url': url,
            'winner': None,
            'loser': None,
            'choice1': choice1, 
            'choice2': choice2,
            'creator': creator,
            'creatorName': c.username,
            'category': category,
            'error': error
        }
        
        path = os.path.join(os.path.dirname(__file__), 'templates/vote.html')
        self.response.out.write(template.render(path, template_values))
开发者ID:freedomd,项目名称:Head2Head,代码行数:62,代码来源:vote.py

示例4: get

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
 def get(self):  
     user = users.get_current_user()
     
     if user:
         login = True
         url = users.create_logout_url(self.request.uri)
     else:
         login = False
         url = users.create_login_url(self.request.uri)
         self.redirect("/")
         return 
     
     userCats = Category.all()
     userCats.filter('user =', user.email()) # get user category
     isEmpty = userCats.get()
     #print userCats.count(self)"
     
     
     template_values = {
         'user': user,
         'userCats': userCats,
         'login': login, 
         'url': url,
         'isEmpty': isEmpty,
         'error': self.request.get('error'),
         'message': self.request.get('message'),
         'importMessage': self.request.get('importMessage')
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/category.html')
     self.response.out.write(template.render(path, template_values))
开发者ID:freedomd,项目名称:Head2Head,代码行数:33,代码来源:category.py

示例5: __init__

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
 def __init__(self, user, type, *args, **kwargs):
     super(CategoryForm, self).__init__(*args, **kwargs)
     self.fields['parent_category'].query = Category.all()\
         .filter('user =', user)\
         .filter('type =', type)\
         .filter('parent_category =', None)\
         .order('name')
开发者ID:jbochi,项目名称:depoisdavirgula,代码行数:9,代码来源:forms.py

示例6: __init__

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def __init__(self, table_p, parent, product=None, *args, **kwargs):
        QDialog.__init__(self, parent, *args, **kwargs)

        self.table_p = table_p
        self.prod = product
        self.parent = parent
        self.filename = "Parcourire ..."
        self.path_filename = None

        if self.prod:
            self.title = u"Modification de l'article {}".format(self.prod.name)
            self.succes_msg = u"L'article <b>%s</b> a été mise à jour" % self.prod.name
            try:
                self.filename = self.prod.file_join.file_name
            except:
                pass
        else:
            self.succes_msg = u"L'article a été bien enregistré"
            self.title = u"Ajout de nouvel article"
            self.prod = Product()

        self.setWindowTitle(self.title)

        # self.code = LineEdit(self.prod.code)
        self.name_field = LineEdit(self.prod.name)
        try:
            self.category_name = Category.select().where(
                Category.name == self.prod.category.name).get().name
        except:
            self.category_name = ""
        self.category_field = LineEdit(self.category_name)

        self.number_parts_box_field = IntLineEdit(
            str(self.prod.number_parts_box))
        self.number_parts_box_field.setValidator(QIntValidator())

        completion_values = [catg.name for catg in Category.all()]
        completer = QCompleter(completion_values, parent=self)
        completer.setCaseSensitivity(Qt.CaseInsensitive)
        completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
        self.category_field.setCompleter(completer)

        vbox = QVBoxLayout()
        formbox = QFormLayout()
        formbox.addRow(FLabel(u"Nom"), self.name_field)
        formbox.addRow(FLabel(u"Categorie"), self.category_field)
        # formbox.addRow(
        #     FLabel(u"Quantité (carton)"), self.number_parts_box_field)
        self.butt_parco = QPushButton(
            QIcon.fromTheme('document-open', QIcon('')), self.filename)
        self.butt_parco.clicked.connect(self.import_image)
        butt_cancel = Warning_btt(u"Annuler")
        butt_cancel.clicked.connect(self.cancel)
        # formbox.addRow(FLabel(u"Image"), self.butt_parco)
        butt = Button_save(u"&Enregistrer")
        butt.clicked.connect(self.add_or_edit_prod)
        formbox.addRow(butt_cancel, butt)

        vbox.addLayout(formbox)
        self.setLayout(vbox)
开发者ID:Ciwara,项目名称:gcommon,代码行数:62,代码来源:product_edit_or_add.py

示例7: save_edited_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
def save_edited_category():
    cat_name = request.form.get("category")
    key = request.form.get("key")
    existing = Category.all().filter("owner =", users.get_current_user())
    for e in existing:
        if e.title.lower() == cat_name.lower():
            if not str(e.key()) == key:
                error = "You already have a category with that name. Please choose a different name"
                return Response(status=400)
    category = Category.get(key)
    items_from_form = request.form.get("items").split(",")
    old_items_from_db = Item.all().ancestor(category)
    for item in old_items_from_db:
        if not item.title in items_from_form:
            db.delete(item)
        else:
            items_from_form.remove(item.title)

    for new_item in items_from_form:
        if not new_item == "":
            i = Item(parent=category, title=new_item)
            i.put()
    category.title = request.form.get("category")
    category.put()
    return jsonify(new_items=items_from_form)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:27,代码来源:views.py

示例8: get

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
 def get(self,name):
     cat = Category.all().filter('link = ',name).get()
     posts = BlogPost.all().filter('category = ',cat.key()).order('-pub_date')
     templ_val = {
         'posts': posts,
         'active_blogs':True
     }
     self.render_to_response('index.html',templ_val)
开发者ID:yanzay,项目名称:pagankolo,代码行数:10,代码来源:main.py

示例9: choose_category_page

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def choose_category_page(self, account):
        account_key = db.Key.from_path("Account", account)
        categories = Category.all()
        categories.ancestor(account_key)

        template_values = {"account": account, "categories": categories, "logout_url": users.create_logout_url("/")}
        path = os.path.join(os.path.dirname(__file__), "choose_category.html")
        self.response.out.write(template.render(path, template_values))
开发者ID:xz565,项目名称:vote-item,代码行数:10,代码来源:vote_handler.py

示例10: index

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
def index():
    if not users.get_current_user():
        loginout = users.create_login_url("/")
        link = "Login"
    else:
        loginout = users.create_logout_url("/")
        link = "Logout"
    categories = Category.all()
    return render_template("index.html", categories=categories, loginout=loginout, link=link)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:11,代码来源:views.py

示例11: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def post(self):  
        user = users.get_current_user()
        
        if user == None:
            self.redirect("/")
            return 

        content = self.request.get('content')
        if content == None or content == "":
            self.redirect("/category")
            return 
        xmldoc = minidom.parseString(content)
        category = xmldoc.getElementsByTagName('CATEGORY')[0]
        categoryName = category.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
        itemList = category.getElementsByTagName('ITEM')
        
        cats = Category.all()
        cats.filter("category =", str(categoryName))
        c = cats.get()
        
        if c == None: # category not exist
            newCat = Category() # create a new category
            newCat.category = categoryName
            newCat.user = user.email()
            newCat.username = user.nickname()
            newCat.put() # save
            for item in itemList:
                itemName = item.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
                newItem = Item(item = itemName, win = 0, lose = 0, rate = 0, parent = newCat.key())
                newItem.put()
            importMessage = 'Import new category "%s" successfully.' % categoryName
            self.redirect("/category?importMessage=%s" % importMessage)
        else: # category exists
            items = Item.all()
            items.ancestor(c.key())
            
            oldItemNameList = []
            for item in items.run():
                oldItemNameList.append(item.item)
            
            newItemNameList = []
            for item in itemList:
                itemName = item.getElementsByTagName('NAME')[0].childNodes[0].nodeValue
                newItemNameList.append(itemName)
                if itemName not in oldItemNameList: # new item not exist
                    newItem = Item(item = itemName, win = 0, lose = 0, rate = 0, parent = c.key())
                    newItem.put()
            
            for item in items: # get old items
                if item.item not in newItemNameList: # old item not in new list, delete
                    item.delete()
                    
            importMessage = 'Import existed category "%s" successfully.' % categoryName
            self.redirect("/category?importMessage=%s" % importMessage)
开发者ID:freedomd,项目名称:Head2Head,代码行数:56,代码来源:xmlHandler.py

示例12: respond

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
def respond(request, template, params=None):
  
  if params is None:
    params = {}

  if request.LANGUAGE_CODE != 'en':
    params['is_foreign'] = request.LANGUAGE_CODE

  if not template.endswith('.html'):
    template += '.html'

  params['skin'] = settings.SKIN
  params['app_id'] = settings.APP_ID

  session_token = None
  user = users.get_current_user()  
  if user:
    params['user'] = user
    params['author'] = db.Query(Author).filter('email = ', user.email()).get()
    if users.IsCurrentUserAdmin():
      params['authsub_url'], session_token, client = check_auth(request, user)
    params['is_admin'] = True # users.IsCurrentUserAdmin() # global
    params['developer'] = ('Dev' in os.getenv('SERVER_SOFTWARE'))
    params['sign_out'] = users.CreateLogoutURL('/')
  else:
    params['sign_in'] = users.CreateLoginURL(request.path)

  params['session_token'] = session_token

  # Events
  startTime = datetime.datetime.now() + datetime.timedelta(weeks=-2)
  endTime = datetime.datetime.now() + datetime.timedelta(weeks=2)

  urlparams = 'start-min=%s&start-max=%s' % (startTime.strftime("%Y-%m-%dT%H:%M:%S"), endTime.strftime("%Y-%m-%dT%H:%M:%S"))
  url = 'http://www.google.com/calendar/feeds/%s/public/basic?' % settings.GOOGLE_ACCOUNT
  url = url + urlparams  
  
  feed = urlfetch.fetch(url)
  calendar = feedparser.parse(feed.content)
  events = calendar['entries']
  params['events'] = events

  # sidebar categories & page links
  categories = Category.all()
  categories.order("sequence")
  params['categories'] = categories

  pages = Page.all()
  pages.order("sequence")
  params['pages'] = pages

  return shortcuts.render_to_response(template, params)
开发者ID:hollerith,项目名称:schoogle,代码行数:54,代码来源:views.py

示例13: manage_page

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
    def manage_page(self, account_key):
        categories = Category.all()
        categories.ancestor(account_key)

        items = Item.all()

        template_values = {
            'categories': categories,
            'items': items,
            'logout_url': users.create_logout_url("/")
        }
        path = os.path.join(os.path.dirname(__file__), 'manage.html')
        self.response.out.write(template.render(path, template_values))
开发者ID:xz565,项目名称:vote-item,代码行数:15,代码来源:manage_handler.py

示例14: sitemap

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
def sitemap(request):
    str = """<?xml version="1.0" encoding="UTF-8"?>
            <?xml-stylesheet type="text/xsl" href="/static/xsl/sitemap.xsl"?>
            <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
               <url>
                  <loc>http://www.niubi.de/</loc>
                  <changefreq>weekly</changefreq>
                  <priority>0.9</priority>
               </url>
        """
    posts = Post.all().filter("is_published", True)
    for post in posts:
        str += (
            """<url>
                      <loc>http://www.niubi.de/post/%s/</loc>
                      <changefreq>weekly</changefreq>
                      <priority>0.8</priority>
                   </url>
                """
            % post.key().id()
        )

    categories = Category.all().order("-post_count")
    for category in categories:
        str += (
            """<url>
                      <loc>http://www.niubi.de/category/%s/</loc>
                      <changefreq>monthly</changefreq>
                      <priority>0.8</priority>
                   </url>
                """
            % category.key().id()
        )
    tags = Tag.all().order("-post_count")
    for tag in tags:
        str += (
            """<url>
                      <loc>http://www.niubi.de/tag/%s/</loc>
                      <changefreq>weekly</changefreq>
                      <priority>0.8</priority>
                   </url>
                """
            % tag.name
        )
    str += """<url>
                  <loc>http://www.niubi.de/about/</loc>
                  <changefreq>yearly</changefreq>
                  <priority>0.8</priority>
               </url>"""
    str += "</urlset>"
    return HttpResponse(str, content_type="text/xml")
开发者ID:ytrstu,项目名称:niubi,代码行数:53,代码来源:views.py

示例15: validate_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import all [as 别名]
def validate_category(handler, category_code, kind):
    logging.getLogger().setLevel(logging.DEBUG)
    query = None
    if kind is None:
        query = Category.all()
    elif kind == "forum":
        query = ForumCategory.all()
    if query is not None:
        query.filter('code =', category_code)
        result = query.get()
        if result:
            return result        
    logging.error("Category is not found. Requested category code: " + category_code)
    handler.error(500)
开发者ID:adamantium,项目名称:hic,代码行数:16,代码来源:shortcuts.py


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