• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Category类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

    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,代码行数:60,代码来源:product_edit_or_add.py


示例2: post

 def post(self, subdomain):
     namespace_manager.set_namespace(subdomain)
     visible = False
     if self.request.get('visible') == 'yes':
         visible = True
     name = self.request.get('name')
     categories = self.request.get('category').split(',')
     logging.info(categories)
     cat_refs = []
     for category in categories:
         logging.info(category)
         if Category.get_by_key_name(category):
             cat_refs.append(Category.get_by_key_name(category).key())
     logging.info(cat_refs)
     entity = Product(key_name=name,
                       name=name,
                       shop_id=Shop.get_by_key_name(subdomain),
                       stock=int(self.request.get('qty')),
                       description=self.request.get('description'),
                       price=float(self.request.get('price')),
                       tags=self.request.get('tags').split(','),
                       video=self.request.get('video'),
                       visible=visible,
                       categories=cat_refs
                           )
     entity.put()
     self.redirect(webapp2.uri_for('addproducts'))
开发者ID:itaogit,项目名称:shopapp,代码行数:27,代码来源:admin.py


示例3: new_category

def new_category():
    """ Route that renders the page to add a new category.

    This method validate that the user is logged in.
    The category is associated with the current logged in user.

    Raises:
        If an error occurs the application will redirect to index page and a flash message
        will be displayed with the proper Exception message.
    """
    try:
        logged_in = 'username' in login_session
        if not logged_in:
            flash("You must be logged to perform this operation", category="error")
            return redirect(url_for('index'))
        form = CategoryForm()
        category = Category()
        category.name = "New item"
        if form.validate_on_submit():
            form.populate_obj(category)
            category.user_id = login_session["user_id"]
            db_session.add(category)
            db_session.commit()
            flash("Category '{}' successfully added".format(category.name))
            return redirect(url_for('get_category', category_id=category.id))
        else:
            categories = db_session.query(Category).order_by(Category.name).all()
            return render_template('new_category.html', categories=categories,
                                   active_category=-1, form=form, logged_in=logged_in,
                                   login_session=login_session)
    except Exception as e:
        flash('An error has occurred: {}'.format(str(e)), 'error')
        return redirect(url_for('index'))
开发者ID:aristoteles-nunez,项目名称:Item-Catalog,代码行数:33,代码来源:app.py


示例4: post

 def post(self, *args):
     c = Category(
         name=self.request.get('name'),
         link=self.request.get('link')
     )
     c.put()
     self.redirect('/admin')
开发者ID:yanzay,项目名称:pagankolo,代码行数:7,代码来源:main.py


示例5: test_model_category

 def test_model_category(self):
     """Test category model"""
     obj = Category(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
开发者ID:tovmeod,项目名称:anaf,代码行数:7,代码来源:tests.py


示例6: show_by_category

def show_by_category(request, key):
    context = base_context()
    rpp = record_per_page()
    cur_page = 1
    try:
        cur_page = int(request.REQUEST["jumpPage"].strip())
    except:
        cur_page = 1

    blogs_count = Blog.all().filter("category", Category.get(key)).count()
    max_page = blogs_count / rpp
    temp2 = blogs_count % rpp
    if temp2 != 0:
        max_page = max_page + 1

    if cur_page > max_page or cur_page <= 0:
        cur_page = max_page

    if cur_page == 0 or cur_page > max_page:
        cur_page = max_page
        blogs = Blog.all().filter("category", Category.get(key)).order("-date").fetch(0)
    else:
        blogs = Blog.all().filter("category", Category.get(key)).order("-date").fetch(rpp, rpp * (cur_page - 1))
    context.cur_page = cur_page
    context.max_page = max_page
    context.action_mode = "/category/" + key + "/show"
    context.range1 = range(1, max_page + 1)
    context.up_page = cur_page - 1
    context.down_page = cur_page + 1
    context.blogs = blogs
    template = loader.get_template("blogs/index.html")
    return HttpResponse(template.render(context))
开发者ID:proming,项目名称:myblogongae,代码行数:32,代码来源:views.py


示例7: setUp

 def setUp(self):
     testboss = User.objects.create(username='big_boss')
     testuser = User.objects.create(username='joe__test', password='new password')
     category = Category(name="TEST")
     category.save()
     self.task = Task.objects.create(summary='Some job', content='', reported_by=testboss)
     self.task.categories.add(category)
开发者ID:davidbernick,项目名称:djangotest,代码行数:7,代码来源:tests.py


示例8: new_category

def new_category():
    """ Add new category """

    # Check if the user is loged in
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':

        # Get data from the front-end
        name = request.form['name']
        description = request.form['description']

        # Put the data into a model
        category = Category(name=name, user_id=login_session['user_id'])

        # Save description if there are one
        if description:
            category.description = description

        session.add(category)
        session.commit()

        return redirect(url_for('categories'))

    return render_template('categories/new_category.html')
开发者ID:Ilyes-Hammadi,项目名称:sportia,代码行数:26,代码来源:views.py


示例9: save_edited_category

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,代码行数:25,代码来源:views.py


示例10: index

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,代码行数:27,代码来源:views.py


示例11: _get_next_level

 def _get_next_level(self, current):
     if self.direction == 'down':
         return Category.get_all_children(current, version=self.version)
     elif self.direction == 'up':
         return Category.get_all_parents(current, version=self.version)
     else:
         raise Exception("Unknown direction %s" % self.direction)
开发者ID:michaelbrooks,项目名称:wikicat,代码行数:7,代码来源:bfs.py


示例12: save

    def save(self):
        cd = self.cleaned_data
        category = Category(
            name=cd['name']
        )
        category.save()
	
开发者ID:belate,项目名称:money,代码行数:6,代码来源:forms.py


示例13: category

def category(action, id=None):
    if action=="edit":
        category = Category.query.get(id)
        if category == None:
            abort(404)
        name = category.name
    else:
        name = None
    form = category_form(name)

    if form.validate_on_submit():
        if action == "new":
            category = Category(
                name=form.name.data, 
                color=form.color.data, 
                user=g.user)
        elif action == "edit":
            category.name = form.name.data
            category.color = form.color.data
        db.session.add(category)
        db.session.commit()
        return redirect(url_for('settings'))

    elif request.method != 'POST':
        if action=="edit":
            form.name.data = category.name
            form.color.data = category.color
    return render_template(
        'category.html',
        title = "Configure category",
        form = form)
开发者ID:JrtPec,项目名称:archiver,代码行数:31,代码来源:views.py


示例14: get

 def get(self, name = ''):
     objs = Category.get_cat_page_posts(name, 1)
     
     catobj = Category.get_cat_by_name(name)
     if catobj:
         pass
     else:
         self.redirect(BASE_URL)
         return
     
     allpost =  catobj.id_num
     allpage = allpost/EACH_PAGE_POST_NUM
     if allpost%EACH_PAGE_POST_NUM:
         allpage += 1
         
     output = self.render('index.html', {
         'title': "%s - %s"%( catobj.name, SITE_TITLE),
         'keywords':catobj.name,
         'description':SITE_DECR,
         'objs': objs,
         'cats': Category.get_all_cat_name(),
         'tags': Tag.get_hot_tag_name(),
         'page': 1,
         'allpage': allpage,
         'listtype': 'cat',
         'name': name,
         'namemd5': md5(name.encode('utf-8')).hexdigest(),
         'comments': Comment.get_recent_comments(),
         'links':Link.get_all_links(),
     },layout='_layout.html')
     self.write(output)
     return output
开发者ID:wing1000,项目名称:wb3,代码行数:32,代码来源:blog.py


示例15: add_category_success

def add_category_success(request):
    if request.method == "POST":
        name = request.POST['name']
        description = request.POST['description']
        c = Category(name=name, description=description)
        c.save()
    return render_to_response('blog/add_category_success.html', context_instance=RequestContext(request))
开发者ID:lpcpp,项目名称:www,代码行数:7,代码来源:views.py


示例16: post

    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,代码行数:34,代码来源:blog.py


示例17: test_edit

    def test_edit(self):
        title = "Vodka based"
        category = Category(title=title)
        category.save()
        self.assertEqual(Category.objects.all().count(), 1)

        url = category.get_absolute_url()
        res = self.app.get(url)

        edit_url = category.get_edit_url()
        self.assert_(edit_url in res.content)

        res = self.app.get(edit_url)
        self.assert_(title in res.content)
        self.assert_("Edit" in res.content)

        form = res.form
        title += ' edited'
        form['title'] = title
        datail_res = form.submit().follow()

        self.assert_(title in datail_res.content)
        self.assert_(edit_url in datail_res.content)

        self.assertEqual(Category.objects.all().count(), 1)
开发者ID:pokutnik,项目名称:test_projects,代码行数:25,代码来源:tests.py


示例18: post

    def post(self):
        json = {}
        if not self.current_user:
            json = {
                'error': 1,
                'msg': self._('Access denied')
            }
            self.write(json)
            return

        title = self.get_argument('title', None)
        slug = self.get_argument('slug', None)
        description = self.get_argument('description', '')
        # valid arguments
        if not title:
            json = {
                'error': 1,
                'msg': self._('Title field can not be empty')
            }
            self.write(json)
            return
        if not slug:
            json = {
                'error': 1,
                'msg': self._('Slug field can not be empty')
            }
            self.write(json)
            return
        elif self.get_category_by_slug(slug):
            json = {
                'error': 1,
                'msg': self._('Slug already exists')
            }
            self.write(json)
            return
        # create category
        category = Category()
        category.title = title
        category.slug = slug
        category.description = description
        self.db.add(category)
        self.db.commit()
        # delete cache
        keys = ['CategoryList', 'SystemStatus']
        self.cache.delete_multi(keys)

        json = {
            'error': 0,
            'msg': self._('Successfully created'),
            'category': {
                'id': category.id,
                'title': category.title,
                'slug': category.slug,
                'description': category.description,
                'permalink': category.permalink,
                'post_count': category.post_count
            }
        }
        self.write(json)
开发者ID:messense,项目名称:YaBlog,代码行数:59,代码来源:api.py


示例19: add_category

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,代码行数:8,代码来源:views.py


示例20: top_users

def top_users():
    user_m = UserManager()
    post_m = PostManager()
    top_users = user_m.top_users()
    top_posts = post_m.top_posts()
    top_comments = User.top_comments()
    Category.posts_without_cat()
    return render_template('top_users.html', users=top_users)
开发者ID:mcrisan,项目名称:blog,代码行数:8,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.ChallengeGame类代码示例发布时间:2022-05-27
下一篇:
Python models.Builder类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap