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


Python Category.put方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
    def post(self):
        update = self.request.get('update', False)
        cate_name = self.request.get('cate_name')
        tags_list = self.request.get_all('tags_name', [])
        title = self.request.get('title')
        blog = self.request.get('blog')
        if not blog:
            self.response.write('blog content empty!')

        cate = Category.query(Category.title==cate_name).get()
        if not cate:
            cate = Category(title=cate_name)
            cate.put()
        print tags_list
        tags = Tag.query(Tag.title.IN(tags_list)).fetch()
        tags_old = [tag.title for tag in tags]
        tags_new = []
        for tag in tags_list:
            if tag not in tags_old:
                tag = Tag(title=tag)
                tag.put()
                tags_new.append(tag)
        print tags
        print tags_new
        tags += tags_new
        print tags
        print '==='
        print dir(tags[0])
        tags = [tag.key for tag in tags]

        blog = Blog(title=title, text=blog, category=cate.key, tags=tags)
        blog.put()
        self.response.write('blog publish success')
        self.response.set_status(200)
开发者ID:hackrole,项目名称:gblog,代码行数:36,代码来源:blog.py

示例2: testdb_init

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def testdb_init():
    # db clear
    t1 = Tag(title="emacs")
    t2 = Tag(title="python")
    t1.put()
    t2.put()

    c1 = Category(title='program')
    c2 = Category(title='edit')
    c1.put()
    c2.put()

    b1 = Blog(title='first blog')
    b1.context = "this is my first blog, hello world"
    b1.put()
    b2 = Blog(title="second blog")
    b2.context = "this is my second blog, hello python"
    b2.tags = [t1.key, t2.key]
    b2.put()
    b3 = Blog(title="third blog")
    b3.context = "this is my third blog, hello python"
    b3.tags = [t1.key,]
    b3.category = c2.key
    b3.put()
    b4 = Blog(title="fourth blog")
    b4.context = "this is my fourth blog, hello python"
    b4.tags = [t2.key,]
    b4.category = c1.key
    b4.put()
开发者ID:hackrole,项目名称:gblog,代码行数:31,代码来源:fts.py

示例3: index

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def index(request):

  params = {}
  if settings.SHOWPAGES:
    pages = Page.all()
    pages.order("-modified")
    posts = pages.fetch(settings.SHOWPAGES)
    params['posts'] = posts
    return respond(request, 'base.html', params)
  else:
    home_category = 'Main'
    home_page = 'Home'

    page = db.GqlQuery("SELECT * FROM Page WHERE name = :1", home_page).get()
    if page == None:
      if users.get_current_user():
        category = db.GqlQuery("SELECT * FROM Category WHERE name = :1", home_category).get()
        if category == None:
          category = Category(name=home_category, sequence=1)
          category.put()

        page = Page(name=home_page, category=home_category, sequence=1, content='<h1>Home Page</h1><h5>Change me!</h5>')
        page.put()
      else:
        return HttpResponseRedirect(users.create_login_url(request.get_full_path()))

    return viewPage(request, 'Main', 'Home')
开发者ID:hollerith,项目名称:schoogle,代码行数:29,代码来源:views.py

示例4: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
 def post(self, *args):
     c = Category(
         name=self.request.get('name'),
         link=self.request.get('link')
     )
     c.put()
     self.redirect('/admin')
开发者ID:yanzay,项目名称:pagankolo,代码行数:9,代码来源:main.py

示例5: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [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

示例6: add_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def add_category(request):
    if request.method == "POST":
        category = Category()
        category.name = request.POST["name"]
        category.slug = request.POST["slug"]
        category.put()
        return HttpResponseRedirect("/category/add")
    return render_to_response("add_category.html", context_instance=RequestContext(request))
开发者ID:ytrstu,项目名称:niubi,代码行数:10,代码来源:views.py

示例7: add_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def add_category(request):
    if request.method == 'POST':
        category = Category()
        category.name = request.POST['name']
        category.slug = request.POST['slug']
        category.put();   
        return HttpResponseRedirect('/category/add')  
    return render_to_response('add_category.html', context_instance=RequestContext(request))
开发者ID:lvbeck,项目名称:niubi,代码行数:10,代码来源:views.py

示例8: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
 def post(self):
     try:
         title = self.request.get('title')
         desc = self.request.get('desc')
     except:
         self.redirect('/categories')
     if title:
         c = Category(title=title, desc=desc)
         c.put()
     self.redirect('/categories')
开发者ID:e911miri,项目名称:adroid,代码行数:12,代码来源:main.py

示例9: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [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

示例10: new_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def new_category():
    form = CategoryForm()
    if form.validate_on_submit():
        category = Category(name=form.name.data)
        try:
            category.put()
            flash(u"Example %s successfully saved." % category.name, "success")
            return redirect(url_for("list_categories"))
        except CapabilityDisabledError:
            flash(u"App Engine Datastore is currently in read-only mode.", "info")
            return redirect(url_for("list_categories"))
    return render_template("new_category.html", form=form)
开发者ID:cenzino,项目名称:vp-gae,代码行数:14,代码来源:views.py

示例11: save_new_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
def save_new_category():
    category = request.form.get("category")
    existing = Category.all().filter("owner =", users.get_current_user())
    for e in existing:
        if e.title.lower() == category.lower():
            return Response(status=400)
    else:
        items = request.form.get("items").split(",")
        cat = Category(title=category, owner=users.get_current_user())
        cat.put()
        for i in items:
            if not i == "":
                item = Item(parent=cat.key(), title=i)
                item.put()
        return Response(status=200)
开发者ID:ssb402,项目名称:Vote-or-Skip-Web-App,代码行数:17,代码来源:views.py

示例12: setUp

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        tag1 = Tag(title='emacs')
        tag2 = Tag(title='vim')
        tag1.put()
        tag2.put()
        cate = Category(title='emacs笔记')
        cate.put()
        b1 = Blog(title="the first emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b2 = Blog(title="the second emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b3 = Blog(title="the third emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b1.put()
        b2.put()
        b3.put()
开发者ID:hackrole,项目名称:gblog,代码行数:23,代码来源:tests.py

示例13: putMenu

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
    def putMenu(self, date, periodId):
        """ date format: XXXX-XX-XX, peroid: 481,482,483 for breakfast, lunch and dinner, 1778 and 1779 for other two """
        values = {}
        values['LocationId'] = "1965"  # fixed for ARA
        values['PeriodId'] = periodId  # 481,482,483 for breakfast, lunch and dinner, 1778 and 1779 for other two
        values['MenuDate'] = date
        values['UIBuildDateForm'] = date
        data = urllib.urlencode(values)
        url = "http://rose-hulman.campusdish.com/Commerce/Catalog/Menus.aspx"
        geturl = url + "?" + data
        print geturl
        request = urllib2.Request(geturl)
        response = urllib2.urlopen(request)
        soup = BeautifulSoup(response.read())
        blocks = soup.find_all('div', class_='menu-details-station')

        if periodId == 481:
            pName = "Breakfast"
        elif periodId == 482:
            pName = "Lunch"
        elif periodId == 483:
            pName = "Dinner"
        elif periodId == 1778:
            pName = "Con't Breakfast"
        elif periodId == 1779:
            pName = "Soup & Salad"

        period = Period(selectDate=date,
                        name=pName)
        period.put()
        for block in blocks:
            # print block.h2.string, "------"
            category = Category(parent=period.entityKey,
                                name=block.h2.string)
            category.put()
            for item in block.find_all('div', class_='menu-name'):
                # print "     ", item.a.string
                dish = Dish(parent=category.entityKey,
                            name=item.a.string)
                dish.put()
开发者ID:FFyuan,项目名称:aramark-helper-menu-fetcher,代码行数:42,代码来源:main.py

示例14: post

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
    def post(self):
        upload_files = self.get_uploads()  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        #self.redirect('/serve/%s' % blob_info.key())
        blob_key = blob_info.key()
        blob_reader = blobstore.BlobReader(blob_key)
        document = blob_reader.read()
        #self.response.out.write(document)
        dom = xml.dom.minidom.parseString(document)
        names = dom.getElementsByTagName("NAME")

        xml_cat_name = names[0].toxml() 
        xml_cat_name = xml_cat_name.replace("<NAME>", "")
        xml_cat_name = xml_cat_name.replace("</NAME>", "")

        xml_item_names = []
        for i in range(1, len(names)):
            name = names[i].toxml()
            name = name.replace("<NAME>", "")
            name = name.replace("</NAME>", "")
            xml_item_names.append(name)

        currt_user = users.get_current_user()
        account_key = db.Key.from_path('Account', currt_user.nickname())
        account = db.get(account_key)
        categories = Category.all()
        categories.ancestor(account_key)

        cat_names = []
        for category in categories.run():
            cat_names.append(category.cat_name)


        ### if category exists
        if xml_cat_name in cat_names:
            items = Item.all()
            category = categories.filter("cat_name =", xml_cat_name)
            category = category.get()
            category_key = category.key()
            
            items = items.ancestor(category_key)
            item_names = []
            for item in items:
                item_names.append(item.item_name)

            ### add new items
            for item_name in xml_item_names:
                if item_name not in item_names:
                    item = Item(key_name=item_name, parent=category, item_name=item_name)
                    item.win = 0
                    item.lose = 0
                    item.put()

            ### delete old items
            for item_name in item_names:
                if item_name not in xml_item_names:
                    items = Item.all()
                    items = items.ancestor(category_key)
                    items.filter("item_name =", item_name)
                    item = items.get()
                    item.delete()

        ### if new category
        else:
            cat = Category(key_name=xml_cat_name, parent=account, cat_name=xml_cat_name)
            cat.put()
            for xml_item_name in xml_item_names:
                item = Item(key_name=xml_item_name, parent=cat, item_name=xml_item_name)
                item.win = 0
                item.lose = 0
                item.put()


        self.redirect("/option?option=manage")
开发者ID:xz565,项目名称:vote-item,代码行数:76,代码来源:main.py

示例15: add_category

# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import put [as 别名]
 def add_category(self, new_cat, account):
     cat = Category(key_name=new_cat, parent=account, cat_name=new_cat)
     cat.put()
开发者ID:xz565,项目名称:vote-item,代码行数:5,代码来源:manage_handler.py


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