本文整理汇总了Python中tags.models.Tag.save方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.save方法的具体用法?Python Tag.save怎么用?Python Tag.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tags.models.Tag
的用法示例。
在下文中一共展示了Tag.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ask
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def ask(request):
ask_form = AskQuestion(request.POST or None)
args = {}
args['form'] = ask_form
if request.POST and ask_form.is_valid():
question = Question(text=ask_form.cleaned_data['text'], title=ask_form.cleaned_data['title'])
tags = ask_form.cleaned_data['tags']
g = Tag.objects.all()
getTag = tags.split(', ')
for tag in getTag:
counter = 0
for l in g:
if l.tag == tag:
counter += 1
if counter == 0:
t = Tag(tag=tag)
t.save()
user = auth.get_user(request)
question.author = user
question.save()
a = g.filter(tag__in=getTag)
question.tags.add(*a)
return redirect('questionGet', question_id=question.id)
else:
return render(request, 'ask.html', args)
示例2: mutate_and_get_payload
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def mutate_and_get_payload(cls, input, request, info):
gid_type, gid = from_global_id(input.get('lifeNode'))
node = LifeNode._meta.model.objects.get(document_id=gid)
error = has_permission(cls, request, node, 'edit')
if error:
return error
tag_title = input.get('title').strip(' \t\n\r')
tag_slug = slugify(tag_title)
try:
tag = TagModel.objects.get(slug=tag_slug)
except TagModel.DoesNotExist:
tag = TagModel(
title=tag_title,
slug=tag_slug,
)
tag.save(request=request)
c = CharacteristicModel(
tag=tag.document,
lifeNode=node.document,
value=input.get('value')
)
c.save(request=request)
return CharacteristicAdd(
lifeNode=node,
characteristic=Characteristic.Connection.Edge(
node=c, cursor=offset_to_cursor(0))
)
示例3: post_save
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def post_save(post, args, request):
post.url = args.get('url')
post.title = args.get('title')
post.body = args.get('body')
post.published_at = args.get('published_at')
post.save(request=request)
post.tags.clear()
from tags.models import Tag
tags_raw = args.get('tags', '')
for tag_title in tags_raw.split(','):
tag_title = tag_title.strip(' \t\n\r')
tag_slug = slugify(tag_title)
if len(tag_title) == 0:
# don't save empty tag
continue
try:
tag = Tag.objects.get(slug=tag_slug)
except Tag.DoesNotExist:
tag = Tag(
title=tag_title,
slug=tag_slug,
)
tag.save(request=request)
post.tags.add(tag.document)
return post
示例4: add
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def add(request, app_label, model, object_id):
content_type = get_object_or_404(ContentType, app_label=app_label,
model=model)
model = content_type.model_class()
object_id = int(object_id)
item = get_object_or_404(model, id=object_id)
user = request.user
new_tags = []
if request.method == "POST":
tags = [t.strip() for t in request.POST.get("tags", u"").split(u",")]
for tag in tags:
if not item.tags.filter(user=user, slug=slugify(tag)).count():
tag = Tag(content_type=content_type, object_id=object_id,
user=user, name=tag)
tag.save()
new_tags.append(tag)
reindex(item)
response = {"tags": []}
for tag in new_tags:
response["tags"].append(dict(name=tag.name,
id=tag.id,
url=reverse("materials:keyword_index",
kwargs={"keywords": tag.slug}),
))
return response
示例5: tagref_create
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def tagref_create(request, tag_name):
""" Create a single tag reference.
The resource must exist and the reference must be valid, but if the tag
doesn't exist, then then it is created.
"""
try:
# resource MUST exist
res_str = request.POST['resource'].strip()
resource = library.get(res_str)
# reference must be valid
ref_str = request.POST['reference']
ref = resource.reference(ref_str)
except:
log.info("User provided bad resource or reference. (res: %s; ref: )", res_str, ref_str)
raise Http404
# if tag name doesn't exist, create it
try:
t = get_exact_tag(request.user, tag_name)
except:
# TODO: move to models
t = Tag(tag=tag_name, user=request.user)
t.save()
log.debug("Saving new tag %s %s %s %s", ref_str, tag_name, t, ref.pretty())
# TODO: move to models
new_ref = Reference(tag=t, resource=res_str, reference=ref.pretty(),
offset_start=ref.indices().start, offset_end=ref.indices().end,
user=request.user)
new_ref.save()
return HttpResponseRedirect(reverse('tagref_detail', args=(tag_name, str(new_ref.id))));
示例6: setUp
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def setUp(self):
from regions.models import Region
from pages.models import Page
from tags.models import Tag, PageTagSet
self.factory = RequestFactory()
# Create a new region and associate a domain with it
self.sf = Region(full_name="San Francisco", slug="sf")
self.sf.save()
self.sf.regionsettings.domain = 'fakename.org'
self.sf.regionsettings.save()
self.user = User.objects.create_user(
username='testuser', email='[email protected]', password='fakepassword')
self.user.save()
# Create a page in the SF region
p = Page(name='Parks', content='<p>Hi</p>', region=self.sf)
p.save(user=self.user)
p.content += "!"
p.save(user=self.user)
# Add a tag to the page
t = Tag(name='park', slug='park', region=self.sf)
t.save(user=self.user)
pts = PageTagSet(region=self.sf, page=p)
pts.save(user=self.user)
pts.tags.add(t)
pts.save(user=self.user)
示例7: test_edit_tag_form_is_valid
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_edit_tag_form_is_valid():
user = make_users(1)[0]
tag = Tag(title='title', user=user)
tag.save()
form = EditTagForm({
'title': 'test',
}, user=user, instance=tag)
assert form.is_valid()
示例8: test_slug
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_slug(self):
t = Tag(name='Library of Congress', region=self.region)
t.save()
self.assertEqual(t.slug, 'libraryofcongress')
t = Tag(name='Сочи 2014', region=self.region)
t.save()
self.assertEqual(t.slug, 'сочи2014'.decode('utf-8'))
示例9: test_bookmarks_get_delete_url_returns_correct_url
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_bookmarks_get_delete_url_returns_correct_url():
user = make_users(1)[0]
tag = Tag(title='Test Tag', slug='test-tag', user=user)
tag.save()
Bookmark(title='Test Bookmark', slug='test-bookmark', tag=tag,
url="http://www.testers.com", user=user).save()
bookmark = Bookmark.objects.get(pk=1)
assert bookmark.get_delete_url() == '/bookmarks/delete/test-tag/test-bookmark/'
示例10: test_bookmarks_unicode_method_returns_title_correctly
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_bookmarks_unicode_method_returns_title_correctly():
user = make_users(1)[0]
tag = Tag(title='Test Tag', slug='test-tag', user=user)
tag.save()
Bookmark(title='Test Bookmark', slug='test-bookmark', tag=tag,
url="http://www.testers.com", user=user).save()
bookmark = Bookmark.objects.get(pk=1)
assert bookmark.__unicode__() == 'Test Bookmark'
示例11: test_remove_tag_button
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_remove_tag_button(self):
self.client.login(username='[email protected]', password='password')
tag = Tag(tag_text='f')
tag.save()
AddonTag(addon=Addon.objects.get(pk=3615), tag=tag, user_id=999).save()
r = self.client.get(reverse('addons.detail', args=[3615]))
doc = pq(r.content)
assert len(doc('#tags li input.removetag'))
示例12: setUp
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def setUp(self):
u = UserProfile(username='foo')
u.save()
t = Tag(tag_text='donkeybuttrhino')
t.save()
a = Addon.objects.all()[0]
at = AddonTag(tag=t, user=u, addon=a)
at.save()
super(TagTest, self).setUp()
示例13: test_edit_tag_form_is_invalid_due_to_no_title
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_edit_tag_form_is_invalid_due_to_no_title():
user = make_users(1)[0]
tag = Tag(title='title', user=user)
tag.save()
form = EditTagForm({
'title': '',
}, user=user, instance=tag)
assert not form.is_valid()
assert ['title'] == form.errors.keys()
示例14: test_not_blacklisted
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_not_blacklisted(self):
"""Make sure Tag Manager filters right for not blacklisted tags."""
tag1 = Tag(tag_text='abc', blacklisted=False)
tag1.save()
tag2 = Tag(tag_text='swearword', blacklisted=True)
tag2.save()
eq_(Tag.objects.all().count(), 2)
eq_(Tag.objects.not_blacklisted().count(), 1)
eq_(Tag.objects.not_blacklisted()[0], tag1)
示例15: test_edit_tag_form_saves_correctly
# 需要导入模块: from tags.models import Tag [as 别名]
# 或者: from tags.models.Tag import save [as 别名]
def test_edit_tag_form_saves_correctly():
user = make_users(1)[0]
tag = Tag(title='tag', user=user)
tag.save()
form = EditTagForm({
'title': 'new name',
}, user=user, instance=tag)
assert form.is_valid()
form.save()
assert Tag.objects.get(pk=1).title == 'new name'