From 07561c1782b0c169ccf10a98d17981935826a3d3 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Thu, 26 Sep 2019 20:37:02 +0200 Subject: [PATCH] Various general clean-ups, including templates. --- src/wiki/models/article.py | 11 +++++++---- src/wiki/plugins/attachments/forms.py | 11 +++-------- .../images/templates/wiki/plugins/images/sidebar.html | 7 +------ src/wiki/sites.py | 1 - src/wiki/templates/wiki/base_site.html | 8 +------- src/wiki/templates/wiki/create_root.html | 4 +++- src/wiki/templates/wiki/edit.html | 2 +- src/wiki/templates/wiki/history.html | 2 +- src/wiki/templates/wiki/includes/breadcrumbs.html | 2 +- src/wiki/templates/wiki/includes/searchresult.html | 2 +- src/wiki/views/accounts.py | 2 +- tests/base.py | 10 ++++------ tests/core/test_checks.py | 4 ++-- tests/core/test_views.py | 2 +- 14 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/wiki/models/article.py b/src/wiki/models/article.py index 393210f1..618e2f2c 100644 --- a/src/wiki/models/article.py +++ b/src/wiki/models/article.py @@ -171,7 +171,8 @@ class Article(models.Model): def get_for_object(cls, obj): return ArticleForObject.objects.get( object_id=obj.id, - content_type=ContentType.objects.get_for_model(obj)).article + content_type=ContentType.objects.get_for_model(obj), + ).article def __str__(self): if self.current_revision: @@ -193,9 +194,11 @@ class Article(models.Model): content = preview_content else: content = self.current_revision.content - return mark_safe(article_markdown(content, self, - preview=preview_content is not None, - user=user)) + return mark_safe(article_markdown( + content, self, + preview=preview_content is not None, + user=user) + ) def get_cache_key(self): """Returns per-article cache key.""" diff --git a/src/wiki/plugins/attachments/forms.py b/src/wiki/plugins/attachments/forms.py index 1215e6af..8de0046b 100644 --- a/src/wiki/plugins/attachments/forms.py +++ b/src/wiki/plugins/attachments/forms.py @@ -133,8 +133,7 @@ class AttachmentArchiveForm(AttachmentForm): attachment.articles.add(self.article) attachment_revision = models.AttachmentRevision() attachment_revision.file = f - attachment_revision.description = self.cleaned_data[ - 'description'] + attachment_revision.description = self.cleaned_data['description'] attachment_revision.attachment = attachment attachment_revision.set_from_request(self.request) attachment_revision.save() @@ -153,10 +152,8 @@ class AttachmentArchiveForm(AttachmentForm): class DeleteForm(forms.Form): - """This form is both used for dereferencing and deleting attachments""" - confirm = forms.BooleanField(label=_('Yes I am sure...'), - required=False) + confirm = forms.BooleanField(label=_('Yes I am sure...'), required=False) def clean_confirm(self): if not self.cleaned_data['confirm']: @@ -168,7 +165,5 @@ class SearchForm(forms.Form): query = forms.CharField( label="", - widget=forms.TextInput( - attrs={ - 'class': 'search-query form-control'}), + widget=forms.TextInput(attrs={'class': 'search-query form-control'}), ) diff --git a/src/wiki/plugins/images/templates/wiki/plugins/images/sidebar.html b/src/wiki/plugins/images/templates/wiki/plugins/images/sidebar.html index 909bf6c9..cd711f22 100644 --- a/src/wiki/plugins/images/templates/wiki/plugins/images/sidebar.html +++ b/src/wiki/plugins/images/templates/wiki/plugins/images/sidebar.html @@ -46,7 +46,7 @@ function add_image(form) { {% with image.current_revision.imagerevision as revision %} {% thumbnail revision.image "50x50" crop="center" as thumb %} - +

{% trans "Image id" %}: {{ image.id }}

{% trans "Insert" %}
@@ -98,11 +98,6 @@ function add_image(form) {

{% for field in form.visible_fields %}

- {% if field.label %} - - {% endif %} {{ field }} {% if field.errors %}
diff --git a/src/wiki/sites.py b/src/wiki/sites.py index fbfb824c..9d5f9ed3 100644 --- a/src/wiki/sites.py +++ b/src/wiki/sites.py @@ -7,7 +7,6 @@ from wiki.core.plugins import registry class WikiSite: - """ Wiki site configurator. diff --git a/src/wiki/templates/wiki/base_site.html b/src/wiki/templates/wiki/base_site.html index d025e53c..a104ff08 100644 --- a/src/wiki/templates/wiki/base_site.html +++ b/src/wiki/templates/wiki/base_site.html @@ -12,12 +12,6 @@ {% render_block "css" %} - - - - @@ -145,7 +139,7 @@ {% block wiki_footer_prepend %} {% endblock %}

{% blocktrans %}Powered by django-wiki, an open source application under the GPLv3 license. Let knowledge be the cure.{% endblocktrans %}

-
+
diff --git a/src/wiki/templates/wiki/create_root.html b/src/wiki/templates/wiki/create_root.html index 73a14ae0..e75ceb90 100644 --- a/src/wiki/templates/wiki/create_root.html +++ b/src/wiki/templates/wiki/create_root.html @@ -32,7 +32,9 @@
- +
diff --git a/src/wiki/templates/wiki/edit.html b/src/wiki/templates/wiki/edit.html index aa9ee032..545a1970 100644 --- a/src/wiki/templates/wiki/edit.html +++ b/src/wiki/templates/wiki/edit.html @@ -63,7 +63,7 @@ -
+
{% include "wiki/includes/modals.html" %} diff --git a/src/wiki/templates/wiki/history.html b/src/wiki/templates/wiki/history.html index d7a3a4da..f1c34e31 100644 --- a/src/wiki/templates/wiki/history.html +++ b/src/wiki/templates/wiki/history.html @@ -95,7 +95,7 @@ {% endif %} -
+
diff --git a/src/wiki/templates/wiki/includes/breadcrumbs.html b/src/wiki/templates/wiki/includes/breadcrumbs.html index b7a8aeae..d783e21e 100644 --- a/src/wiki/templates/wiki/includes/breadcrumbs.html +++ b/src/wiki/templates/wiki/includes/breadcrumbs.html @@ -56,6 +56,6 @@
-
+
{% endif %} diff --git a/src/wiki/templates/wiki/includes/searchresult.html b/src/wiki/templates/wiki/includes/searchresult.html index f6dd7a09..40547344 100644 --- a/src/wiki/templates/wiki/includes/searchresult.html +++ b/src/wiki/templates/wiki/includes/searchresult.html @@ -16,7 +16,7 @@ {% endif %}

{{ article.render|get_content_snippet:search_query }}

- + {{ article.current_revision.created|naturaltime }} diff --git a/src/wiki/views/accounts.py b/src/wiki/views/accounts.py index 47333099..78ed29ff 100644 --- a/src/wiki/views/accounts.py +++ b/src/wiki/views/accounts.py @@ -131,7 +131,7 @@ class Update(UpdateView): def form_valid(self, form): pw = form.cleaned_data["password1"] - if pw is not "": + if pw != "": self.object.set_password(pw) self.object.save() diff --git a/tests/base.py b/tests/base.py index 3f058bb6..46fc9086 100644 --- a/tests/base.py +++ b/tests/base.py @@ -71,8 +71,7 @@ class WebTestCommonMixin(RequireBasicData, django_functest.ShortcutLoginMixin): def setUp(self): super().setUp() - self.shortcut_login(username=SUPERUSER1_USERNAME, - password=SUPERUSER1_PASSWORD) + self.shortcut_login(username=SUPERUSER1_USERNAME, password=SUPERUSER1_PASSWORD) class WebTestBase(WebTestCommonMixin, django_functest.FuncWebTestMixin, TestCase): @@ -88,7 +87,7 @@ class SeleniumBase(WebTestCommonMixin, django_functest.FuncSeleniumMixin, Static display = os.environ.get('SELENIUM_SHOW_BROWSER', '0') == '1' if not INCLUDE_SELENIUM_TESTS: - # Don't call super() in setUpClass(), it will attempt to instatiate + # Don't call super() in setUpClass(), it will attempt to instantiate # a browser instance which is slow and might fail @classmethod def setUpClass(cls): @@ -106,7 +105,6 @@ class ArticleWebTestUtils: Get the article response for the path. Example: self.get_by_path("Level1/Slug2/").title """ - return self.client.get(reverse('wiki:get', kwargs={'path': path})) @@ -125,11 +123,11 @@ class TemplateTestCase(TestCase): class wiki_override_settings(override_settings): def enable(self): - super(wiki_override_settings, self).enable() + super().enable() self.reload_wiki_settings() def disable(self): - super(wiki_override_settings, self).disable() + super().disable() self.reload_wiki_settings() def reload_wiki_settings(self): diff --git a/tests/core/test_checks.py b/tests/core/test_checks.py index 07acf8b7..bea9d82a 100644 --- a/tests/core/test_checks.py +++ b/tests/core/test_checks.py @@ -45,10 +45,10 @@ class CheckTests(TestCase): def test_custom_user_model_mitigation_required(self): """ - Django & six check django.forms.ModelForm.Meta on definition, and raises an error if Meta.fields don't exist in Meta.model. + Django check django.forms.ModelForm.Meta on definition, and raises an error if Meta.fields don't exist in Meta.model. This causes problems in wiki.forms.UserCreationForm and wiki.forms.UserUpdateForm when a custom user model doesn't have fields django-wiki assumes. There is some code in wiki.forms that detects this situation. - This check asserts that Django/six are still raising an exception on definition, and asserts the mitigation code in wiki.forms, + This check asserts that Django are still raising an exception on definition, and asserts the mitigation code in wiki.forms, and that test_check_for_fields_in_custom_user_model below are required. """ from django.core.exceptions import FieldError diff --git a/tests/core/test_views.py b/tests/core/test_views.py index d85c0327..e6287e90 100644 --- a/tests/core/test_views.py +++ b/tests/core/test_views.py @@ -27,7 +27,7 @@ class RootArticleViewTestsBase(FuncBaseMixin): '#id_content': 'test heading h1\n====\n', '#id_title': 'Wiki Test', }) - self.submit('input[name="save_changes"]') + self.submit('button[name="save_changes"]') self.assertUrlsEqual('/') self.assertTextPresent('test heading h1') article = URLPath.root().article -- 2.45.2