0001-applications-add-link-to-hide-applications-63273.patch
hobo/applications/migrations/0002_application_hidden.py | ||
---|---|---|
1 |
# Generated by Django 2.2.24 on 2022-03-29 10:00 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('applications', '0001_initial'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.AddField( |
|
14 |
model_name='application', |
|
15 |
name='hidden', |
|
16 |
field=models.BooleanField(default=False), |
|
17 |
), |
|
18 |
] |
hobo/applications/models.py | ||
---|---|---|
40 | 40 |
editable = models.BooleanField(default=True) |
41 | 41 |
elements = models.ManyToManyField('Element', blank=True, through='Relation') |
42 | 42 |
creation_timestamp = models.DateTimeField(default=now) |
43 |
hidden = models.BooleanField(default=False) |
|
43 | 44 |
last_update_timestamp = models.DateTimeField(auto_now=True) |
44 | 45 | |
45 | 46 |
def __repr__(self): |
hobo/applications/templates/hobo/applications/app_confirm_delete.html | ||
---|---|---|
1 |
{% extends "hobo/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>{% blocktrans with title=object.name %}Removal of "{{ title }}"{% endblocktrans %}</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block content %} |
|
9 |
<form method="post"> |
|
10 |
{% csrf_token %} |
|
11 |
<p> |
|
12 |
{% trans 'Are you sure you want to remove this application ?' %} |
|
13 |
</p> |
|
14 |
<div class="buttons"> |
|
15 |
<button class="delete-button">{% trans 'Delete' %}</button> |
|
16 |
<a class="cancel" href="{% url 'application-manifest' app_slug=view.kwargs.slug %}">{% trans 'Cancel' %}</a> |
|
17 |
</div> |
|
18 |
</form> |
|
19 |
{% endblock %} |
hobo/applications/urls.py | ||
---|---|---|
22 | 22 |
url(r'^$', views.home, name='applications-home'), |
23 | 23 |
url(r'^create/$', views.init, name='application-init'), |
24 | 24 |
url(r'^install/$', views.install, name='application-install'), |
25 |
url(r'^manifest/(?P<slug>[\w-]+)/delete/$', views.delete, name='application-delete'), |
|
25 | 26 |
url(r'^manifest/(?P<app_slug>[\w-]+)/$', views.manifest, name='application-manifest'), |
26 | 27 |
url(r'^manifest/(?P<app_slug>[\w-]+)/metadata/$', views.metadata, name='application-metadata'), |
27 | 28 |
url(r'^manifest/(?P<app_slug>[\w-]+)/scandeps/$', views.scandeps, name='application-scandeps'), |
hobo/applications/views.py | ||
---|---|---|
40 | 40 |
model = Application |
41 | 41 | |
42 | 42 |
def get_queryset(self): |
43 |
return super().get_queryset().order_by('name') |
|
43 |
return super().get_queryset().filter(hidden=False).order_by('name')
|
|
44 | 44 | |
45 | 45 | |
46 | 46 |
home = HomeView.as_view() |
... | ... | |
298 | 298 | |
299 | 299 | |
300 | 300 |
install = Install.as_view() |
301 | ||
302 | ||
303 |
class AppDeleteView(DeleteView): |
|
304 |
model = Application |
|
305 |
template_name = 'hobo/applications/app_confirm_delete.html' |
|
306 | ||
307 |
def post(self, request, *args, **kwargs): |
|
308 |
self.object = self.get_object() |
|
309 |
success_url = self.get_success_url() |
|
310 |
self.object.hidden = True |
|
311 |
self.object.save() |
|
312 |
return HttpResponseRedirect(success_url) |
|
313 | ||
314 |
def get_success_url(self): |
|
315 |
return reverse('applications-home') |
|
316 | ||
317 | ||
318 |
delete = AppDeleteView.as_view() |
tests/test_application.py | ||
---|---|---|
178 | 178 |
assert b'<carddef/>' in resp.content |
179 | 179 | |
180 | 180 | |
181 |
def test_delete_application(app, admin_user, settings): |
|
182 |
Wcs.objects.create(base_url='https://wcs.example.invalid', slug='foobar', title='Foobar') |
|
183 | ||
184 |
settings.KNOWN_SERVICES = { |
|
185 |
'wcs': { |
|
186 |
'foobar': { |
|
187 |
'title': 'Foobar', |
|
188 |
'url': 'https://wcs.example.invalid/', |
|
189 |
'orig': 'example.org', |
|
190 |
'secret': 'xxx', |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 | ||
195 |
login(app) |
|
196 | ||
197 |
Application.objects.create(name='AppToDelete', slug='app_to_delete') |
|
198 |
Application.objects.create(name='OtherApp', slug='other_app') |
|
199 | ||
200 |
filtered_applications = Application.objects.filter(hidden=False) |
|
201 |
assert filtered_applications.count() == 2 |
|
202 | ||
203 |
resp = app.get('/applications/manifest/app_to_delete/delete/') |
|
204 | ||
205 |
resp = resp.forms[0].submit() |
|
206 |
resp = resp.follow() |
|
207 | ||
208 |
assert '/applications/' in resp |
|
209 |
assert 'AppToDelete' not in resp.text |
|
210 | ||
211 |
assert filtered_applications.count() == 1 |
|
212 |
assert filtered_applications[0].name == 'OtherApp' |
|
213 | ||
214 | ||
181 | 215 |
@pytest.fixture |
182 | 216 |
def app_bundle(): |
183 | 217 |
tar_io = io.BytesIO() |
184 |
- |