0001-manager-support-for-saving-a-page-snapshot-with-a-la.patch
combo/data/migrations/0057_pagesnapshot_label.py | ||
---|---|---|
1 |
# Generated by Django 2.2.26 on 2022-07-06 12:14 |
|
2 | ||
3 |
from django.db import migrations, models |
|
4 | ||
5 | ||
6 |
class Migration(migrations.Migration): |
|
7 | ||
8 |
dependencies = [ |
|
9 |
('data', '0056_display_condition'), |
|
10 |
] |
|
11 | ||
12 |
operations = [ |
|
13 |
migrations.AddField( |
|
14 |
model_name='pagesnapshot', |
|
15 |
name='label', |
|
16 |
field=models.CharField(blank=True, max_length=150, verbose_name='Label'), |
|
17 |
), |
|
18 |
] |
combo/data/models.py | ||
---|---|---|
717 | 717 |
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True) |
718 | 718 |
comment = models.TextField(blank=True, null=True) |
719 | 719 |
serialization = JSONField(blank=True, default=dict) |
720 |
label = models.CharField(_('Label'), max_length=150, blank=True) |
|
720 | 721 | |
721 | 722 |
class Meta: |
722 | 723 |
ordering = ('-timestamp',) |
723 | 724 | |
724 | 725 |
@classmethod |
725 |
def take(cls, page, request=None, comment=None, deletion=False): |
|
726 |
snapshot = cls(page=page, comment=comment) |
|
726 |
def take(cls, page, request=None, comment=None, deletion=False, label=None):
|
|
727 |
snapshot = cls(page=page, comment=comment, label=label or '')
|
|
727 | 728 |
if request and not request.user.is_anonymous: |
728 | 729 |
snapshot.user = request.user |
729 | 730 |
if not deletion: |
combo/manager/forms.py | ||
---|---|---|
408 | 408 |
('fx-grid--t3', _('3 columns')), |
409 | 409 |
], |
410 | 410 |
) |
411 | ||
412 | ||
413 |
class PageSnapshotSaveForm(forms.Form): |
|
414 |
label = forms.CharField(label=_('Label'), max_length=150, required=True) |
combo/manager/templates/combo/page_history.html | ||
---|---|---|
16 | 16 |
{% block content %} |
17 | 17 | |
18 | 18 |
<div> |
19 |
<ul class="objects-list"> |
|
20 |
{% for snapshot in object_list %} |
|
21 |
<li>{{ snapshot.timestamp }}, {{ snapshot.comment }} |
|
22 |
{% if snapshot.user %} ({{ snapshot.user.get_full_name }}){% endif %} |
|
23 |
— <a href="{% url 'combo-snapshot-view' pk=snapshot.id %}">{% trans "view" %}</a> |
|
24 |
— <a href="{% url 'combo-manager-snapshot-export' page_pk=view.page.id pk=snapshot.id %}">{% trans "export" %}</a> |
|
25 |
— <a href="{% url 'combo-manager-snapshot-restore' page_pk=view.page.id pk=snapshot.id %}" rel="popup">{% trans "restore" %}</a> |
|
26 |
</li> |
|
27 |
{% endfor %} |
|
28 |
</ul> |
|
19 |
<table class="main"> |
|
20 |
<thead> |
|
21 |
<th>{% trans 'Date' %}</th> |
|
22 |
<th>{% trans 'Description' %}</th> |
|
23 |
<th>{% trans 'User' %}</th> |
|
24 |
<th>{% trans 'Actions' %}</th> |
|
25 |
</thead> |
|
26 |
<tbody> |
|
27 |
{% for snapshot in object_list %} |
|
28 |
<tr> |
|
29 |
<td> |
|
30 |
{{ snapshot.timestamp }} |
|
31 |
</td> |
|
32 |
<td> |
|
33 |
{% if snapshot.label %} |
|
34 |
<strong>{{ snapshot.label }}</strong> |
|
35 |
{% elif snapshot.comment %} |
|
36 |
{{ snapshot.comment }} |
|
37 |
{% endif %} |
|
38 |
</td> |
|
39 |
<td>{% if snapshot.user %} {{ snapshot.user.get_full_name }}{% endif %}</td> |
|
40 |
<td> |
|
41 |
<a href="{% url 'combo-snapshot-view' pk=snapshot.id %}">{% trans "view" %}</a> |
|
42 |
— <a href="{% url 'combo-manager-snapshot-export' page_pk=view.page.id pk=snapshot.id %}">{% trans "export" %}</a> |
|
43 |
— <a href="{% url 'combo-manager-snapshot-restore' page_pk=view.page.id pk=snapshot.id %}" rel="popup">{% trans "restore" %}</a> |
|
44 |
</td> |
|
45 |
</tr> |
|
46 |
{% endfor %} |
|
47 |
</tbody> |
|
48 |
</table> |
|
29 | 49 | |
30 | 50 |
{% include "gadjo/pagination.html" %} |
31 | 51 |
combo/manager/templates/combo/page_view.html | ||
---|---|---|
16 | 16 |
<li><a class="action-add-child" rel="popup" href="{% url 'combo-manager-page-add-child' pk=object.id %}">{% trans 'Add a child page' %}</a></li> |
17 | 17 |
<li><a class="action-edit-roles" rel="popup" href="{% url 'combo-manager-page-edit-roles' pk=object.id %}">{% trans 'Manage edit roles' %}</a></li> |
18 | 18 |
<li><a rel="popup" class="action-duplicate" href="{% url 'combo-manager-page-duplicate' pk=object.id %}">{% trans 'Duplicate' %}</a></li> |
19 |
<li><a rel="popup" class="action-save" href="{% url 'combo-manager-page-save' pk=object.id %}">{% trans 'Save snapshot' %}</a></li> |
|
19 | 20 |
<li><a class="action-delete" rel="popup" href="{% url 'combo-manager-page-delete' pk=object.id %}">{% trans 'Delete' %}</a></li> |
20 | 21 |
{% endif %} |
21 | 22 |
</ul> |
combo/manager/templates/combo/snapshot_save.html | ||
---|---|---|
1 |
{% extends "combo/manager_base.html" %} |
|
2 |
{% load i18n %} |
|
3 |
{% load cells %} |
|
4 |
{% load thumbnail %} |
|
5 | ||
6 |
{% block appbar %} |
|
7 |
<h2>{% trans 'Save Page' %} - {{ page.title }}</h2> |
|
8 |
{% endblock %} |
|
9 | ||
10 |
{% block breadcrumb %} |
|
11 |
{{ block.super }} |
|
12 |
<a href="{% url 'combo-manager-page-view' pk=page.id %}">{% trans 'Page' %} - {{page.title }}</a> |
|
13 |
{% endblock %} |
|
14 | ||
15 |
{% block content %} |
|
16 |
<form method="post"> |
|
17 |
{% csrf_token %} |
|
18 |
{{ form.as_p }} |
|
19 |
<div class="buttons"> |
|
20 |
<button class="submit-button">{% trans 'Save' %}</button> |
|
21 |
<a class="cancel" href="{% url 'combo-manager-page-view' pk=page.id %}">{% trans 'Cancel' %}</a> |
|
22 |
</div> |
|
23 |
</form> |
|
24 |
{% endblock %} |
combo/manager/urls.py | ||
---|---|---|
85 | 85 |
pages_admin_required(views.page_duplicate), |
86 | 86 |
name='combo-manager-page-duplicate', |
87 | 87 |
), |
88 |
url( |
|
89 |
r'^pages/(?P<pk>\d+)/save', |
|
90 |
pages_admin_required(views.snapshot_save), |
|
91 |
name='combo-manager-page-save', |
|
92 |
), |
|
88 | 93 |
url( |
89 | 94 |
r'^pages/(?P<pk>\d+)/edit-roles/$', |
90 | 95 |
pages_admin_required(views.page_edit_roles), |
combo/manager/views.py | ||
---|---|---|
83 | 83 |
PageExportForm, |
84 | 84 |
PageRestrictedAddForm, |
85 | 85 |
PageSelectTemplateForm, |
86 |
PageSnapshotSaveForm, |
|
86 | 87 |
PageVisibilityForm, |
87 | 88 |
PlaceholderOptionsForm, |
88 | 89 |
SiteExportForm, |
... | ... | |
644 | 645 |
return response |
645 | 646 | |
646 | 647 | |
648 |
class SnapshotSaveView(ManagedPageMixin, FormView): |
|
649 |
form_class = PageSnapshotSaveForm |
|
650 |
template_name = 'combo/snapshot_save.html' |
|
651 | ||
652 |
def get_success_url(self): |
|
653 |
return reverse('combo-manager-page-view', kwargs={'pk': self.page.pk}) |
|
654 | ||
655 |
def get_context_data(self, **kwargs): |
|
656 |
context = super().get_context_data(**kwargs) |
|
657 |
context['page'] = self.page |
|
658 |
return context |
|
659 | ||
660 |
def form_valid(self, form): |
|
661 |
PageSnapshot.take(self.page, request=self.request, label=form.cleaned_data['label']) |
|
662 |
messages.info(self.request, _('Snapshot "%s" has been saved.') % form.cleaned_data['label']) |
|
663 |
return super().form_valid(form) |
|
664 | ||
665 | ||
666 |
snapshot_save = SnapshotSaveView.as_view() |
|
667 | ||
668 | ||
647 | 669 |
class PageRedirectToEditView(RedirectView): |
648 | 670 |
permanent = False |
649 | 671 |
tests/test_manager.py | ||
---|---|---|
2510 | 2510 |
resp2 = resp.click('See online') |
2511 | 2511 |
assert resp2.text.index('Foobar1') < resp2.text.index('Foobar2') < resp2.text.index('Foobar3') |
2512 | 2512 | |
2513 |
# save snapshot with a label |
|
2514 |
app = login(app) |
|
2515 |
resp = app.get('/manage/pages/%s/' % page.id, status=200) |
|
2516 |
resp = resp.click('Save snapshot') |
|
2517 |
resp.form['label'] = 'CGUv1' |
|
2518 |
resp = resp.form.submit().follow() |
|
2519 |
assert page.pagesnapshot_set.latest('pk').label == 'CGUv1' |
|
2520 | ||
2513 | 2521 |
# clean it up |
2514 | 2522 |
Page.snapshots.all().delete() |
2515 | 2523 |
assert Page.objects.count() == 1 |
2516 |
- |