diff --git a/.gitignore b/.gitignore index bbcfe75..8e44d11 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ logfile # Sublime Text *.sublime-workspace *.sublime-project + +# test media upload +media diff --git a/djadmin2/themes/djadmin2theme_default/templates/djadmin2theme_default/model_update_form.html b/djadmin2/themes/djadmin2theme_default/templates/djadmin2theme_default/model_update_form.html index 8d25010..a613705 100644 --- a/djadmin2/themes/djadmin2theme_default/templates/djadmin2theme_default/model_update_form.html +++ b/djadmin2/themes/djadmin2theme_default/templates/djadmin2theme_default/model_update_form.html @@ -42,7 +42,7 @@ {% block content %} -
+ {% if view.model_admin.save_on_top %} {% include "djadmin2theme_default/includes/save_buttons.html" %} diff --git a/example/blog/tests/test_views.py b/example/blog/tests/test_views.py index a91c3eb..9d31b97 100644 --- a/example/blog/tests/test_views.py +++ b/example/blog/tests/test_views.py @@ -356,6 +356,7 @@ class PostDetailViewTest(BaseIntegrationTest): class PostCreateViewTest(BaseIntegrationTest): def test_view_ok(self): response = self.client.get(reverse("admin2:blog_post_create")) + self.assertNotIn('''enctype="multipart/form-data"''', response.content) self.assertEqual(response.status_code, 200) def test_create_post(self): diff --git a/example/example/settings.py b/example/example/settings.py index 8633e1d..161a76f 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -129,6 +129,7 @@ INSTALLED_APPS = ( 'djadmin2', 'djadmin2.themes.djadmin2theme_default', 'blog', + 'files', ) # A sample logging configuration. The only tangible logging diff --git a/example/files/__init__.py b/example/files/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/example/files/admin.py b/example/files/admin.py new file mode 100644 index 0000000..1629d51 --- /dev/null +++ b/example/files/admin.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from __future__ import division, absolute_import, unicode_literals + +from django.contrib import admin + +from .models import CaptionedFile, UncaptionedFile + + +admin.site.register(CaptionedFile) +admin.site.register(UncaptionedFile) diff --git a/example/files/admin2.py b/example/files/admin2.py new file mode 100644 index 0000000..1e6016e --- /dev/null +++ b/example/files/admin2.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from __future__ import division, absolute_import, unicode_literals + +import djadmin2 + +from .models import CaptionedFile, UncaptionedFile + + +djadmin2.default.register(CaptionedFile) +djadmin2.default.register(UncaptionedFile) diff --git a/example/files/locale/de/LC_MESSAGES/django.mo b/example/files/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000..77c46d9 Binary files /dev/null and b/example/files/locale/de/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/de/LC_MESSAGES/django.po b/example/files/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..edbd7d9 --- /dev/null +++ b/example/files/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,51 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# dbrgn , 2013 +# Jannis Leidel , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-08 08:49+0000\n" +"Last-Translator: dbrgn \n" +"Language-Team: German (http://www.transifex.com/projects/p/django-admin2/" +"language/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Beispiel Start" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(für's Protokoll)" diff --git a/example/files/locale/en/LC_MESSAGES/django.mo b/example/files/locale/en/LC_MESSAGES/django.mo new file mode 100644 index 0000000..b308414 Binary files /dev/null and b/example/files/locale/en/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/en/LC_MESSAGES/django.po b/example/files/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000..f0f95ad --- /dev/null +++ b/example/files/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,46 @@ +# This file is distributed under the same license as the django-admin2 package. +# +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-09 11:57+0200\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "" diff --git a/example/files/locale/fr/LC_MESSAGES/django.mo b/example/files/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 0000000..9d65870 Binary files /dev/null and b/example/files/locale/fr/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/fr/LC_MESSAGES/django.po b/example/files/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..389b0a2 --- /dev/null +++ b/example/files/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,51 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# NotSqrt , 2013. +# +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: NotSqrt \n" +"Language-Team: French (http://www.transifex.com/projects/p/django-admin2/" +"language/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Exemple de page d'accueil" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(pour référence)" diff --git a/example/files/locale/it/LC_MESSAGES/django.mo b/example/files/locale/it/LC_MESSAGES/django.mo new file mode 100644 index 0000000..86084e6 Binary files /dev/null and b/example/files/locale/it/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/it/LC_MESSAGES/django.po b/example/files/locale/it/LC_MESSAGES/django.po new file mode 100644 index 0000000..935bd6c --- /dev/null +++ b/example/files/locale/it/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# brente , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-07 17:47+0000\n" +"Last-Translator: brente \n" +"Language-Team: Italian (http://www.transifex.com/projects/p/django-admin2/" +"language/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(per riferimento)" diff --git a/example/files/locale/nl/LC_MESSAGES/django.mo b/example/files/locale/nl/LC_MESSAGES/django.mo new file mode 100644 index 0000000..f0da8b3 Binary files /dev/null and b/example/files/locale/nl/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/nl/LC_MESSAGES/django.po b/example/files/locale/nl/LC_MESSAGES/django.po new file mode 100644 index 0000000..cea1118 --- /dev/null +++ b/example/files/locale/nl/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# Density21.5 , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-08 10:46+0000\n" +"Last-Translator: Density21.5 \n" +"Language-Team: Dutch (http://www.transifex.com/projects/p/django-admin2/" +"language/nl/)\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Voorbeeld Home" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(ter verwijzing)" diff --git a/example/files/locale/pl_PL/LC_MESSAGES/django.mo b/example/files/locale/pl_PL/LC_MESSAGES/django.mo new file mode 100644 index 0000000..9dbd093 Binary files /dev/null and b/example/files/locale/pl_PL/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/pl_PL/LC_MESSAGES/django.po b/example/files/locale/pl_PL/LC_MESSAGES/django.po new file mode 100644 index 0000000..5a485c4 --- /dev/null +++ b/example/files/locale/pl_PL/LC_MESSAGES/django.po @@ -0,0 +1,52 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# dasm , 2013 +# Marcin Jabrzyk , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-08 18:04+0000\n" +"Last-Translator: dasm \n" +"Language-Team: Polish (Poland) (http://www.transifex.com/projects/p/django-" +"admin2/language/pl_PL/)\n" +"Language: pl_PL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " +"|| n%100>=20) ? 1 : 2);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Początek" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(dla przykładu)" diff --git a/example/files/locale/pt_BR/LC_MESSAGES/django.mo b/example/files/locale/pt_BR/LC_MESSAGES/django.mo new file mode 100644 index 0000000..5b3fb02 Binary files /dev/null and b/example/files/locale/pt_BR/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/pt_BR/LC_MESSAGES/django.po b/example/files/locale/pt_BR/LC_MESSAGES/django.po new file mode 100644 index 0000000..f53e803 --- /dev/null +++ b/example/files/locale/pt_BR/LC_MESSAGES/django.po @@ -0,0 +1,49 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-09 05:00+0000\n" +"Last-Translator: Douglas Miranda \n" +"Language-Team: Portuguese (Brazil) (http://www.transifex.com/projects/p/" +"django-admin2/language/pt_BR/)\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Página inicial de exemplo" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(para referência)" diff --git a/example/files/locale/sk/LC_MESSAGES/django.mo b/example/files/locale/sk/LC_MESSAGES/django.mo new file mode 100644 index 0000000..b5084db Binary files /dev/null and b/example/files/locale/sk/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/sk/LC_MESSAGES/django.po b/example/files/locale/sk/LC_MESSAGES/django.po new file mode 100644 index 0000000..eb7d93f --- /dev/null +++ b/example/files/locale/sk/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# Ivana Kellyerova , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-07 12:47+0000\n" +"Last-Translator: marekzelinka \n" +"Language-Team: Slovak (http://www.transifex.com/projects/p/django-admin2/" +"language/sk/)\n" +"Language: sk\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "Ukážka domovskej stránky" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(pre informáciu)" diff --git a/example/files/locale/tl_PH/LC_MESSAGES/django.mo b/example/files/locale/tl_PH/LC_MESSAGES/django.mo new file mode 100644 index 0000000..257c417 Binary files /dev/null and b/example/files/locale/tl_PH/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/tl_PH/LC_MESSAGES/django.po b/example/files/locale/tl_PH/LC_MESSAGES/django.po new file mode 100644 index 0000000..f2edc93 --- /dev/null +++ b/example/files/locale/tl_PH/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# rukku , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-09 08:22+0000\n" +"Last-Translator: rukku \n" +"Language-Team: Tagalog (Philippines) (http://www.transifex.com/projects/p/" +"django-admin2/language/tl_PH/)\n" +"Language: tl_PH\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "" diff --git a/example/files/locale/zh/LC_MESSAGES/django.mo b/example/files/locale/zh/LC_MESSAGES/django.mo new file mode 100644 index 0000000..775e6ca Binary files /dev/null and b/example/files/locale/zh/LC_MESSAGES/django.mo differ diff --git a/example/files/locale/zh/LC_MESSAGES/django.po b/example/files/locale/zh/LC_MESSAGES/django.po new file mode 100644 index 0000000..5369fb4 --- /dev/null +++ b/example/files/locale/zh/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +# This file is distributed under the same license as the django-admin2 package. +# +# Translators: +# EricHo , 2013 +msgid "" +msgstr "" +"Project-Id-Version: django-admin2\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-09-11 06:09-0500\n" +"PO-Revision-Date: 2013-07-07 11:16+0000\n" +"Last-Translator: EricHo \n" +"Language-Team: Chinese (http://www.transifex.com/projects/p/django-admin2/" +"language/zh/)\n" +"Language: zh\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: models.py:9 +msgid "caption" +msgstr "" + +#: models.py:10 models.py:21 +msgid "Uploaded File" +msgstr "" + +#: models.py:16 +msgid "Captioned File" +msgstr "" + +#: models.py:17 +msgid "Captioned Files" +msgstr "" + +#: models.py:27 +msgid "Uncaptioned File" +msgstr "" + +#: models.py:28 +msgid "Uncaptioned Files" +msgstr "" + +#: templates/home.html:4 +msgid "Example Home" +msgstr "首頁範本" + +#: templates/home.html:8 +msgid "(for reference)" +msgstr "(參考)" diff --git a/example/files/models.py b/example/files/models.py new file mode 100644 index 0000000..701b4fa --- /dev/null +++ b/example/files/models.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from __future__ import division, absolute_import, unicode_literals + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + + +class CaptionedFile(models.Model): + caption = models.CharField(max_length=200, verbose_name=_('caption')) + publication = models.FileField(upload_to='media', verbose_name=_('Uploaded File')) + + def __unicode__(self): + return self.caption + + class Meta: + verbose_name = _('Captioned File') + verbose_name_plural = _('Captioned Files') + + +class UncaptionedFile(models.Model): + publication = models.FileField(upload_to='media', verbose_name=_('Uploaded File')) + + def __unicode__(self): + return unicode(self.publication) + + class Meta: + verbose_name = _('Uncaptioned File') + verbose_name_plural = _('Uncaptioned Files') diff --git a/example/files/templates/home.html b/example/files/templates/home.html new file mode 100644 index 0000000..cf8e1a6 --- /dev/null +++ b/example/files/templates/home.html @@ -0,0 +1,10 @@ +{% extends "djadmin2theme_default/base.html" %} +{% load i18n %} +{% block content %} +

{% trans "Example Home" %}

+ + +{% endblock %} diff --git a/example/files/tests/__init__.py b/example/files/tests/__init__.py new file mode 100644 index 0000000..efb306e --- /dev/null +++ b/example/files/tests/__init__.py @@ -0,0 +1,2 @@ +from test_models import * +from test_views import * diff --git a/example/files/tests/fixtures/pubtest.txt b/example/files/tests/fixtures/pubtest.txt new file mode 100644 index 0000000..557db03 --- /dev/null +++ b/example/files/tests/fixtures/pubtest.txt @@ -0,0 +1 @@ +Hello World diff --git a/example/files/tests/test_models.py b/example/files/tests/test_models.py new file mode 100644 index 0000000..4ccc0c5 --- /dev/null +++ b/example/files/tests/test_models.py @@ -0,0 +1,54 @@ +from django.test import TestCase +from django.utils import timezone + +from files.models import CaptionedFile +from files.models import UncaptionedFile + + +from os import path + + +fixture_dir = path.join(path.abspath(path.dirname(__file__)), 'fixtures') + + +class CaptionedFileTestCase(TestCase): + + def setUp(self): + self.captioned_file = CaptionedFile.objects.create( + caption="this is a file", + publication=path.join('pubtest.txt') + ) + self.captioned_file.save() + + def test_creation(self): + cf = CaptionedFile.objects.create( + caption="lo lo", + publication=path.join('pubtest.txt') + ) + cf.save() + self.assertEqual(CaptionedFile.objects.count(), 2) + # Cause setup created one already + + def test_update(self): + self.captioned_file.caption = "I like text files" + self.captioned_file.save() + + cf = CaptionedFile.objects.get() + self.assertEqual(cf.caption, "I like text files") + + def test_delete(self): + cf = CaptionedFile.objects.get() + cf.delete() + + self.assertEqual(CaptionedFile.objects.count(), 0) + + +class MultiEncodedAdminFormTest(TestCase): + def setUp(self): + self.user = User( + username='admin', + is_staff=True, + is_superuser=True) + self.user.set_password('admin') + self.user.save() + self.create_url = reverse('admin2:example3_captioned_file_create') diff --git a/example/files/tests/test_views.py b/example/files/tests/test_views.py new file mode 100644 index 0000000..82859eb --- /dev/null +++ b/example/files/tests/test_views.py @@ -0,0 +1,162 @@ +from django.contrib.auth import get_user_model +from django.core.urlresolvers import reverse +from django.test import TestCase, Client +from django.utils import timezone + +from ..models import CaptionedFile + +from os import path + +fixture_dir = path.join(path.abspath(path.dirname(__file__)), 'fixtures') +fixture_file = path.join(fixture_dir, 'pubtest.txt') + + +class BaseIntegrationTest(TestCase): + """ + Base TestCase for integration tests. + """ + def setUp(self): + self.client = Client() + self.user = get_user_model()(username='user', is_staff=True, + is_superuser=True) + self.user.set_password("password") + self.user.save() + self.client.login(username='user', password='password') + + +class AdminIndexTest(BaseIntegrationTest): + def test_view_ok(self): + response = self.client.get(reverse("admin2:dashboard")) + self.assertContains(response, reverse("admin2:files_captionedfile_index")) + + +class CaptionedFileListTest(BaseIntegrationTest): + def test_view_ok(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + response = self.client.get(reverse("admin2:files_captionedfile_index")) + self.assertContains(response, captioned_file.caption) + + def test_actions_displayed(self): + response = self.client.get(reverse("admin2:files_captionedfile_index")) + self.assertInHTML('Delete selected items', response.content) + + def test_delete_selected_captioned_file(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + params = {'action': 'DeleteSelectedAction', 'selected_model_pk': str(captioned_file.pk)} + response = self.client.post(reverse("admin2:files_captionedfile_index"), params) + self.assertInHTML('

Are you sure you want to delete the selected Captioned File? The following item will be deleted:

', response.content) + + def test_delete_selected_captioned_file_confirmation(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + params = {'action': 'DeleteSelectedAction', 'selected_model_pk': str(captioned_file.pk), 'confirmed': 'yes'} + response = self.client.post(reverse("admin2:files_captionedfile_index"), params) + self.assertRedirects(response, reverse("admin2:files_captionedfile_index")) + + def test_delete_selected_captioned_file_none_selected(self): + CaptionedFile.objects.create(caption="some file", publication=fixture_file) + params = {'action': 'DeleteSelectedAction'} + response = self.client.post(reverse("admin2:files_captionedfile_index"), params, follow=True) + self.assertContains(response, "Items must be selected in order to perform actions on them. No items have been changed.") + + +class CaptionedFileDetailViewTest(BaseIntegrationTest): + def test_view_ok(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + response = self.client.get(reverse("admin2:files_captionedfile_detail", args=(captioned_file.pk, ))) + self.assertContains(response, captioned_file.caption) + + +class CaptionedFileCreateViewTest(BaseIntegrationTest): + def test_view_ok(self): + response = self.client.get(reverse("admin2:files_captionedfile_create")) + self.assertIn('''enctype="multipart/form-data"''', response.content) + self.assertEqual(response.status_code, 200) + + def test_create_captioned_file(self): + with open(fixture_file, 'r') as fp: + params = { + "caption": "some file", + "publication": fp, + } + response = self.client.post(reverse("admin2:files_captionedfile_create"), + params, + follow=True) + self.assertTrue(CaptionedFile.objects.filter(caption="some file").exists()) + self.assertRedirects(response, reverse("admin2:files_captionedfile_index")) + + def test_save_and_add_another_redirects_to_create(self): + """ + Tests that choosing 'Save and add another' from the model create + page redirects the user to the model create page. + """ + with open(fixture_file, 'r') as fp: + params = { + "caption": "some file", + "publication": fp, + "_addanother": "" + } + response = self.client.post(reverse("admin2:files_captionedfile_create"), + params) + self.assertTrue(CaptionedFile.objects.filter(caption="some file").exists()) + self.assertRedirects(response, reverse("admin2:files_captionedfile_create")) + + def test_save_and_continue_editing_redirects_to_update(self): + """ + Tests that choosing "Save and continue editing" redirects + the user to the model update form. + """ + with open(fixture_file, 'r') as fp: + params = { + "caption": "some file", + "publication": fp, + "_continue": "" + } + response = self.client.post(reverse("admin2:files_captionedfile_create"), + params) + captioned_file = CaptionedFile.objects.get(caption="some file") + self.assertRedirects(response, reverse("admin2:files_captionedfile_update", + args=(captioned_file.pk, ))) + + +class CaptionedFileDeleteViewTest(BaseIntegrationTest): + def test_view_ok(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + response = self.client.get(reverse("admin2:files_captionedfile_delete", + args=(captioned_file.pk, ))) + self.assertContains(response, captioned_file.caption) + + def test_delete_captioned_file(self): + captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + response = self.client.post(reverse("admin2:files_captionedfile_delete", + args=(captioned_file.pk, ))) + self.assertRedirects(response, reverse("admin2:files_captionedfile_index")) + self.assertFalse(CaptionedFile.objects.filter(pk=captioned_file.pk).exists()) + + +class FileDeleteActionTest(BaseIntegrationTest): + """ + Tests the behaviour of the 'Delete selected items' action. + """ + def test_confirmation_page(self): + cf1 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + cf2 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + params = { + 'action': 'DeleteSelectedAction', + 'selected_model_pk': [cf1.pk, cf2.pk] + } + response = self.client.post(reverse("admin2:files_captionedfile_index"), + params) + self.assertContains(response, cf1.caption) + self.assertContains(response, cf2.caption) + + def test_results_page(self): + cf1 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + cf2 = captioned_file = CaptionedFile.objects.create(caption="some file", publication=fixture_file) + params = { + 'action': 'DeleteSelectedAction', + 'selected_model_pk': [cf1.pk, cf2.pk], + 'confirmed': 'yes' + } + response = self.client.post(reverse("admin2:files_captionedfile_index"), + params, follow=True) + self.assertContains(response, "Successfully deleted 2 Captioned Files") diff --git a/example/files/views.py b/example/files/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/example/files/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/runtests.py b/runtests.py index 6e2cf3f..3e58b51 100755 --- a/runtests.py +++ b/runtests.py @@ -10,7 +10,7 @@ from django.test.utils import get_runner from django.conf import settings -def runtests(tests=('blog', 'djadmin2',)): +def runtests(tests=('blog', 'files', 'djadmin2')): ''' Takes a list as first argument, enumerating the apps and specific testcases that should be executed. The syntax is the same as for what you would pass