application: add documentation_url field (#69662)
gitea-wip/hobo/pipeline/head There was a failure building this commit Details
gitea/hobo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-10-21 09:28:04 +02:00
parent 89b9a5285d
commit 0165713e53
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
6 changed files with 38 additions and 7 deletions

View File

@ -32,7 +32,7 @@ class InstallForm(forms.Form):
class MetadataForm(forms.ModelForm):
class Meta:
model = Application
fields = ['name', 'slug', 'description', 'icon']
fields = ['name', 'slug', 'description', 'documentation_url', 'icon']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -0,0 +1,16 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('applications', '0005_version_num_notes'),
]
operations = [
migrations.AddField(
model_name='application',
name='documentation_url',
field=models.URLField(blank=True, verbose_name='Documentation URL'),
),
]

View File

@ -48,6 +48,7 @@ class Application(models.Model):
null=True,
)
description = models.TextField(verbose_name=_('Description'), blank=True)
documentation_url = models.URLField(_('Documentation URL'), blank=True)
editable = models.BooleanField(default=True)
elements = models.ManyToManyField('Element', blank=True, through='Relation')
creation_timestamp = models.DateTimeField(default=now)

View File

@ -29,6 +29,7 @@
{{ application.name }}
</h3>
<p>{{ application.description|default:""|linebreaksbr }}</p>
{% if application.documentation_url %}<p><a href="{{ application.documentation_url }}">{% trans 'Documentation' %}</a></p>{% endif %}
{% if application.editable %}
<div class="buttons">
<a class="button" href="{% url 'application-manifest' app_slug=application.slug %}"

View File

@ -255,8 +255,9 @@ class GenerateView(FormView):
manifest_json = {
'application': app.name,
'slug': app.slug,
'description': app.description,
'icon': os.path.basename(app.icon.name) if app.icon.name else None,
'description': app.description,
'documentation_url': app.documentation_url,
'version_number': version.number,
'version_notes': version.notes,
'elements': [],
@ -332,6 +333,7 @@ class Install(FormView):
)
app.name = manifest.get('application')
app.description = manifest.get('description')
app.documentation_url = manifest.get('documentation_url') or ''
if created:
# mark as non-editable only newly deployed applications, this allows
# overwriting a local application and keep on developing it.

View File

@ -186,8 +186,11 @@ def test_create_application(app, admin_user, settings, analyze):
# edit metadata
resp = resp.click('Metadata')
resp.form['description'] = 'Lorem ipsum'
resp.form['documentation_url'] = 'http://foo.bar'
resp = resp.form.submit().follow()
assert Application.objects.get(slug='test').icon.name == ''
application = Application.objects.get(slug='test')
assert application.icon.name == ''
assert application.documentation_url == 'http://foo.bar'
# add forms
assert '/add/forms/' in resp
@ -196,8 +199,8 @@ def test_create_application(app, admin_user, settings, analyze):
assert resp.form.fields['elements'][1]._value == 'test2-form'
resp.form.fields['elements'][0].checked = True
resp = resp.form.submit().follow()
assert Application.objects.get(slug='test').elements.count() == 1
element = Application.objects.get(slug='test').elements.all()[0]
assert application.elements.count() == 1
element = application.elements.all()[0]
assert element.slug == 'test-form'
assert 'Test Card' not in resp.text
@ -219,6 +222,7 @@ def test_create_application(app, admin_user, settings, analyze):
assert b'<formdef/>' in resp.content
assert b'<carddef/>' in resp.content
assert b'"icon": null' in resp.content
assert b'"documentation_url": "http://foo.bar"' in resp.content
assert b'"version_number": "1.0"' in resp.content
assert b'"version_notes": "Foo bar blah."' in resp.content
@ -256,15 +260,19 @@ def test_create_application(app, admin_user, settings, analyze):
),
'image/png',
)
resp.form['documentation_url'] = '' # and reset documentation_url
resp = resp.form.submit().follow()
assert re.match(r'applications/icons/foo(_\w+)?.png', Application.objects.get(slug='test').icon.name)
application.refresh_from_db()
assert re.match(r'applications/icons/foo(_\w+)?.png', application.icon.name)
assert application.documentation_url == ''
# try an icon in an invalid format
resp = app.get('/applications/manifest/test/metadata/')
resp.form['icon'] = Upload('test.txt', b'hello', 'text/plain')
resp = resp.form.submit()
assert 'The icon must be in JPEG or PNG format' in resp
assert re.match(r'applications/icons/foo(_\w+)?.png', Application.objects.get(slug='test').icon.name)
application.refresh_from_db()
assert re.match(r'applications/icons/foo(_\w+)?.png', application.icon.name)
resp = app.get('/applications/manifest/test/')
resp = resp.click('Generate application bundle')
@ -277,6 +285,7 @@ def test_create_application(app, admin_user, settings, analyze):
assert b'<formdef/>' in resp.content
assert b'<carddef/>' in resp.content
assert b'"icon": "foo' in resp.content
assert b'"documentation_url": ""' in resp.content
assert b'"version_number": "2.0"' in resp.content
assert b'"version_notes": "Foo bar blah. But with an icon."' in resp.content
version = Version.objects.latest('pk')
@ -412,6 +421,7 @@ def get_bundle(with_icon=False):
'slug': 'test',
'icon': 'foo.png' if with_icon else None,
'description': '',
'documentation_url': 'http://foo.bar',
'version_number': '42.0',
'version_notes': 'foo bar blah',
'elements': [
@ -467,6 +477,7 @@ def test_deploy_application(app, admin_user, settings, app_bundle, app_bundle_wi
assert re.match(r'applications/icons/foo(_\w+)?.png', app.icon.name)
else:
assert app.icon.name == ''
assert app.documentation_url == 'http://foo.bar'
assert app.version_set.count() == i + 1
version = app.version_set.all()[i]
assert version.number == '42.0'