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


Python models.Category类代码示例

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


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


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