From 39e756b1a9b74f43cacd37c4406f94d87d5d69be Mon Sep 17 00:00:00 2001 From: adi Date: Sun, 4 Dec 2016 19:36:41 +0100 Subject: [PATCH] [Updates #33] Testapp source code --- testapp/__init__.py | 0 testapp/admin.py | 28 +++++++++ testapp/forms.py | 7 +++ testapp/models.py | 10 +++ testapp/settings.py | 84 +++++++++++++++++++++++++ testapp/templates/base.html | 22 +++++++ testapp/templates/index.html | 8 +++ testapp/templates/test_create_view.html | 8 +++ testapp/templates/test_form_view.html | 8 +++ testapp/urls.py | 18 ++++++ testapp/views.py | 20 ++++++ testapp/wsgi.py | 5 ++ 12 files changed, 218 insertions(+) create mode 100644 testapp/__init__.py create mode 100644 testapp/admin.py create mode 100644 testapp/forms.py create mode 100644 testapp/models.py create mode 100644 testapp/settings.py create mode 100644 testapp/templates/base.html create mode 100644 testapp/templates/index.html create mode 100644 testapp/templates/test_create_view.html create mode 100644 testapp/templates/test_form_view.html create mode 100644 testapp/urls.py create mode 100644 testapp/views.py create mode 100644 testapp/wsgi.py diff --git a/testapp/__init__.py b/testapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/testapp/admin.py b/testapp/admin.py new file mode 100644 index 0000000..de84192 --- /dev/null +++ b/testapp/admin.py @@ -0,0 +1,28 @@ +from django.db import models +from django.contrib import admin + +from markdownx.widgets import AdminMarkdownxWidget +from markdownx.models import MarkdownxField + +from .models import MyModel + + +class MyModelAdmin(admin.ModelAdmin): + formfield_overrides = { + MarkdownxField: {'widget': AdminMarkdownxWidget}, + models.TextField: {'widget': AdminMarkdownxWidget}, + } + +admin.site.register(MyModel, MyModelAdmin) + +## +## SHORTER OPTION: +## + +# from django.contrib import admin + +# from markdownx.admin import MarkdownxModelAdmin + +# from .models import MyModel + +# admin.site.register(MyModel, MarkdownxModelAdmin) diff --git a/testapp/forms.py b/testapp/forms.py new file mode 100644 index 0000000..d869053 --- /dev/null +++ b/testapp/forms.py @@ -0,0 +1,7 @@ +from django import forms + +from markdownx.fields import MarkdownxFormField + +class MyForm(forms.Form): + markdownx_form_field1 = MarkdownxFormField() + markdownx_form_field2 = MarkdownxFormField() diff --git a/testapp/models.py b/testapp/models.py new file mode 100644 index 0000000..30c74b7 --- /dev/null +++ b/testapp/models.py @@ -0,0 +1,10 @@ +from django.db import models + +from markdownx.models import MarkdownxField + +class MyModel(models.Model): + markdownx_field1 = MarkdownxField() + markdownx_field2 = MarkdownxField() + + textfield1 = models.TextField() + textfield2 = models.TextField() diff --git a/testapp/settings.py b/testapp/settings.py new file mode 100644 index 0000000..b6601a4 --- /dev/null +++ b/testapp/settings.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- + +import os +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +SECRET_KEY = 'vcpt&w*g54+rlu(le#@_f#y*8^382ubn4uue*xpwrj#upre5ei' + +DEBUG = True + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'markdownx', + + 'testapp', +) + +MIDDLEWARE = [ + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +] + +ROOT_URLCONF = 'testapp.urls' + +WSGI_APPLICATION = 'testapp.wsgi.application' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +STATIC_URL = '/static/' +STATIC_ROOT = 'testapp/static/' +MEDIA_URL = '/media/' +MEDIA_ROOT = 'testapp/media/' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + 'testapp/templates', + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this + # list if you haven't customized them: + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.template.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + ], + 'debug': True, + }, + }, +] + +MARKDOWNX_MARKDOWN_EXTENSIONS = [ + 'markdown.extensions.extra', +] diff --git a/testapp/templates/base.html b/testapp/templates/base.html new file mode 100644 index 0000000..9f72fa8 --- /dev/null +++ b/testapp/templates/base.html @@ -0,0 +1,22 @@ + + + + + + + + {% block content %}{% endblock %} + + diff --git a/testapp/templates/index.html b/testapp/templates/index.html new file mode 100644 index 0000000..20b26c7 --- /dev/null +++ b/testapp/templates/index.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} + +{% endblock %} diff --git a/testapp/templates/test_create_view.html b/testapp/templates/test_create_view.html new file mode 100644 index 0000000..cc4d337 --- /dev/null +++ b/testapp/templates/test_create_view.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} +
{% csrf_token %} + {{ form.as_p }} +
+{{ form.media }} +{% endblock %} diff --git a/testapp/templates/test_form_view.html b/testapp/templates/test_form_view.html new file mode 100644 index 0000000..cc4d337 --- /dev/null +++ b/testapp/templates/test_form_view.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} +
{% csrf_token %} + {{ form.as_p }} +
+{{ form.media }} +{% endblock %} diff --git a/testapp/urls.py b/testapp/urls.py new file mode 100644 index 0000000..96b71cd --- /dev/null +++ b/testapp/urls.py @@ -0,0 +1,18 @@ +from django.conf import settings +from django.conf.urls import include, url +from django.conf.urls.static import static +from django.contrib import admin + +from testapp.views import ( + IndexTemplateView, + TestFormView, + TestCreateView, +) + +urlpatterns = [ + url(r'^$', IndexTemplateView.as_view()), + url(r'^form-view/$', TestFormView.as_view(), name='form_view'), + url(r'^create-view/$', TestCreateView.as_view(), name='create_view'), + url(r'^markdownx/', include('markdownx.urls')), + url(r'^admin/', include(admin.site.urls)), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/testapp/views.py b/testapp/views.py new file mode 100644 index 0000000..382ed37 --- /dev/null +++ b/testapp/views.py @@ -0,0 +1,20 @@ +from django.views.generic.base import TemplateView +from django.views.generic.edit import FormView, CreateView + +from testapp.models import MyModel +from testapp.forms import MyForm + + +class IndexTemplateView(TemplateView): + template_name = 'index.html' + +class TestFormView(FormView): + template_name = "test_form_view.html" + form_class = MyForm + success_url = '/' + +class TestCreateView(CreateView): + template_name = "test_create_view.html" + model = MyModel + fields = ['markdownx_field1', 'markdownx_field2', 'textfield1', 'textfield2'] + success_url = '/' diff --git a/testapp/wsgi.py b/testapp/wsgi.py new file mode 100644 index 0000000..8456c77 --- /dev/null +++ b/testapp/wsgi.py @@ -0,0 +1,5 @@ +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application()