當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.create方法代碼示例

本文整理匯總了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()
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:13,代碼來源:tests.py

示例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')
開發者ID:dengmin,項目名稱:logpress-tornado,代碼行數:13,代碼來源:admin.py

示例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']"))
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:16,代碼來源:tests.py

示例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()
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:17,代碼來源:tests.py

示例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']"))
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:19,代碼來源:test.py

示例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)
開發者ID:lost-theory,項目名稱:moviepicker,代碼行數:11,代碼來源:app.py

示例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.")
開發者ID:KyubiSystems,項目名稱:Wisewolf,代碼行數:22,代碼來源:DatabaseUtils.py

示例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)
開發者ID:Tibodef,項目名稱:PythonBlog,代碼行數:20,代碼來源:views.py

示例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.")
開發者ID:KyubiSystems,項目名稱:Wisewolf,代碼行數:41,代碼來源:DatabaseUtils.py

示例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)
開發者ID:ak64th,項目名稱:courses.myctu.cn,代碼行數:19,代碼來源:category_import_2.py

示例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]
開發者ID:KyubiSystems,項目名稱:Wisewolf,代碼行數:64,代碼來源:views.py

示例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)
開發者ID:dsantosp12,項目名稱:NapAdmin,代碼行數:5,代碼來源:category.py

示例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":
開發者ID:KyubiSystems,項目名稱:Wisewolf,代碼行數:33,代碼來源:opml_test.py


注:本文中的models.Category.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。