mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-05-16 08:43:10 +00:00
[Updates #33] Testapp source code
This commit is contained in:
parent
9dba8c0abd
commit
39e756b1a9
12 changed files with 218 additions and 0 deletions
0
testapp/__init__.py
Normal file
0
testapp/__init__.py
Normal file
28
testapp/admin.py
Normal file
28
testapp/admin.py
Normal file
|
|
@ -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)
|
||||
7
testapp/forms.py
Normal file
7
testapp/forms.py
Normal file
|
|
@ -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()
|
||||
10
testapp/models.py
Normal file
10
testapp/models.py
Normal file
|
|
@ -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()
|
||||
84
testapp/settings.py
Normal file
84
testapp/settings.py
Normal file
|
|
@ -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',
|
||||
]
|
||||
22
testapp/templates/base.html
Normal file
22
testapp/templates/base.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
console.log("ready");
|
||||
|
||||
$('.markdownx').on('markdownx.init', function() {
|
||||
console.log("INIT");
|
||||
});
|
||||
|
||||
$('.markdownx').on('markdownx.update', function(e, response) {
|
||||
console.log("UPDATE" + response);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
8
testapp/templates/index.html
Normal file
8
testapp/templates/index.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<ul>
|
||||
<li><a href="{% url 'form_view' %}">Generic Form</a></li>
|
||||
<li><a href="{% url 'create_view' %}">Generic Create View</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
8
testapp/templates/test_create_view.html
Normal file
8
testapp/templates/test_create_view.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form role="form" method="POST" action="">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</form>
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
8
testapp/templates/test_form_view.html
Normal file
8
testapp/templates/test_form_view.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form role="form" method="POST" action="">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
</form>
|
||||
{{ form.media }}
|
||||
{% endblock %}
|
||||
18
testapp/urls.py
Normal file
18
testapp/urls.py
Normal file
|
|
@ -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)
|
||||
20
testapp/views.py
Normal file
20
testapp/views.py
Normal file
|
|
@ -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 = '/'
|
||||
5
testapp/wsgi.py
Normal file
5
testapp/wsgi.py
Normal file
|
|
@ -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()
|
||||
Loading…
Reference in a new issue