aboutsummaryrefslogtreecommitdiffstats
path: root/demo
diff options
context:
space:
mode:
Diffstat (limited to 'demo')
-rw-r--r--demo/__init__.py0
-rw-r--r--demo/forms.py37
-rw-r--r--demo/templates/demo/base.html25
-rw-r--r--demo/templates/demo/bootstrap.html3
-rw-r--r--demo/templates/demo/form.html17
-rw-r--r--demo/templates/demo/form_horizontal.html17
-rw-r--r--demo/templates/demo/form_inline.html17
-rw-r--r--demo/templates/demo/form_with_files.html17
-rw-r--r--demo/templates/demo/home.html7
-rw-r--r--demo/templates/demo/pagination.html25
-rw-r--r--demo/urls.py32
-rw-r--r--demo/views.py79
12 files changed, 276 insertions, 0 deletions
diff --git a/demo/__init__.py b/demo/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/demo/__init__.py
diff --git a/demo/forms.py b/demo/forms.py
new file mode 100644
index 0000000..aea1ce7
--- /dev/null
+++ b/demo/forms.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django import forms
+
+from bootstrap3.tests import TestForm
+
+RADIO_CHOICES = (
+ ('1', 'Radio 1'),
+ ('2', 'Radio 2'),
+)
+
+MEDIA_CHOICES = (
+ ('Audio', (
+ ('vinyl', 'Vinyl'),
+ ('cd', 'CD'),
+ )
+ ),
+ ('Video', (
+ ('vhs', 'VHS Tape'),
+ ('dvd', 'DVD'),
+ )
+ ),
+ ('unknown', 'Unknown'),
+)
+
+
+class ContactForm(TestForm):
+ pass
+
+
+class FilesForm(forms.Form):
+ text1 = forms.CharField()
+ file1 = forms.FileField()
+ file2 = forms.FileField(required=False)
+ file3 = forms.FileField(widget=forms.ClearableFileInput)
+ file4 = forms.FileField(required=False, widget=forms.ClearableFileInput)
diff --git a/demo/templates/demo/base.html b/demo/templates/demo/base.html
new file mode 100644
index 0000000..06dc6e3
--- /dev/null
+++ b/demo/templates/demo/base.html
@@ -0,0 +1,25 @@
+{% extends 'demo/bootstrap.html' %}
+
+{% load url from future %}
+
+{% load bootstrap3 %}
+
+{% block bootstrap3_content %}
+ <div class="container">
+ <h1>{% block title %}(no title){% endblock %}</h1>
+
+ <p>
+ <a href="{% url 'home' %}">home</a>
+ <a href="{% url 'form_default' %}">form</a>
+ <a href="{% url 'form_horizontal' %}">form_horizontal</a>
+ <a href="{% url 'form_inline' %}">form_inline</a>
+ <a href="{% url 'form_with_files' %}">form_with_files</a>
+ <a href="{% url 'pagination' %}">pagination</a>
+ </p>
+
+ {% bootstrap_messages %}
+
+ {% block content %}(no content){% endblock %}
+ </div>
+
+{% endblock %}
diff --git a/demo/templates/demo/bootstrap.html b/demo/templates/demo/bootstrap.html
new file mode 100644
index 0000000..5e5b581
--- /dev/null
+++ b/demo/templates/demo/bootstrap.html
@@ -0,0 +1,3 @@
+{% extends 'bootstrap3/bootstrap3.html' %}
+
+{% block bootstrap3_title %}{% block title %}{% endblock %}{% endblock %}
diff --git a/demo/templates/demo/form.html b/demo/templates/demo/form.html
new file mode 100644
index 0000000..d89672f
--- /dev/null
+++ b/demo/templates/demo/form.html
@@ -0,0 +1,17 @@
+{% extends 'demo/base.html' %}
+
+{% load bootstrap3 %}
+
+{% block title %}
+ Forms
+{% endblock %}
+
+{% block content %}
+
+ <form role="form" method="post">
+ {% csrf_token %}
+ {% bootstrap_form form %}
+ {% buttons submit='OK' reset="Cancel" %}{% endbuttons %}
+ </form>
+
+{% endblock %}
diff --git a/demo/templates/demo/form_horizontal.html b/demo/templates/demo/form_horizontal.html
new file mode 100644
index 0000000..229d400
--- /dev/null
+++ b/demo/templates/demo/form_horizontal.html
@@ -0,0 +1,17 @@
+{% extends 'demo/base.html' %}
+
+{% load bootstrap3 %}
+
+{% block title %}
+ Forms
+{% endblock %}
+
+{% block content %}
+
+ <form role="form" class="form-horizontal" method="post">
+ {% csrf_token %}
+ {% bootstrap_form form layout="horizontal" %}
+ {% buttons submit='OK' reset='Cancel' layout='horizontal' %}{% endbuttons %}
+ </form>
+
+{% endblock %}
diff --git a/demo/templates/demo/form_inline.html b/demo/templates/demo/form_inline.html
new file mode 100644
index 0000000..9f76c1e
--- /dev/null
+++ b/demo/templates/demo/form_inline.html
@@ -0,0 +1,17 @@
+{% extends 'demo/base.html' %}
+
+{% load bootstrap3 %}
+
+{% block title %}
+ Forms
+{% endblock %}
+
+{% block content %}
+
+ <form role="form" class="form-inline" method="post">
+ {% csrf_token %}
+ {% bootstrap_form form layout='inline' %}
+ {% buttons submit='OK' reset='Cancel' layout='inline' %}{% endbuttons %}
+ </form>
+
+{% endblock %}
diff --git a/demo/templates/demo/form_with_files.html b/demo/templates/demo/form_with_files.html
new file mode 100644
index 0000000..3e5e83f
--- /dev/null
+++ b/demo/templates/demo/form_with_files.html
@@ -0,0 +1,17 @@
+{% extends 'demo/base.html' %}
+
+{% load bootstrap3 %}
+
+{% block title %}
+ Forms
+{% endblock %}
+
+{% block content %}
+
+ <form role="form" method="post" enctype="multipart/form-data" {% if layout != 'vertical' %}class="form-{{ layout }}"{% endif %}>
+ {% csrf_token %}
+ {% bootstrap_form form layout=layout %}
+ {% buttons submit='OK' reset="Cancel" %}{% endbuttons %}
+ </form>
+
+{% endblock %}
diff --git a/demo/templates/demo/home.html b/demo/templates/demo/home.html
new file mode 100644
index 0000000..7166062
--- /dev/null
+++ b/demo/templates/demo/home.html
@@ -0,0 +1,7 @@
+{% extends 'demo/base.html' %}
+
+{% block title %}django-bootstrap3{% endblock %}
+
+{% block content %}
+ This is <em>bootstrap3</em> for <strong>Django</strong>.
+{% endblock %} \ No newline at end of file
diff --git a/demo/templates/demo/pagination.html b/demo/templates/demo/pagination.html
new file mode 100644
index 0000000..e7c1ed3
--- /dev/null
+++ b/demo/templates/demo/pagination.html
@@ -0,0 +1,25 @@
+{% extends 'demo/base.html' %}
+
+{% load bootstrap3 %}
+
+{% block title %}
+ Pagination
+{% endblock %}
+
+{% block content %}
+
+ <table class="table">
+ {% for line in lines %}
+ <tr>
+ <td>{{ line }}</td>
+ </tr>
+ {% endfor %}
+ </table>
+
+ <hr>
+
+ {% bootstrap_pagination lines url="/pagination?page=1&flop=flip" extra="q=foo" size="small" %}
+
+ {% bootstrap_pagination lines url="/pagination?page=1" size="large" %}
+
+{% endblock %} \ No newline at end of file
diff --git a/demo/urls.py b/demo/urls.py
new file mode 100644
index 0000000..b45a57a
--- /dev/null
+++ b/demo/urls.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.conf.urls import patterns, url
+
+from .views import HomePageView, FormHorizontalView, FormInlineView, PaginationView, FormWithFilesView, \
+ DefaultFormView
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+# urlpatterns = patterns('',
+# # Examples:
+# # url(r'^$', 'demo.views.home', name='home'),
+# # url(r'^demo/', include('demo.foo.urls')),
+#
+# # Uncomment the admin/doc line below to enable admin documentation:
+# # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+#
+# # Uncomment the next line to enable the admin:
+# # url(r'^admin/', include(admin.site.urls)),
+# )
+
+urlpatterns = patterns('',
+ url(r'^$', HomePageView.as_view(), name='home'),
+ url(r'^form$', DefaultFormView.as_view(), name='form_default'),
+ url(r'^form_horizontal$', FormHorizontalView.as_view(), name='form_horizontal'),
+ url(r'^form_inline$', FormInlineView.as_view(), name='form_inline'),
+ url(r'^pagination$', PaginationView.as_view(), name='pagination'),
+ url(r'^form_with_files$', FormWithFilesView.as_view(), name='form_with_files'),
+)
diff --git a/demo/views.py b/demo/views.py
new file mode 100644
index 0000000..07c25f0
--- /dev/null
+++ b/demo/views.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.core.files.storage import default_storage
+
+from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
+from django.db.models.fields.files import FieldFile
+from django.views.generic import FormView
+from django.views.generic.base import TemplateView
+from django.contrib import messages
+
+from .forms import ContactForm, FilesForm
+
+
+# http://yuji.wordpress.com/2013/01/30/django-form-field-in-initial-data-requires-a-fieldfile-instance/
+class FakeField(object):
+ storage = default_storage
+
+
+fieldfile = FieldFile(None, FakeField, 'dummy.txt')
+
+
+class HomePageView(TemplateView):
+ template_name = 'demo/home.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(HomePageView, self).get_context_data(**kwargs)
+ messages.info(self.request, 'This is a demo of a message.')
+ return context
+
+
+class DefaultFormView(FormView):
+ template_name = 'demo/form.html'
+ form_class = ContactForm
+
+
+class FormHorizontalView(FormView):
+ template_name = 'demo/form_horizontal.html'
+ form_class = ContactForm
+
+
+class FormInlineView(FormView):
+ template_name = 'demo/form_inline.html'
+ form_class = ContactForm
+
+
+class FormWithFilesView(FormView):
+ template_name = 'demo/form_with_files.html'
+ form_class = FilesForm
+
+ def get_context_data(self, **kwargs):
+ context = super(FormWithFilesView, self).get_context_data(**kwargs)
+ context['layout'] = self.request.GET.get('layout', 'vertical')
+ return context
+
+ def get_initial(self):
+ return {
+ 'file4': fieldfile,
+ }
+
+class PaginationView(TemplateView):
+ template_name = 'demo/pagination.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(PaginationView, self).get_context_data(**kwargs)
+ lines = []
+ for i in range(10000):
+ lines.append('Line %s' % (i + 1))
+ paginator = Paginator(lines, 10)
+ page = self.request.GET.get('page')
+ try:
+ show_lines = paginator.page(page)
+ except PageNotAnInteger:
+ # If page is not an integer, deliver first page.
+ show_lines = paginator.page(1)
+ except EmptyPage:
+ # If page is out of range (e.g. 9999), deliver last page of results.
+ show_lines = paginator.page(paginator.num_pages)
+ context['lines'] = show_lines
+ return context