本文整理汇总了Python中models.Category.create方法的典型用法代码示例。如果您正苦于以下问题:Python Category.create方法的具体用法?Python Category.create怎么用?Python Category.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.create方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_stock_no_duplicate
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def test_create_stock_no_duplicate(self):
"""Makes sure stock don't have the same stock_id when creating."""
Category.create(category_id='001', description='Testing Stock')
create_stock('001', 'Testing stock', 1, '001', 9.99)
from peewee import IntegrityError
with self.assertRaises(IntegrityError):
create_stock('001', 'Testing stock', 1, '001', 9.99)
q = Stock.delete().where(Stock.stock_id == '001')
q.execute()
t = Category.delete().where(Category.category_id == '001')
t.execute()
示例2: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def post(self):
name = self.get_argument('name', None)
slug = self.get_argument('slug', None)
q = Category.select().where(Category.name == name)
if q.count() > 0:
self.flash('cateegory exists!')
self.render('admin/category/add.html')
return
else:
Category.create(name=name, slug=slug)
self.redirect('/admin/category')
示例3: test_create_stock
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def test_create_stock(self):
"""Make sure it create a stock."""
Category.create(category_id='001', description='Testing Stock')
create_stock('001', 'Testing stock', 1, '001', 9.99)
s = Stock.select().where(Stock.stock_id == '001')
t = Stock.delete().where(Stock.stock_id == '001')
t.execute()
t = Category.delete().where(Category.category_id == '001')
t.execute()
self.assertEqual(str(s), ("<class 'models.Stock'> SELECT `t1`.`id`,"
" `t1`.`stock_id`, `t1`.`description`,"
" `t1`.`quantity`, `t1`.`category_id`,"
" `t1`.`price` FROM `stock` AS t1"
" WHERE (`t1`.`stock_id` = %s) ['001']"))
示例4: test_create_outgoing
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def test_create_outgoing(self):
"""Create an outgoing record."""
Category.create(category_id='001', description='Testing Stock')
Project.create(project_id='001', project_description="Testing")
Role.create(role_name='Admin')
User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='JayPalm',
password='jfresh13', email='[email protected]')
create_stock('001', 'Testing stock', 1, '001', 9.99)
create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='JayPalm')
OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
Stock.get(Stock.category == '001').delete_instance()
User.get(User.username == 'JayPalm').delete_instance()
Role.get(Role.role_name == 'Admin').delete_instance()
Project.get(Project.project_id == '001').delete_instance()
Category.get(Category.category_id == '001').delete_instance()
示例5: test_create_incoming
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def test_create_incoming(self):
"""Create an incoming record."""
Category.create(category_id='001', description='Testing Stock')
create_stock('001', 'Testing stock', 1, '001', 9.99)
create_incoming_stock(stock="001", date="2015-07-22", quantity=13, price=13.99)
p = IncomingStock.select().where(IncomingStock.stock == '001')
q = IncomingStock.delete().where(IncomingStock.stock == '001')
q.execute()
s = Stock.select().where(Stock.stock_id == '001')
t = Stock.delete().where(Stock.stock_id == '001')
t.execute()
t = Category.delete().where(Category.category_id == '001')
t.execute()
self.assertEqual(str(p), ("<class 'models.IncomingStock'> SELECT `t1`.`id`, `t1`.`stock_id`, "
"`t1`.`date`, `t1`.`price`, `t1`.`cost` FROM `incomingstock` AS t1 WHERE "
"(`t1`.`stock_id` = %s) ['001']"))
示例6: add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def add_category():
if request.method == 'GET':
return render_template("add_category.html")
name = request.form.get('category', '').replace(' ', '_')
try:
is_valid_category(name)
category = Category.create(name)
except RuntimeError, e:
return render_template("add_category.html", category=name, error=e.message)
示例7: create_db
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def create_db():
logging.info("Creating SQLite database %s..." % DB_FILE)
# Define database
db = SqliteDatabase(DB_FILE, threadlocals=True)
# Connect to database
db.connect()
# Create tables
Category.create_table()
Feed.create_table()
Post.create_table()
Image.create_table()
# Create default Unsorted category
Category.create(name='Unsorted', comment='Uncategorised feeds', order=1)
logging.info("Database created.")
示例8: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def post(self):
form = CategoryForm()
if request.method == 'POST':
if form.validate_on_submit():
try:
category = Category.create()
form.populate_obj(category)
category.save()
flash(gettext('Category succesfully created'))
return util.redirect_json_or_html(url_for('CategoriesView:index'), 'category')
except:
flash(gettext('Error while creating the category'), 'error')
else:
flash(gettext('Invalid submission, please check the message below'), 'error')
return render_template('admin/categories/add.html',
title=gettext('Create Category'),
form=form)
示例9: load_defaults
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def load_defaults():
logging.info("Loading default feed entries into database %s..." % DB_FILE)
# Open defaults file
with open(DEFAULTS_FILE, 'r') as f:
rows = f.readlines()
f.close()
# Define database
db = SqliteDatabase(DB_FILE, threadlocals=True)
# Connect to database
db.connect()
# Iterate over default feeds list
# PSV format name|url|category
for row in rows:
(name, url, category) = row.split('|')
category = category.strip()
# Update Category table
c = Category.create(name=category, comment='Default category', order=1)
# Get Category insert id
cid = c.id
# Update Feeds table
f = Feed.create(name=name, version='', url=url, category=cid, favicon='', comment='Default feed', description='Default feed')
# Get Feed insert id
fid = f.id
# Get favicon for this Feed
# returns path to local favicon file, or None
# write to current feed record
logging.info("Getting favicon for %s" % f.url)
f.favicon = getFavicon(fid)
logging.info("Got favicon %s" % f.favicon)
# Save entry to feeds table
f.save()
logging.info("Default feeds loaded.")
示例10: open
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
# coding:utf-8
import csv
# 读取岗位族群分类信息
from models import Category
with open('04.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile)
rows = [row for row in reader]
# 抓取数据时是深度优先
for row in rows:
if not row['parent_code']:
c = Category.create(name=row['name'], code=row['code'])
else:
parent = Category.select().where(Category.code == row['parent_code']).get()
Category.create(name=row['name'], code=row['code'], parent=parent)
示例11: opml_parse
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def opml_parse():
UPLOAD_FOLDER = os.path.realpath('.') + '/static/uploads'
file = request.files['file']
if file and allowed_file(file.filename):
opml_filename = str(uuid.uuid4()) + '.xml' # use UUID as unique uploaded filename root
opml_path = os.path.join(UPLOAD_FOLDER, opml_filename)
file.save(opml_path)
print('OPML uploaded OK!')
# run Opml parser on uploaded file
o = Opml.OpmlReader(opml_path)
o.parseOpml()
print('OPML parsed OK!')
# Save categories to DB, skip invalid or duplicate feeds
for c in o.categories:
try:
cat = Category.create(name=c)
cat.save()
except IntegrityError:
pass
print('Categories added to DB!')
# Iterate over feeds found
for f in o.feeds:
print('------------')
print(f)
# Get corresponding Category id
cat_id = Category.get(Category.name == f['category']).id
if o.version == "1.0":
# Add feed from OPML version 1.0
# TODO: Exception handling
feed = Feed.create(name=f['text'], category=cat_id, version=f['type'], url=f['url'])
elif o.version == "1.1" or o.version == "2.0":
# Add feed from OPML version 1.1
# TODO: Exception handling
feed = Feed.create(name=f['title'], category=cat_id, version=f['type'], comment=f['text'],
description=f['description'], url=f['xmlUrl'])
else:
continue
# Add feed to DB, skip invalid or duplicate feeds
try:
feed.save()
except IntegrityError:
pass
print('Feeds added to DB!')
# return send_from_directory(UPLOAD_FOLDER, opml_filename) # Test returning uploaded OPML file
return redirect(url_for('index'), code=302)
return "<h1>Oops, something went wrong here...</h1>file extension is " + os.path.splitext(file.filename)[1]
示例12: create_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
def create_category(category_id, description):
"""Takes arguments and create a new record in category table."""
Category.create(category_id=category_id, description=description)
示例13: print
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import create [as 别名]
Testing OPML import
(c) 2015 KyubiSystems: www.kyubi.co.uk
"""
from opml import Opml
from models import Category, Feed, IntegrityError
o = Opml.OpmlReader('./opml/testing.xml')
o.parseOpml()
# Show retrieved data structures
print(o.version)
# Save categories to DB, skip invalid or duplicate feeds
for c in o.categories:
cat = Category.create(name=c)
try:
cat.save()
except IntegrityError:
pass
# Iterate over feeds found
for f in o.feeds:
print('------------')
print(f)
# Get corresponding Category id
cat_id = Category.get(Category.name == f['category']).id
if o.version == "1.0":