Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
clean up Theme Submission form and success page (bug 795966, bug 830988)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Feb 27, 2013
1 parent 6c40ed5 commit 1e706ca
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 49 deletions.
51 changes: 26 additions & 25 deletions apps/addons/forms.py
Expand Up @@ -504,6 +504,7 @@ class NewPersonaForm(AddonFormBase):
footer_hash = forms.CharField(widget=forms.HiddenInput)
accentcolor = ColorField(required=False)
textcolor = ColorField(required=False)
agreed = forms.BooleanField()
# This lets us POST the data URIs of the unsaved previews so we can still
# show them if there were form errors. It's really clever.
unsaved_data = forms.CharField(required=False, widget=forms.HiddenInput)
Expand Down Expand Up @@ -533,39 +534,38 @@ def clean_tags(self):
return clean_tags(self.request, self.cleaned_data['tags'])

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()
from addons.tasks import (create_persona_preview_image,
save_persona_image)
data = self.cleaned_data
# TODO: Ask for slug.
addon = Addon.objects.create(name=data['name'],
description=data.get('summary'),
status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA)
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])
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 = os.path.join(settings.PERSONAS_PATH, str(addon.id))
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])
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
Expand All @@ -586,8 +586,9 @@ def save(self, commit=False):
Tag(tag_text=t).save_tag(addon)

# Save categories.
tb_c = Category.objects.get(application=amo.THUNDERBIRD.id,
name__id=data['category'].name_id)
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()

Expand Down
1 change: 0 additions & 1 deletion apps/addons/tasks.py
Expand Up @@ -205,7 +205,6 @@ def create_persona_preview_image(src, dst, img_basename, **kw):
@set_modified_on
def save_persona_image(src, dst, img_basename, **kw):
"""Creates a JPG of a Persona header/footer image."""

log.info('[1@None] Saving persona image: %s' % dst)
img = ImageCheck(storage.open(src))
if not img.is_image():
Expand Down
34 changes: 20 additions & 14 deletions apps/devhub/templates/devhub/personas/submit.html
Expand Up @@ -20,11 +20,11 @@ <h1>{{ title }}</h1>
<fieldset>
<legend>{{ _('Theme Details') }}</legend>
<ul>
{{ pretty_field(form.name, label=_('Give your Theme a name.')) }}
{{ pretty_field(form.name, label=_('Give your Theme a name.'), validate=True) }}
{{ pretty_field(form.category, label=_('Select the category that best describes your Theme.'),
class='row radios addon-cats') }}
class='row radios addon-cats', validate=True) }}
<li class="row">
{{ pretty_field(form.tags, label=_('Add some tags to describe your Theme.'), tag=None, opt=True) }}
{{ pretty_field(form.tags, label=_('Add some tags to describe your Theme.'), tag=None, opt=True, validate=True) }}
<span class="note">
{{ ngettext('Comma-separated, minimum of {0} character.',
'Comma-separated, minimum of {0} characters.',
Expand All @@ -38,7 +38,7 @@ <h1>{{ title }}</h1>
basic functionality that is displayed in
search and browse listings, as well as at
the top of your theme's details page."),
tag=None, opt=True) }}
tag=None, opt=True, validate=True) }}
<div class="note">
{{ some_html_tip() }}
<span class="char-count" data-for="{{ form.summary.auto_id }}"
Expand Down Expand Up @@ -148,7 +148,7 @@ <h3>{{ _('Select a license for your Theme.') }}</h3>
<li id="persona-header" class="row">
{{ pretty_field(form.header, label=_('Select a header image for your Theme.'),
tag=None, req=True) }}
{{ form.header_hash }}
{{ form.header_hash.as_widget(attrs={'required': ''}) }}
{{ form.header_hash.errors }}
<ul class="note">
<li>{{ _('3000 &times; 200 pixels') }}</li>
Expand All @@ -164,7 +164,7 @@ <h3>{{ _('Select a license for your Theme.') }}</h3>
<li id="persona-footer" class="row">
{{ pretty_field(form.footer, label=_('Select a footer image for your Theme.'),
tag=None, req=True) }}
{{ form.footer_hash }}
{{ form.footer_hash.as_widget(attrs={'required': ''}) }}
{{ form.footer_hash.errors }}
<ul class="note">
<li>{{ _('3000 &times; 100 pixels') }}</li>
Expand All @@ -181,9 +181,11 @@ <h3>{{ _('Select a license for your Theme.') }}</h3>
<h3>{{ _('Select colors for your Theme.') }}</h3>
<ul class="colors">
{{ pretty_field(form.textcolor, label=_('Foreground Text'),
tooltip=_('This is the color of the tab text.')) }}
tooltip=_('This is the color of the tab text.'),
validate=True) }}
{{ pretty_field(form.accentcolor, label=_('Background'),
tooltip=_('This is the color of the tabs.')) }}
tooltip=_('This is the color of the tabs.'),
validate=True) }}
</ul>
</fieldset>
<fieldset id="persona-preview">
Expand All @@ -204,12 +206,16 @@ <h3>{{ _('Select colors for your Theme.') }}</h3>
</div>
</div>
</fieldset>
<p class="legal"><label><input type="checkbox" required>
{% trans tos_url='https://wiki.mozilla.org/Marketplace/Reviewers/Themes/TOS',
guidelines_url='https://wiki.mozilla.org/Marketplace/Reviewers/Themes/Guidelines' %}
By submitting your Theme, you agree to the <a href="{{ tos_url }}" target="_blank">Themes Terms of Service</a>. Your Theme is subject to approval according to the standards established in the <a href="{{ guidelines_url }}" target="_blank">Review Guidelines</a>.
{% endtrans %}
</label></p>
<p class="legal">
<label>
{{ form.agreed.as_widget(attrs={'required': ''}) }}
{% trans tos_url='https://wiki.mozilla.org/Marketplace/Reviewers/Themes/TOS',
guidelines_url='https://wiki.mozilla.org/Marketplace/Reviewers/Themes/Guidelines' %}
By submitting your Theme, you agree to the <a href="{{ tos_url }}" target="_blank">Themes Terms of Service</a>. Your Theme is subject to approval according to the standards established in the <a href="{{ guidelines_url }}" target="_blank">Review Guidelines</a>.
{% endtrans %}
</label>
{{ form.agreed.errors }}
</p>
<p class="listing-footer"><button class="button prominent" disabled type="submit">{{ _('Submit Theme') }}</button></p>
</form>
</div>
Expand Down
14 changes: 7 additions & 7 deletions apps/devhub/templates/devhub/personas/submit_done.html
Expand Up @@ -9,23 +9,23 @@ <h1>{{ _("You're done!") }}</h1>
<div class="prose">
<p>
{% trans %}
Your Persona has been submitted to the Review queue.
Your Theme has been submitted to the Review queue.
{% endtrans %}
</p>
{# TODO(cvan): The following is a lie. Personas cannot be installed before being reviewed - yet. #}
{# TODO(cvan): The following is a lie. Themes cannot be installed before being reviewed - yet. #}
<p>
{# TODO(cvan)(fligtar): Finalize copy. #}
You'll receive an email once your Persona has been reviewed by an editor.
You'll receive an email once your Theme has been reviewed by an editor.
</p>
<h2>{{ _('Next steps:') }}</h2>
<ul class="done-next-steps">
{# TODO(cvan): This should lead to the Persona Edit page. #}
{# TODO(cvan): This should lead to the Theme Edit page. #}
{% set edit_url = url('devhub.addons.edit', addon.slug) %}
<li>{{ _('Provide more details about your Persona by <a href="{0}">editing its listing</a>.')|f(edit_url)|safe }}</li>
<li>{{ _('Provide more details about your Theme by <a href="{0}">editing its listing</a>.')|f(edit_url)|safe }}</li>
{% set profile_url = addon.get_dev_url('profile') %}
<li>{{ _('Tell your users why you created this Persona in your <a href="{0}">Developer Profile</a>.')|f(profile_url)|safe }}</li>
<li>{{ _('Tell your users why you created this Theme in your <a href="{0}">Developer Profile</a>.')|f(profile_url)|safe }}</li>
{% set feed_url = url('devhub.feed', addon.slug) %}
<li>{{ _('View and subscribe to your Persona\'s <a href="{0}">activity feed</a> to stay updated on reviews, collections, and more.')|f(feed_url)|safe }}</li>
<li>{{ _('View and subscribe to your Theme\'s <a href="{0}">activity feed</a> to stay updated on reviews, collections, and more.')|f(feed_url)|safe }}</li>
<li>{{ _('View approximate review queue <a href="{0}">wait times</a>.')|f('https://forums.addons.mozilla.org/viewforum.php?f=21')|safe }}</li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/includes/forms.html
Expand Up @@ -11,14 +11,14 @@
{%- endmacro %}

{% macro pretty_field(field, label=None, tooltip=None, tag='li', req=None,
opt=False, choice=None, class='row') %}
opt=False, choice=None, class='row', validate=False) %}
{% if choice == None %}
{% set choice = field|is_choice_field %}
{% endif %}
{% if req == None %}
{% set req = field.field.required %}
{% endif %}
{% set attrs = {'required': ''} if req else {} %}
{% set attrs = {'required': ''} if req and validate else {} %}

{% if tag %}
<{{ tag }} class="{{ class }}{{ ' error' if field.errors }}">
Expand Down

0 comments on commit 1e706ca

Please sign in to comment.