Bug 604154 - [editpage] Support Information

This commit is contained in:
Gregory Koberger 2010-10-18 10:57:48 -07:00
Родитель b5b1914ded
Коммит 4800d56d3c
5 изменённых файлов: 160 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,5 @@
import re
from django import forms
import happyforms
@ -33,6 +35,33 @@ class AddonFormDetails(happyforms.ModelForm):
fields = ('description', 'default_locale', 'homepage')
class AddonFormSupport(happyforms.ModelForm):
support_url = forms.URLField(widget=TranslationTextInput)
support_email = forms.EmailField(widget=TranslationTextInput)
def save(self, addon, commit=False):
instance = self.instance
# If there's a GetSatisfaction URL entered, we'll extract the product
# and company name and save it to the DB.
gs_regex = "getsatisfaction\.com/(\w*)(?:/products/(\w*))?"
match = re.search(gs_regex, instance.support_url.localized_string)
company = product = None
if match:
company, product = match.groups()
instance.get_satisfaction_company = company
instance.get_satisfaction_product = product
return super(AddonFormSupport, self).save()
class Meta:
mode = Addon
fields = ('support_email', 'support_url')
class AddonForm(happyforms.ModelForm):
name = forms.CharField(widget=TranslationTextInput,)
homepage = forms.CharField(widget=TranslationTextInput,)

Просмотреть файл

@ -37,6 +37,10 @@
{% include 'devhub/includes/addon_edit_details.html' %}
</div>
<div class="edit-addon-section" id="edit-addon-support">
{% include 'devhub/includes/addon_edit_support.html' %}
</div>
</div>
</section>

Просмотреть файл

@ -0,0 +1,79 @@
{% from "devhub/includes/macros.html" import tip, empty_unless %}
<form method="post" action="{{ url('devhub.addons.section', addon.id, 'support', 'edit') }}">
<h3>
{{ _('Support Information') }}
{% if not editable %}
<a href="{{ url('devhub.addons.section', addon.id, 'support', 'edit') }}" class="button">
{{ _('Edit') }}</a>
{% endif %}
</h3>
<div class="item">
<div class="item_wrapper">
<table>
{# L10n: {0} is an addon name #}
<caption>{{ _('Support Information for {0}')|f(addon.name) }}</caption>
<tbody>
<tr>
<th>
{{ tip(_("Email"),
_("If you wish to display an e-mail address for support inquiries,
enter it here. If you have different addresses for each language,
multiple translations of this field can be added.")) }}
</th>
<td>
{% if editable %}
{{ form.support_email|safe }}
{{ form.support_email.errors|safe }}
{% else %}
{% call empty_unless(addon.support_email) %}
{{ addon.support_email }}
{% endcall %}
{% endif %}
</td>
</tr>
<tr>
<th>
{{ tip(_("Website"),
_("If your add-on has a support website or forum, enter its
address here. If your website is localized into other
languages, multiple translations of this field can be added. If
you use a GetSatisfaction URL, users will be able to interact with
a GetSatisfaction widget.")) }}
</th>
<td>
{% if editable %}
{{ form.support_url|safe }}
{{ form.support_url.errors|safe }}
{% else %}
{% call empty_unless(addon.support_url) %}
{{ addon.support_url }}
{% endcall %}
{% endif %}
</td>
</tr>
{% if addon.get_satisfaction_company and not editable %}
<tr>
<th>{{ _('Get Satisfaction') }}</th>
<td class="addon_edit_gs">
{{ addon.get_satisfaction_company }}
{% if addon.get_satisfaction_product %}
&raquo; {{ addon.get_satisfaction_product }}
{% endif %}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
{% if editable %}
<div class="listing-footer">
<button>{{ _('Save Changes') }}</button> {{ _('or') }}
<a href="{{ url('devhub.addons.section', addon.id, 'support') }}"
class="addon-edit-cancel">
{{ _('Cancel') }}</a>
</div>
{% endif %}
</div>
</form>

Просмотреть файл

@ -1,4 +1,5 @@
from decimal import Decimal
import re
import socket
from django.utils import translation
@ -560,14 +561,17 @@ class TestEdit(test_utils.TestCase):
self.addon = self.get_addon()
assert self.client.login(username='del@icio.us', password='password')
self.url = reverse('devhub.addons.edit', args=[self.addon.id])
self.url_basic = reverse('devhub.addons.section',
args=[self.addon.id, 'basic', 'edit'])
self.url_details = reverse('devhub.addons.section',
args=[self.addon.id, 'details', 'edit'])
def get_addon(self):
return Addon.objects.no_cache().get(id=3615)
def get_url(self, section, edit=False):
args = [self.addon.id, section]
if edit:
args.append('edit')
return reverse('devhub.addons.section', args=args)
def test_redirect(self):
# /addon/:id => /addon/:id/edit
r = self.client.get('/en-US/developers/addon/3615/', follow=True)
@ -581,7 +585,7 @@ class TestEdit(test_utils.TestCase):
slug='test_addon',
summary='new summary')
r = self.client.post(self.url_basic, data)
r = self.client.post(self.get_url('basic', True), data)
eq_(r.status_code, 200)
addon = self.get_addon()
@ -598,7 +602,7 @@ class TestEdit(test_utils.TestCase):
slug='test_slug',
summary='new summary')
r = self.client.post(self.url_basic, data)
r = self.client.post(self.get_url('basic', True), data)
eq_(r.status_code, 200)
self.assertFormError(r, 'form', 'slug', 'This slug is already in use.')
@ -609,7 +613,7 @@ class TestEdit(test_utils.TestCase):
slug=self.addon.slug,
summary=self.addon.summary)
r = self.client.post(self.url_basic, data)
r = self.client.post(self.get_url('basic', True), data)
eq_(r.status_code, 200)
self.assertFormError(r, 'form', 'name', 'This field is required.')
@ -619,7 +623,7 @@ class TestEdit(test_utils.TestCase):
default_locale='es-ES',
homepage='http://twitter.com/fligtarsmom')
r = self.client.post(self.url_details, data)
r = self.client.post(self.get_url('details', True), data)
eq_(r.status_code, 200)
addon = self.get_addon()
@ -630,14 +634,44 @@ class TestEdit(test_utils.TestCase):
addon = self.get_addon()
addon.update(default_locale='en-US')
url_details = reverse('devhub.addons.section',
args=[self.addon.id, 'details'])
r = self.client.get(self.get_url('details', False))
r = self.client.get(url_details)
doc = pq(r.content)
eq_(doc('.addon_edit_locale').eq(0).text(), "English (US)")
def test_edit_support(self):
data = dict(support_email='sjobs@apple.com',
support_url='http://apple.com/')
r = self.client.post(self.get_url('support', True), data)
eq_(r.status_code, 200)
addon = self.get_addon()
for k in data:
eq_(unicode(getattr(addon, k)), data[k])
def test_edit_support_getsatisfaction(self):
urls = [("getsatisfaction.com/abc/products/def", 'abcdef'), # GS URL
("getsatisfaction.com/abc/", 'abc'), # No company
("google.com", None)] # Delete GS
for (url, val) in urls:
data = dict(support_email='abc@def.com',
support_url=url)
r = self.client.post(self.get_url('support', True), data)
eq_(r.status_code, 200)
r = self.client.get(self.get_url('support', False))
doc = pq(r.content)
result = doc('.addon_edit_gs').eq(0).text()
result = re.sub('\W', '', result) if result else None
eq_(result, val)
class TestProfile(test_utils.TestCase):
fixtures = ['base/apps', 'base/users', 'base/addon_3615']

Просмотреть файл

@ -13,7 +13,7 @@ from tower import ugettext_lazy as _lazy
import amo.utils
from amo.decorators import login_required, post_required
from access import acl
from addons.forms import AddonFormBasic, AddonFormDetails
from addons.forms import AddonFormBasic, AddonFormDetails, AddonFormSupport
from addons.models import Addon, AddonUser, AddonLog
from addons.views import BaseFilter
from files.models import FileUpload
@ -233,7 +233,8 @@ def upload_detail(request, uuid):
@dev_required
def addons_section(request, addon_id, addon, section, editable=False):
models = {'basic': AddonFormBasic,
'details': AddonFormDetails}
'details': AddonFormDetails,
'support': AddonFormSupport}
if section not in models:
return http.HttpResponseNotFound()