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


Python models.Category类代码示例

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


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

示例1: transfer_post

    def transfer_post(self):

        form = TranferForm()

        if form.is_submitted():
            try:
                if not form.validate():
                    raise Exception(_('ERROR_INVALID_SUBMISSION'))

                cat_from = Category.get_by_id(form.from_id.data)
                cat_to = Category.get_by_id(form.to_id.data)

                if not cat_from or not cat_to:
                    raise Exception(_('CATEGORY_TRANSFER_POSTS_CHECK_FAILED'))

                Category.transfer_posts(cat_from, cat_to)

                message = _('CATEGORY_TRANSFER_POSTS_SUCCESS',
                            from_name=cat_from.name,
                            to_name=cat_to.name)

                return render_view(url_for('CategoriesView:index'),
                                   message=message,
                                   redirect=True)
            except Exception as e:
                flash(e.message, 'error')

        return render_view('admin/categories/transfer.html',
                           form=form)
开发者ID:jctt1983,项目名称:PythonBlog,代码行数:29,代码来源:index.py

示例2: post

    def post(self):
        form = CategoryForm()

        if form.is_submitted():
            try:
                if not form.validate():
                    raise Exception(_('ERROR_INVALID_SUBMISSION'))

                category = Category.create()

                if not form.slug.data:
                    form.slug.data = form.name.data

                form.slug.data = Category.urlify(form.slug.data)

                form.populate_obj(category)
                category.save()

                return render_view(url_for('CategoriesView:put', id=category.id),
                                   message=_('CATEGORY_CREATE_SUCESS'),
                                   redirect=True)
            except Exception as e:
                flash(e.message, 'error')

        return render_view('admin/categories/add.html', form=form)
开发者ID:jctt1983,项目名称:PythonBlog,代码行数:25,代码来源:index.py

示例3: addCategory

def addCategory(request):
    if request.method == 'GET':
        category_name = request.GET.get('name')
        user = User.objects.get(pk=request.user.id)
        category = Category(name=category_name, user=user)
        category.save()
        return redirect('home')
    else:
        return Response(status=403)
开发者ID:mykytamorachov,项目名称:SaveYourPage,代码行数:9,代码来源:views.py

示例4: category_add

def category_add():
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/category_add.html')
        return template.render(categories=all_categories)
    if request.method == 'POST':
        new_category = Category.create(category_name=post_get('category_name'))
        app.flash(u'Нова категорія була успішно додана')
        redirect('/category/add')
开发者ID:bmwant,项目名称:bmwlog,代码行数:9,代码来源:post.py

示例5: create_new

 def create_new(self):
     rv = Form.validate(self)
     if rv:
         category = Category()
         category.init(self.name.data, self.num.data, self.parentid.data, self.visible.data, self.paid.data, self.dcost.data)
         db.session.add(category)
         db.session.commit()
         self.category = category
         return True
     return False
开发者ID:RedBuld,项目名称:Aviator,代码行数:10,代码来源:forms.py

示例6: db_init

def db_init():
    """Initialize the database."""
    from app import db
    db.create_all()
    click.echo('Initialize the database.')

    from app.models import Category
    c1 = Category.create(name=u'Uncategorized', slug=u'uncategorized')
    c1.save()
    c2 = Category.create(name=u'News', slug=u'news')
    c2.save()
开发者ID:,项目名称:,代码行数:11,代码来源:

示例7: deploy

def deploy():
    """Run deploment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User, Post, Category

    upgrade()

    Role.insert_roles()
    User.add_self_follows()
    Category.add_categorys()
    Post.add_default_title()
    Post.add_default_category()
开发者ID:yuzhou6,项目名称:myflask,代码行数:12,代码来源:manage.py

示例8: add_five_random_categories

def add_five_random_categories(request):
	categories = Category.objects.filter(user=request.user)
	for idx in range(5):
		raw_name = list(string.ascii_lowercase)
		random.shuffle(raw_name)
		name = ''.join(raw_name[:6])
		column_number = random.randrange(0, 6)
		row_number = get_max_row_number(categories.filter(column_number=column_number)) + 1
		progress_bar_color = get_random_color()
		category = Category(user=request.user, name=name, column_number=column_number, 
			row_number=row_number, progress_bar_color=progress_bar_color)
		category.save()
	return HttpResponseRedirect('/b/edit')
开发者ID:chiranjeevjain,项目名称:bookmark-manager,代码行数:13,代码来源:bulk_adders.py

示例9: create_new

 def create_new(self):
     rv = Form.validate(self)
     ri = self.img.validate(self)
     if rv and ri:
         category = Category()
         if not check_icon(self.img.data):
             self.img.errors.append(_(u'Image not found'))
             return False
         category.init(self.name.data, self.num.data, self.visible.data, self.img.data)
         i = Upload.query.filter_by(url=self.img.data).first()
         db.session.delete(i)
         db.session.add(category)
         db.session.commit()
         self.category = category
         return True
     return False
开发者ID:RedBuld,项目名称:-exp-W7_1pc,代码行数:16,代码来源:forms.py

示例10: adduser

def adduser(email, username, admin=False):
  """ Register a new user"""
  from getpass import getpass
  password = getpass()
  password2 = getpass(prompt='Confirm: ')

  if password != password2:
    import sys
    sys.exit("Error: Passwords do not match!")

  db.create_all()

  category = Category.get_by_name('Almenn frétt')
  if category is None:
    category = Category(name='Almenn frétt',
                        name_en='General News',
                        active=True)
    db.session.add(category)

  user = User(email=email,
              username=username,
              password=password,
              is_admin=admin)
  db.session.add(user)
  db.session.commit()

  print('User {0} was registered successfully!'.format(username))
开发者ID:finnurtorfa,项目名称:aflafrettir.is,代码行数:27,代码来源:manage.py

示例11: post_add

def post_add():
    form = PostForm()
    if request.method == 'GET':
        all_categories = Category.select()
        template = env.get_template('post/add.html')
        return template.render(
            form=form,
            categories=all_categories,
        )
    if request.method == 'POST':
        post = Post.create(
            category=post_get('category-id'),
            post_text=post_get('text'),
            title=post_get('title'),
            slug=post_get('slug'),
            user=app.current_user.user_id,
            date_posted=datetime.now(),
            draft=bool(int(post_get('draft'))),
            show_on_index=bool(post_get('show-on-index')),
            language=post_get('language'),
        )
        post_id = post.post_id
        post.save()
        add_new_tags(post_get('tags'), post_id)
        redirect('/post/' + str(post_id))
开发者ID:bmwant,项目名称:bmwlog,代码行数:25,代码来源:post.py

示例12: post_edit

def post_edit(post_id):
    if request.method == 'GET':
        try:
            post = Post.get(Post.post_id == post_id)  # todo: get not deleted
        except Post.DoesNotExist:
            abort(404)

        form = PostForm(obj=post)
        all_categories = Category.select()
        template = env.get_template('post/edit.html')
        return template.render(
            item=post,
            form=form,
            categories=all_categories,
        )
    elif request.method == 'POST':
        post = Post.get(Post.post_id == post_id)
        post.category = post_get('category-id')
        post.post_text = post_get('text')
        post.slug = post_get('slug')
        post.title = post_get('title')
        post.draft = bool(int(post_get('draft')))  # zero int is False
        post.language = post_get('language')
        post.show_on_index = bool(post_get('show-on-index'))
        post.date_updated = datetime.now()
        new_tags = post_get('tags')
        old_tags = Tag.select().join(Tag_to_Post)\
            .where(Tag_to_Post.post_id == post_id)
        remove_tags(old_tags, new_tags, post_id)
        add_new_tags(new_tags, post_id)
        post.save()
        app.flash('Article updated')
        redirect('/post/' + str(post_id))
开发者ID:bmwant,项目名称:bmwlog,代码行数:33,代码来源:post.py

示例13: test_is_not_sortable

 def test_is_not_sortable(self):
     """
     A model should only become sortable if it has more than
     record to sort.
     """
     self.create_category()
     self.assertFalse(Category.is_sortable(),
         'Category only has one record. It should not be sortable.')
开发者ID:Hedde,项目名称:django-admin-sortable,代码行数:8,代码来源:tests.py

示例14: test_07_order_cate

    def test_07_order_cate(self):
        """测试分类顺序"""
        cate1 = Category(name='cate1')
        db.session.add(cate1)
        db.session.commit()

        cate2 = Category(name='cate2',
                         order=1)
        cate3 = Category(name='cate3',
                         order=2)
        cate3.parent = cate1
        cate2.parent = cate1
        db.session.add(cate2)
        db.session.add(cate3)
        db.session.commit()

        self.assertTrue(cate2.order < cate3.order)
开发者ID:imhuwq,项目名称:imhuwq,代码行数:17,代码来源:create_cate_tag.py

示例15: add_category

def add_category(request):
    if request.method == "POST" and request.is_ajax():
        category_name = request.POST.get("name")
        if category_name == "":
            return HttpResponse("分类名称不能为空")
            # print category_name		#打印分类名称
        user = User.objects.get(username=request.user.username)
        # print user.username		#打印当前用户名
        category = Category(name=category_name, user=user)
        category.save()
        return HttpResponse("添加成功")  # ajax post要返回一个值,否则报500错误
    else:
        # print 'get请求, 返回管理界面!'
        category_list = Category.objects.filter(user=request.user)
        # category_list = Category.objects.all()
        content_dict = {"categories": category_list}
        return render(request, "admin/category_manage.htm", content_dict)
开发者ID:xueyue123,项目名称:zhBlog,代码行数:17,代码来源:back_manage.py


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