本文整理汇总了Python中models.Category.name方法的典型用法代码示例。如果您正苦于以下问题:Python Category.name方法的具体用法?Python Category.name怎么用?Python Category.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
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'))
示例2: category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
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)
示例3: add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
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))
示例4: add_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
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))
示例5: get_category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def get_category(self, category_name):
category = None
if category_name != None:
try:
category = Category.objects.get(name=category_name)
except Category.DoesNotExist:
category = Category()
category.name = category_name
category.save()
return category
示例6: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def post(self, user_id):
auth_key = request.args.get('key')
user = User.authenticate(user_id, auth_key)
if user:
supposed_category = request.get_json(force=True)
category = Category()
category.user_id = user_id
category.name = supposed_category['name']
category.icon_id = supposed_category['icon_id']
db.session.add(category)
db.session.commit()
if category.category_id:
return json.jsonify(category.as_dict())
return json.jsonify({})
示例7: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def post(self, username):
user = self.authenticate()
if user:
supposed_category = request.get_json(force=True)
category = Category()
category.category_id = next_id(user)
category.user_id = user.user_id
category.name = supposed_category['name']
category.icon = supposed_category['icon']
db.session.add(category)
db.session.commit()
if category.category_id:
return json.jsonify(category.as_dict())
raise InvalidUsage()
示例8: convert_categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def convert_categories(self):
start_time = time.time()
cursor = connection.cursor()
cursor.execute("SELECT * FROM smf_categories;")
rows = cursor.fetchall()
for row in rows:
category = Category()
category.old_category_id = row[0]
category.name = row[2]
category.position = row[1]
category.active = True
category.save()
self.calculate_time(start_time, time.time())
示例9: category_save
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def category_save(request):
# try:
if int(request.POST["id"]) > 0:
item = Category.objects.get(pk=int(request.POST["id"]))
item.name = request.POST["name"]
workshop = Workshop.objects.get(pk=int(request.POST["related_item1"]))
item.workshop = workshop
item.save()
return ajax_response({"id": item.id, "name": item.name, "related_item1": workshop.id})
item = Category()
item.name = request.POST["name"]
workshop = Workshop.objects.get(pk=int(request.POST["related_item1"]))
item.workshop = workshop
item.save()
return ajax_response({"id": item.id, "name": item.name, "workshop_id": workshop.id})
示例10: _check_categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def _check_categories(self):
categories = self.race.get_categories()
if not categories.is_empty():
return
for short, name in CATEGORIES.items():
cat = Category()
cat.race = self.race
cat.short_name = short
cat.name = name
cat.total_laps = CATEGORIES_LAPS[short]
self.store.add(cat)
#for i in range(200):
# racer = Racer()
# racer.name = unicode(i)
# racer.number = i
# racer.race = self.race
# racer.category = cat
# self.store.add(racer)
self.store.commit()
示例11: savegoods
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def savegoods(request):
params = request.POST;
community = Community.objects.get(number=params["communityId"])
group = UserGroupProfile.objects.filter(user=request.user,community=community)[0]
goods = Goods()
goods.name = params["name"]
img = re.compile(r'^/media').sub("/image",params["image"])
fimg = re.compile(r'^/media').sub("",params["image"])
goods.image = img
goods.groupProfile = group
goods.link = params["link"]
goods.price = float(params["price"])
goods.offprice = float(params["sale"])
goods.desc = params['desc']
goods.community = community
goods.save()
indexs = params.getlist("categoryIndex")
for index in indexs:
category = Category()
category.name = params["categoryName"+index]
category.save()
cvs = params.getlist("categoryValue"+index+"[]")
for cvp in cvs:
cv = CategoryValue()
cv.category = category
cv.value = cvp
cv.save()
gc = GoodsCategory()
gc.category = category
gc.product = goods
gc.save()
if re.search('^http://',params["image"]) == None:
try:
os.mkdir("/www/image/"+str(request.user.id))
except:
pass
shutil.move("/www/tmp/"+fimg,"/www/image/"+str(request.user.id))
return HttpResponseRedirect(redirect_to=reverse("mm:index"))
示例12: category
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def category(request, category):
try:
category = Category.objects.get(name= category)
all_posts = Post.objects.filter(category= category)
related_posts = TaggedItem.objects.get_related(all_posts[0], Post)[:6]
except:
category = Category()
category.name = "No Articles Yet"
all_posts = []
related_posts = []
categories = Category.objects.all()
return render_to_response('articles.html',
{
"page_title": category.name,
"page_moto": category.description,
"page_cover": category.get_cover_url(),
"posts" : all_posts,
"categories" : categories,
"related" : related_posts,
},
context_instance=RequestContext(request))
示例13: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def post(self, title):
if self.form.validate():
post = None
if self.form.post_id.data:
post = yield Post.asyncQuery(id=self.form.post_id.data).first()
if post:
post.modified_time = datetime.datetime.utcnow()
else:
post = Post()
post.create_time = \
self.BeiJing2UTCTime(self.form.create_time.data)
title = self.form.title.data.replace(' ', '-')
content = self.form.content.data
markdown_text = self.form.markdown.data
tags = self.separate_tags(self.form.tags.data)
category_str = self.form.category.data.capitalize()
category = yield Category.asyncQuery(
name=category_str).first()
if not category:
category = Category()
category.name = category_str
yield category.save()
post.title = title
post.content = content
post.markdown = markdown_text
post.category = category
post.tags = tags
post.author = self.current_user
yield post.save()
self.flash("compose finsh!")
return self.redirect('/blog')
self.render("compose.html", form=self.form)
示例14: fetch_categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def fetch_categories(self):
"""
Fetch categories present on EventBrite.
If categories are not cached into database, they are accessed from API and stored into database.
Returns:
"""
global categories_stored
if not categories_stored:
data = Category.objects.all().delete()
payload = {"token": self.token}
request = requests.get(self.base_url + "categories", params=payload)
data = request.json()
for category in data["categories"]:
c = Category()
c.name = category["name"]
c.name_localized = category["name_localized"]
c.category_id = category["id"]
c.save()
categories_stored = True
data = Category.objects.all()
return data
示例15: setUp
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import name [as 别名]
def setUp(self):
c = Category()
c.name = 'test_category'
c.category_id = 1
c.save()