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


Python Category.user方法代码示例

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


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

示例1: post

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

示例2: post

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

示例3: add_category

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

    if request.is_ajax():
        name = request.POST['name'].strip()
        description = request.POST['description']
        shared = request.POST['shared']

        if shared == "false":
            shared = False
        else:
            shared = True

        category = Category(user=request.user, name=name, description=description, shared=shared)

        # Saves it
        category.save()

        id = category.id

        category_url = Category.objects.get(id=id).slug

        return JsonResponse({"response":"Success", "category": category_url, "category_id": id })


    if request.method == "POST":
        category_data = request.POST
        category_data['name'] = category_data['name'].strip()
        if category_data['name'] == "":
            return render(request, "fhs/add_category.html", {"invalid": True})

        category_form = CategoryForm(data=category_data)
        if category_form.is_valid():
            try:
                category = category_form.save(commit=False)
                category.user = request.user
                category.save()

                return HttpResponseRedirect('/fhs/profile/'+request.user.username)
            except:
                return render(request, "fhs/add_category.html", {"existent": True})
        else:
            return render(request, "fhs/add_category.html", {"existent": True})

    return render(request, "fhs/add_category.html", {})
开发者ID:georgikoyrushki95,项目名称:ehealth_backup-backup_fhs-,代码行数:46,代码来源:views.py


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