本文整理汇总了Python中addons.models.Persona类的典型用法代码示例。如果您正苦于以下问题:Python Persona类的具体用法?Python Persona怎么用?Python Persona使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Persona类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_personas_landing
def test_personas_landing(self):
"""Show landing page if there are greater than 4 Personas."""
for i in xrange(3):
a = Addon(type=amo.ADDON_PERSONA)
a.name = 'persona-%s' % i
a.all_categories = []
a.save()
v = Version.objects.get(addon=Addon.objects.get(id=15679))
v.addon = a
v.pk = None
v.save()
p = Persona(addon_id=a.id, persona_id=i)
p.save()
a.persona = p
a._current_version = v
a.status = amo.STATUS_PUBLIC
a.save()
base = (Addon.objects.public().filter(type=amo.ADDON_PERSONA)
.extra(select={'_app': amo.FIREFOX.id}))
eq_(base.count(), 5)
r = self.client.get(reverse('browse.personas'))
self.assertTemplateUsed(r, 'browse/personas/category_landing.html')
示例2: save
def save(self, commit=False):
from .tasks import create_persona_preview_image, save_persona_image
# We ignore `commit`, since we need it to be `False` so we can save
# the ManyToMany fields on our own.
addon = super(NewPersonaForm, self).save(commit=False)
addon.status = amo.STATUS_UNREVIEWED
addon.type = amo.ADDON_PERSONA
addon.save()
addon._current_version = Version.objects.create(addon=addon,
version='0')
addon.save()
amo.log(amo.LOG.CREATE_ADDON, addon)
log.debug('New persona %r uploaded' % addon)
data = self.cleaned_data
header = data['header_hash']
footer = data['footer_hash']
header = os.path.join(settings.TMP_PATH, 'persona_header', header)
footer = os.path.join(settings.TMP_PATH, 'persona_footer', footer)
dst = os.path.join(settings.PERSONAS_PATH, str(addon.id))
# Save header, footer, and preview images.
save_persona_image(src=header, dst=dst, img_basename='header.jpg')
save_persona_image(src=footer, dst=dst, img_basename='footer.jpg')
create_persona_preview_image(src=header, dst=dst,
img_basename='preview.jpg',
set_modified_on=[addon])
# Save user info.
user = self.request.amo_user
AddonUser(addon=addon, user=user).save()
p = Persona()
p.persona_id = 0
p.addon = addon
p.header = 'header.jpg'
p.footer = 'footer.jpg'
if data['accentcolor']:
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:
p.textcolor = data['textcolor'].lstrip('#')
p.license_id = data['license']
p.submit = datetime.now()
p.author = user.name
p.display_username = user.username
p.save()
# Save tags.
for t in data['tags']:
Tag(tag_text=t).save_tag(addon)
# Save categories.
tb_c = Category.objects.get(application=amo.THUNDERBIRD.id,
name__id=data['category'].name_id)
AddonCategory(addon=addon, category=data['category']).save()
AddonCategory(addon=addon, category=tb_c).save()
return addon
示例3: save
def save(self, commit=False):
from addons.tasks import (create_persona_preview_images,
save_persona_image)
data = self.cleaned_data
addon = Addon.objects.create(id=None, name=data['name'],
slug=data['slug'], description=data['summary'],
status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA)
addon._current_version = Version.objects.create(addon=addon,
version='0')
addon.save()
# Save header, footer, and preview images.
try:
header = data['header_hash']
footer = data['footer_hash']
header = os.path.join(settings.TMP_PATH, 'persona_header', header)
footer = os.path.join(settings.TMP_PATH, 'persona_footer', footer)
dst_root = os.path.join(settings.PERSONAS_PATH, str(addon.id))
save_persona_image.delay(src=header,
full_dst=os.path.join(dst_root, 'header.png'))
save_persona_image.delay(src=footer,
full_dst=os.path.join(dst_root, 'footer.png'))
create_persona_preview_images.delay(src=header,
full_dst=[os.path.join(dst_root, 'preview.png',
os.path.join(dst_root, 'icon.png'))],
set_modified_on=[addon])
except IOError:
addon.delete()
raise IOError
# Save user info.
user = self.request.amo_user
AddonUser(addon=addon, user=user).save()
# Create Persona instance.
p = Persona()
p.persona_id = 0
p.addon = addon
p.header = 'header'
p.footer = 'footer'
if data['accentcolor']:
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:
p.textcolor = data['textcolor'].lstrip('#')
p.license_id = data['license']
p.submit = datetime.now()
p.author = user.name
p.display_username = user.username
p.save()
# Save categories.
tb_c, created = Category.objects.get_or_create(
application_id=amo.THUNDERBIRD.id,
name__id=data['category'].name.id, type=amo.ADDON_PERSONA)
AddonCategory(addon=addon, category=data['category']).save()
AddonCategory(addon=addon, category=tb_c).save()
return addon
示例4: save
def save(self, commit=False):
data = self.cleaned_data
addon = Addon.objects.create(
slug=data.get('slug'),
status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA)
addon.name = {'en-US': data['name']}
if data.get('description'):
addon.description = data['description']
addon._current_version = Version.objects.create(addon=addon,
version='0')
addon.save()
# Create Persona instance.
p = Persona()
p.persona_id = 0
p.addon = addon
p.header = 'header.png'
if data['footer_hash']:
p.footer = 'footer.png'
if data['accentcolor']:
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:
p.textcolor = data['textcolor'].lstrip('#')
p.license = data['license']
p.submit = datetime.now()
user = self.request.amo_user
p.author = user.username
p.display_username = user.name
p.save()
# Save header, footer, and preview images.
save_theme.delay(data['header_hash'], data['footer_hash'], addon)
# Save user info.
addon.addonuser_set.create(user=user, role=amo.AUTHOR_ROLE_OWNER)
# Save tags.
for t in data['tags']:
Tag(tag_text=t).save_tag(addon)
# Save categories.
AddonCategory(addon=addon, category=data['category']).save()
return addon
示例5: save
def save(self, commit=False):
from addons.tasks import (create_persona_preview_images,
save_persona_image)
data = self.cleaned_data
addon = Addon.objects.create(slug=data.get('slug'),
status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA)
addon.name = {'en-US': data['name']}
if data.get('summary'):
addon.description = {'en-US': data['summary']}
addon._current_version = Version.objects.create(addon=addon,
version='0')
addon.save()
# Save header, footer, and preview images.
try:
header = data['header_hash']
footer = data['footer_hash']
header = os.path.join(settings.TMP_PATH, 'persona_header', header)
footer = os.path.join(settings.TMP_PATH, 'persona_footer', footer)
dst_root = os.path.join(settings.ADDONS_PATH, str(addon.id))
save_persona_image.delay(src=header,
full_dst=os.path.join(dst_root, 'header.png'))
save_persona_image.delay(src=footer,
full_dst=os.path.join(dst_root, 'footer.png'))
create_persona_preview_images.delay(src=header,
full_dst=[os.path.join(dst_root, 'preview.png'),
os.path.join(dst_root, 'icon.png')],
set_modified_on=[addon])
except IOError:
addon.delete()
raise
# Save user info.
user = self.request.amo_user
addon.addonuser_set.create(user=user, role=amo.AUTHOR_ROLE_OWNER)
# Create Persona instance.
p = Persona()
p.persona_id = 0
p.addon = addon
p.header = 'header.png'
p.footer = 'footer.png'
if data['accentcolor']:
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:
p.textcolor = data['textcolor'].lstrip('#')
p.license = data['license']
p.submit = datetime.now()
p.author = user.username
p.display_username = user.name
p.save()
# Save tags.
for t in data['tags']:
Tag(tag_text=t).save_tag(addon)
# Save categories.
AddonCategory(addon=addon, category=data['category']).save()
return addon