mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Merge branch 'django-update'
This commit is contained in:
@@ -70,22 +70,10 @@ WSGI_APPLICATION = 'PyRIGS.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||
try:
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
except ImportError:
|
||||
pass
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
},
|
||||
'legacy': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'HOST': 'alfie.codedinternet.com',
|
||||
'NAME': 'tec_rigs',
|
||||
'USER': 'tec_rigs',
|
||||
'PASSWORD': 'xMNb(b+Giu]&',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,20 +90,24 @@ class EventPrint(generic.View):
|
||||
object = get_object_or_404(models.Event, pk=pk)
|
||||
template = get_template('RIGS/event_print.xml')
|
||||
copies = ('TEC', 'Client')
|
||||
context = RequestContext(request, {
|
||||
'object': object,
|
||||
'fonts': {
|
||||
'opensans': {
|
||||
'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF',
|
||||
'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF',
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
merger = PdfFileMerger()
|
||||
|
||||
for copy in copies:
|
||||
context['copy'] = copy
|
||||
|
||||
context = RequestContext(request, { # this should be outside the loop, but bug in 1.8.2 prevents this
|
||||
'object': object,
|
||||
'fonts': {
|
||||
'opensans': {
|
||||
'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF',
|
||||
'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF',
|
||||
}
|
||||
},
|
||||
'copy':copy
|
||||
})
|
||||
|
||||
# context['copy'] = copy # this is the way to do it once we upgrade to Django 1.8.3
|
||||
|
||||
rml = template.render(context)
|
||||
buffer = StringIO.StringIO()
|
||||
|
||||
@@ -126,6 +130,7 @@ class EventPrint(generic.View):
|
||||
|
||||
|
||||
class EventDuplicate(generic.RedirectView):
|
||||
permanent = False;
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
new = get_object_or_404(models.Event, pk=kwargs['pk'])
|
||||
new.pk = None
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django import template
|
||||
from django import forms
|
||||
from django.forms.forms import NON_FIELD_ERRORS
|
||||
from django.forms.util import ErrorDict
|
||||
from django.forms.utils import ErrorDict
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ urlpatterns = patterns('',
|
||||
# Rigboard
|
||||
url(r'^rigboard/$', login_required(rigboard.RigboardIndex.as_view()), name='rigboard'),
|
||||
url(r'^rigboard/calendar/$', login_required()(rigboard.WebCalendar.as_view()), name='web_calendar'),
|
||||
url(r'^rigboard/archive/$', RedirectView.as_view(pattern_name='event_archive')),
|
||||
url(r'^rigboard/archive/$', RedirectView.as_view(permanent=True,pattern_name='event_archive')),
|
||||
url(r'^rigboard/activity/$',
|
||||
permission_required_with_403('RIGS.view_event')(versioning.ActivityTable.as_view()),
|
||||
name='activity_table'),
|
||||
@@ -149,8 +149,8 @@ urlpatterns = patterns('',
|
||||
url(r'^api/(?P<model>\w+)/(?P<pk>\d+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"),
|
||||
|
||||
# Legacy URL's
|
||||
url(r'^rig/show/(?P<pk>\d+)/$', RedirectView.as_view(pattern_name='event_detail')),
|
||||
url(r'^bookings/$', RedirectView.as_view(pattern_name='rigboard')),
|
||||
url(r'^bookings/past/$', RedirectView.as_view(pattern_name='event_archive')),
|
||||
url(r'^rig/show/(?P<pk>\d+)/$', RedirectView.as_view(permanent=True,pattern_name='event_detail')),
|
||||
url(r'^bookings/$', RedirectView.as_view(permanent=True,pattern_name='rigboard')),
|
||||
url(r'^bookings/past/$', RedirectView.as_view(permanent=True,pattern_name='event_archive')),
|
||||
)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ def get_versions_for_model(models):
|
||||
|
||||
versions = reversion.models.Version.objects.filter(
|
||||
content_type__in = content_types,
|
||||
).select_related("revision","revision.version_set").order_by("-pk")
|
||||
).select_related("revision").order_by("-pk")
|
||||
|
||||
return versions
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ class PersonDetail(generic.DetailView):
|
||||
|
||||
class PersonCreate(generic.CreateView):
|
||||
model = models.Person
|
||||
fields = ['name','phone','email','address','notes']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
@@ -84,6 +85,7 @@ class PersonCreate(generic.CreateView):
|
||||
|
||||
class PersonUpdate(generic.UpdateView):
|
||||
model = models.Person
|
||||
fields = ['name','phone','email','address','notes']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
@@ -120,6 +122,7 @@ class OrganisationDetail(generic.DetailView):
|
||||
|
||||
class OrganisationCreate(generic.CreateView):
|
||||
model = models.Organisation
|
||||
fields = ['name','phone','email','address','notes','union_account']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
@@ -136,6 +139,7 @@ class OrganisationCreate(generic.CreateView):
|
||||
|
||||
class OrganisationUpdate(generic.UpdateView):
|
||||
model = models.Organisation
|
||||
fields = ['name','phone','email','address','notes','union_account']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
@@ -172,6 +176,7 @@ class VenueDetail(generic.DetailView):
|
||||
|
||||
class VenueCreate(generic.CreateView):
|
||||
model = models.Venue
|
||||
fields = ['name','phone','email','address','notes']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
@@ -188,6 +193,7 @@ class VenueCreate(generic.CreateView):
|
||||
|
||||
class VenueUpdate(generic.UpdateView):
|
||||
model = models.Venue
|
||||
fields = ['name','phone','email','address','notes']
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.is_ajax():
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
Django==1.7.1
|
||||
Pillow==2.7.0
|
||||
PyMySQL==0.6.2
|
||||
PyPDF2==1.23
|
||||
Pygments==2.0.2
|
||||
dj-database-url==0.3.0
|
||||
dj-static==0.0.6
|
||||
django-debug-toolbar==1.2.2
|
||||
Django==1.8.2
|
||||
django-debug-toolbar==1.3.0
|
||||
django-ical==1.3
|
||||
django-recaptcha==1.0.4
|
||||
django-registration-redux==1.1
|
||||
django-reversion==1.8.5
|
||||
django-registration-redux==1.2
|
||||
django-reversion==1.8.7
|
||||
django-toolbelt==0.0.1
|
||||
django-widget-tweaks==1.3
|
||||
gunicorn==19.3.0
|
||||
icalendar==3.9.0
|
||||
lxml==3.4.1
|
||||
lxml==3.4.4
|
||||
Pillow==2.8.1
|
||||
psycopg2==2.6
|
||||
Pygments==2.0.2
|
||||
PyPDF2==1.24
|
||||
python-dateutil==2.4.2
|
||||
pytz==2015.2
|
||||
reportlab==2.7
|
||||
pytz==2015.4
|
||||
reportlab==3.1.44
|
||||
selenium==2.45.0
|
||||
simplejson==3.6.5
|
||||
simplejson==3.7.2
|
||||
six==1.9.0
|
||||
sqlparse==0.1.13
|
||||
static3==0.5.1
|
||||
sqlparse==0.1.15
|
||||
static3==0.6.1
|
||||
svg2rlg==0.3
|
||||
wsgiref==0.1.2
|
||||
yolk==0.4.3
|
||||
z3c.rml==2.7.2
|
||||
z3c.rml==2.8.1
|
||||
zope.event==4.0.3
|
||||
zope.interface==4.1.2
|
||||
zope.schema==4.4.2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% load static from staticfiles %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load url from future %}
|
||||
|
||||
Welcome {{ user }},
|
||||
|
||||
Thank you for registering on {{ site }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load url from future %}
|
||||
|
||||
{% load widget_tweaks %}
|
||||
{% include 'form_errors.html' %}
|
||||
<div class="col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% load widget_tweaks %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
{% block title %}Change Password{% endblock %}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load widget_tweaks %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{% load i18n %}{% load url from future %}{% autoescape off %}
|
||||
{% load i18n %}{% autoescape off %}
|
||||
{% blocktrans %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}
|
||||
|
||||
{% trans "Please go to the following page and choose a new password:" %}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
import re
|
||||
from django.template import Library, Node, Variable, TemplateSyntaxError
|
||||
register = Library()
|
||||
|
||||
|
||||
def silence_without_field(fn):
|
||||
def wrapped(field, attr):
|
||||
if not field:
|
||||
return ""
|
||||
return fn(field, attr)
|
||||
return wrapped
|
||||
|
||||
|
||||
def _process_field_attributes(field, attr, process):
|
||||
|
||||
# split attribute name and value from 'attr:value' string
|
||||
params = attr.split(':', 1)
|
||||
attribute = params[0]
|
||||
value = params[1] if len(params) == 2 else ''
|
||||
|
||||
# decorate field.as_widget method with updated attributes
|
||||
old_as_widget = field.as_widget
|
||||
|
||||
def as_widget(self, widget=None, attrs=None, only_initial=False):
|
||||
attrs = attrs or {}
|
||||
process(widget or self.field.widget, attrs, attribute, value)
|
||||
return old_as_widget(widget, attrs, only_initial)
|
||||
|
||||
bound_method = type(old_as_widget)
|
||||
try:
|
||||
field.as_widget = bound_method(as_widget, field, field.__class__)
|
||||
except TypeError: # python 3
|
||||
field.as_widget = bound_method(as_widget, field)
|
||||
return field
|
||||
|
||||
|
||||
@register.filter("attr")
|
||||
@silence_without_field
|
||||
def set_attr(field, attr):
|
||||
|
||||
def process(widget, attrs, attribute, value):
|
||||
attrs[attribute] = value
|
||||
|
||||
return _process_field_attributes(field, attr, process)
|
||||
|
||||
|
||||
@register.filter("add_error_attr")
|
||||
@silence_without_field
|
||||
def add_error_attr(field, attr):
|
||||
if hasattr(field, 'errors') and field.errors:
|
||||
return set_attr(field, attr)
|
||||
return field
|
||||
|
||||
|
||||
@register.filter("append_attr")
|
||||
@silence_without_field
|
||||
def append_attr(field, attr):
|
||||
def process(widget, attrs, attribute, value):
|
||||
if attrs.get(attribute):
|
||||
attrs[attribute] += ' ' + value
|
||||
elif widget.attrs.get(attribute):
|
||||
attrs[attribute] = widget.attrs[attribute] + ' ' + value
|
||||
else:
|
||||
attrs[attribute] = value
|
||||
return _process_field_attributes(field, attr, process)
|
||||
|
||||
|
||||
@register.filter("add_class")
|
||||
@silence_without_field
|
||||
def add_class(field, css_class):
|
||||
return append_attr(field, 'class:' + css_class)
|
||||
|
||||
|
||||
@register.filter("add_error_class")
|
||||
@silence_without_field
|
||||
def add_error_class(field, css_class):
|
||||
if hasattr(field, 'errors') and field.errors:
|
||||
return add_class(field, css_class)
|
||||
return field
|
||||
|
||||
|
||||
@register.filter("set_data")
|
||||
@silence_without_field
|
||||
def set_data(field, data):
|
||||
return set_attr(field, 'data-' + data)
|
||||
|
||||
|
||||
@register.filter(name='field_type')
|
||||
def field_type(field):
|
||||
"""
|
||||
Template filter that returns field class name (in lower case).
|
||||
E.g. if field is CharField then {{ field|field_type }} will
|
||||
return 'charfield'.
|
||||
"""
|
||||
if hasattr(field, 'field') and field.field:
|
||||
return field.field.__class__.__name__.lower()
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter(name='widget_type')
|
||||
def widget_type(field):
|
||||
"""
|
||||
Template filter that returns field widget class name (in lower case).
|
||||
E.g. if field's widget is TextInput then {{ field|widget_type }} will
|
||||
return 'textinput'.
|
||||
"""
|
||||
if hasattr(field, 'field') and hasattr(field.field, 'widget') and field.field.widget:
|
||||
return field.field.widget.__class__.__name__.lower()
|
||||
return ''
|
||||
|
||||
|
||||
# ======================== render_field tag ==============================
|
||||
|
||||
ATTRIBUTE_RE = re.compile(r"""
|
||||
(?P<attr>
|
||||
[\w_-]+
|
||||
)
|
||||
(?P<sign>
|
||||
\+?=
|
||||
)
|
||||
(?P<value>
|
||||
['"]? # start quote
|
||||
[^"']*
|
||||
['"]? # end quote
|
||||
)
|
||||
""", re.VERBOSE | re.UNICODE)
|
||||
|
||||
@register.tag
|
||||
def render_field(parser, token):
|
||||
"""
|
||||
Render a form field using given attribute-value pairs
|
||||
|
||||
Takes form field as first argument and list of attribute-value pairs for
|
||||
all other arguments. Attribute-value pairs should be in the form of
|
||||
attribute=value or attribute="a value" for assignment and attribute+=value
|
||||
or attribute+="value" for appending.
|
||||
"""
|
||||
error_msg = '%r tag requires a form field followed by a list of attributes and values in the form attr="value"' % token.split_contents()[0]
|
||||
try:
|
||||
bits = token.split_contents()
|
||||
tag_name = bits[0]
|
||||
form_field = bits[1]
|
||||
attr_list = bits[2:]
|
||||
except ValueError:
|
||||
raise TemplateSyntaxError(error_msg)
|
||||
|
||||
form_field = parser.compile_filter(form_field)
|
||||
|
||||
set_attrs = []
|
||||
append_attrs = []
|
||||
for pair in attr_list:
|
||||
match = ATTRIBUTE_RE.match(pair)
|
||||
if not match:
|
||||
raise TemplateSyntaxError(error_msg + ": %s" % pair)
|
||||
dct = match.groupdict()
|
||||
attr, sign, value = dct['attr'], dct['sign'], parser.compile_filter(dct['value'])
|
||||
if sign == "=":
|
||||
set_attrs.append((attr, value))
|
||||
else:
|
||||
append_attrs.append((attr, value))
|
||||
|
||||
return FieldAttributeNode(form_field, set_attrs, append_attrs)
|
||||
|
||||
|
||||
class FieldAttributeNode(Node):
|
||||
def __init__(self, field, set_attrs, append_attrs):
|
||||
self.field = field
|
||||
self.set_attrs = set_attrs
|
||||
self.append_attrs = append_attrs
|
||||
|
||||
def render(self, context):
|
||||
bounded_field = self.field.resolve(context)
|
||||
field = getattr(bounded_field, 'field', None)
|
||||
if (getattr(bounded_field, 'errors', None) and
|
||||
'WIDGET_ERROR_CLASS' in context):
|
||||
bounded_field = append_attr(bounded_field, 'class:%s' %
|
||||
context['WIDGET_ERROR_CLASS'])
|
||||
if field and field.required and 'WIDGET_REQUIRED_CLASS' in context:
|
||||
bounded_field = append_attr(bounded_field, 'class:%s' %
|
||||
context['WIDGET_REQUIRED_CLASS'])
|
||||
for k, v in self.set_attrs:
|
||||
bounded_field = set_attr(bounded_field, '%s:%s' % (k,v.resolve(context)))
|
||||
for k, v in self.append_attrs:
|
||||
bounded_field = append_attr(bounded_field, '%s:%s' % (k,v.resolve(context)))
|
||||
return bounded_field
|
||||
@@ -1,333 +0,0 @@
|
||||
import string
|
||||
try:
|
||||
from django.utils.unittest import expectedFailure
|
||||
except ImportError:
|
||||
def expectedFailure(func):
|
||||
return lambda *args, **kwargs: None
|
||||
|
||||
from django.test import TestCase
|
||||
from django.forms import Form, CharField, TextInput
|
||||
from django import forms
|
||||
from django.template import Template, Context
|
||||
from django.forms.extras.widgets import SelectDateWidget
|
||||
|
||||
# ==============================
|
||||
# Testing helpers
|
||||
# ==============================
|
||||
|
||||
class MyForm(Form):
|
||||
"""
|
||||
Test form. If you want to test rendering of a field,
|
||||
add it to this form and use one of 'render_...' functions
|
||||
from this module.
|
||||
"""
|
||||
simple = CharField()
|
||||
with_attrs = CharField(widget=TextInput(attrs={
|
||||
'foo': 'baz',
|
||||
'egg': 'spam'
|
||||
}))
|
||||
with_cls = CharField(widget=TextInput(attrs={'class':'class0'}))
|
||||
date = forms.DateField(widget=SelectDateWidget(attrs={'egg': 'spam'}))
|
||||
|
||||
|
||||
def render_form(text, form=None, **context_args):
|
||||
"""
|
||||
Renders template ``text`` with widget_tweaks library loaded
|
||||
and MyForm instance available in context as ``form``.
|
||||
"""
|
||||
tpl = Template("{% load widget_tweaks %}" + text)
|
||||
context_args.update({'form': MyForm() if form is None else form})
|
||||
context = Context(context_args)
|
||||
return tpl.render(context)
|
||||
|
||||
|
||||
def render_field(field, template_filter, params, *args, **kwargs):
|
||||
"""
|
||||
Renders ``field`` of MyForm with filter ``template_filter`` applied.
|
||||
``params`` are filter arguments.
|
||||
|
||||
If you want to apply several filters (in a chain),
|
||||
pass extra ``template_filter`` and ``params`` as positional arguments.
|
||||
|
||||
In order to use custom form, pass form instance as ``form``
|
||||
keyword argument.
|
||||
"""
|
||||
filters = [(template_filter, params)]
|
||||
filters.extend(zip(args[::2], args[1::2]))
|
||||
filter_strings = ['|%s:"%s"' % (f[0], f[1],) for f in filters]
|
||||
render_field_str = '{{ form.%s%s }}' % (field, ''.join(filter_strings))
|
||||
return render_form(render_field_str, **kwargs)
|
||||
|
||||
|
||||
def render_field_from_tag(field, *attributes):
|
||||
"""
|
||||
Renders MyForm's field ``field`` with attributes passed
|
||||
as positional arguments.
|
||||
"""
|
||||
attr_strings = [' %s' % f for f in attributes]
|
||||
tpl = string.Template('{% render_field form.$field$attrs %}')
|
||||
render_field_str = tpl.substitute(field=field, attrs=''.join(attr_strings))
|
||||
return render_form(render_field_str)
|
||||
|
||||
|
||||
def assertIn(value, obj):
|
||||
assert value in obj, "%s not in %s" % (value, obj,)
|
||||
|
||||
|
||||
def assertNotIn(value, obj):
|
||||
assert value not in obj, "%s in %s" % (value, obj,)
|
||||
|
||||
|
||||
# ===============================
|
||||
# Test cases
|
||||
# ===============================
|
||||
|
||||
class SimpleAttrTest(TestCase):
|
||||
def test_attr(self):
|
||||
res = render_field('simple', 'attr', 'foo:bar')
|
||||
assertIn('type="text"', res)
|
||||
assertIn('name="simple"', res)
|
||||
assertIn('id="id_simple"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
|
||||
def test_attr_chaining(self):
|
||||
res = render_field('simple', 'attr', 'foo:bar', 'attr', 'bar:baz')
|
||||
assertIn('type="text"', res)
|
||||
assertIn('name="simple"', res)
|
||||
assertIn('id="id_simple"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
assertIn('bar="baz"', res)
|
||||
|
||||
def test_add_class(self):
|
||||
res = render_field('simple', 'add_class', 'foo')
|
||||
assertIn('class="foo"', res)
|
||||
|
||||
def test_add_multiple_classes(self):
|
||||
res = render_field('simple', 'add_class', 'foo bar')
|
||||
assertIn('class="foo bar"', res)
|
||||
|
||||
def test_add_class_chaining(self):
|
||||
res = render_field('simple', 'add_class', 'foo', 'add_class', 'bar')
|
||||
assertIn('class="bar foo"', res)
|
||||
|
||||
def test_set_data(self):
|
||||
res = render_field('simple', 'set_data', 'key:value')
|
||||
assertIn('data-key="value"', res)
|
||||
|
||||
|
||||
class ErrorsTest(TestCase):
|
||||
|
||||
def _err_form(self):
|
||||
form = MyForm({'foo': 'bar'}) # some random data
|
||||
form.is_valid() # trigger form validation
|
||||
return form
|
||||
|
||||
def test_error_class_no_error(self):
|
||||
res = render_field('simple', 'add_error_class', 'err')
|
||||
assertNotIn('class="err"', res)
|
||||
|
||||
def test_error_class_error(self):
|
||||
form = self._err_form()
|
||||
res = render_field('simple', 'add_error_class', 'err', form=form)
|
||||
assertIn('class="err"', res)
|
||||
|
||||
def test_error_attr_no_error(self):
|
||||
res = render_field('simple', 'add_error_attr', 'aria-invalid:true')
|
||||
assertNotIn('aria-invalid="true"', res)
|
||||
|
||||
def test_error_attr_error(self):
|
||||
form = self._err_form()
|
||||
res = render_field('simple', 'add_error_attr', 'aria-invalid:true', form=form)
|
||||
assertIn('aria-invalid="true"', res)
|
||||
|
||||
|
||||
class SilenceTest(TestCase):
|
||||
def test_silence_without_field(self):
|
||||
res = render_field("nothing", 'attr', 'foo:bar')
|
||||
self.assertEqual(res, "")
|
||||
res = render_field("nothing", 'add_class', 'some')
|
||||
self.assertEqual(res, "")
|
||||
|
||||
|
||||
class CustomizedWidgetTest(TestCase):
|
||||
def test_attr(self):
|
||||
res = render_field('with_attrs', 'attr', 'foo:bar')
|
||||
assertIn('foo="bar"', res)
|
||||
assertNotIn('foo="baz"', res)
|
||||
assertIn('egg="spam"', res)
|
||||
|
||||
# see https://code.djangoproject.com/ticket/16754
|
||||
@expectedFailure
|
||||
def test_selectdatewidget(self):
|
||||
res = render_field('date', 'attr', 'foo:bar')
|
||||
assertIn('egg="spam"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
|
||||
def test_attr_chaining(self):
|
||||
res = render_field('with_attrs', 'attr', 'foo:bar', 'attr', 'bar:baz')
|
||||
assertIn('foo="bar"', res)
|
||||
assertNotIn('foo="baz"', res)
|
||||
assertIn('egg="spam"', res)
|
||||
assertIn('bar="baz"', res)
|
||||
|
||||
def test_attr_class(self):
|
||||
res = render_field('with_cls', 'attr', 'foo:bar')
|
||||
assertIn('foo="bar"', res)
|
||||
assertIn('class="class0"', res)
|
||||
|
||||
def test_default_attr(self):
|
||||
res = render_field('with_cls', 'attr', 'type:search')
|
||||
assertIn('class="class0"', res)
|
||||
assertIn('type="search"', res)
|
||||
|
||||
def test_add_class(self):
|
||||
res = render_field('with_cls', 'add_class', 'class1')
|
||||
assertIn('class0', res)
|
||||
assertIn('class1', res)
|
||||
|
||||
def test_add_class_chaining(self):
|
||||
res = render_field('with_cls', 'add_class', 'class1', 'add_class', 'class2')
|
||||
assertIn('class0', res)
|
||||
assertIn('class1', res)
|
||||
assertIn('class2', res)
|
||||
|
||||
|
||||
class FieldReuseTest(TestCase):
|
||||
|
||||
def test_field_double_rendering_simple(self):
|
||||
res = render_form('{{ form.simple }}{{ form.simple|attr:"foo:bar" }}{{ form.simple }}')
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
def test_field_double_rendering_simple_css(self):
|
||||
res = render_form('{{ form.simple }}{{ form.simple|add_class:"bar" }}{{ form.simple|add_class:"baz" }}')
|
||||
self.assertEqual(res.count("baz"), 1)
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
def test_field_double_rendering_attrs(self):
|
||||
res = render_form('{{ form.with_cls }}{{ form.with_cls|add_class:"bar" }}{{ form.with_cls }}')
|
||||
self.assertEqual(res.count("class0"), 3)
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
|
||||
class SimpleRenderFieldTagTest(TestCase):
|
||||
def test_attr(self):
|
||||
res = render_field_from_tag('simple', 'foo="bar"')
|
||||
assertIn('type="text"', res)
|
||||
assertIn('name="simple"', res)
|
||||
assertIn('id="id_simple"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
|
||||
def test_multiple_attrs(self):
|
||||
res = render_field_from_tag('simple', 'foo="bar"', 'bar="baz"')
|
||||
assertIn('type="text"', res)
|
||||
assertIn('name="simple"', res)
|
||||
assertIn('id="id_simple"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
assertIn('bar="baz"', res)
|
||||
|
||||
|
||||
class RenderFieldTagSilenceTest(TestCase):
|
||||
def test_silence_without_field(self):
|
||||
res = render_field_from_tag("nothing", 'foo="bar"')
|
||||
self.assertEqual(res, "")
|
||||
res = render_field_from_tag("nothing", 'class+="some"')
|
||||
self.assertEqual(res, "")
|
||||
|
||||
|
||||
class RenderFieldTagCustomizedWidgetTest(TestCase):
|
||||
def test_attr(self):
|
||||
res = render_field_from_tag('with_attrs', 'foo="bar"')
|
||||
assertIn('foo="bar"', res)
|
||||
assertNotIn('foo="baz"', res)
|
||||
assertIn('egg="spam"', res)
|
||||
|
||||
# see https://code.djangoproject.com/ticket/16754
|
||||
@expectedFailure
|
||||
def test_selectdatewidget(self):
|
||||
res = render_field_from_tag('date', 'foo="bar"')
|
||||
assertIn('egg="spam"', res)
|
||||
assertIn('foo="bar"', res)
|
||||
|
||||
def test_multiple_attrs(self):
|
||||
res = render_field_from_tag('with_attrs', 'foo="bar"', 'bar="baz"')
|
||||
assertIn('foo="bar"', res)
|
||||
assertNotIn('foo="baz"', res)
|
||||
assertIn('egg="spam"', res)
|
||||
assertIn('bar="baz"', res)
|
||||
|
||||
def test_attr_class(self):
|
||||
res = render_field_from_tag('with_cls', 'foo="bar"')
|
||||
assertIn('foo="bar"', res)
|
||||
assertIn('class="class0"', res)
|
||||
|
||||
def test_default_attr(self):
|
||||
res = render_field_from_tag('with_cls', 'type="search"')
|
||||
assertIn('class="class0"', res)
|
||||
assertIn('type="search"', res)
|
||||
|
||||
def test_append_attr(self):
|
||||
res = render_field_from_tag('with_cls', 'class+="class1"')
|
||||
assertIn('class0', res)
|
||||
assertIn('class1', res)
|
||||
|
||||
def test_duplicate_append_attr(self):
|
||||
res = render_field_from_tag('with_cls', 'class+="class1"', 'class+="class2"')
|
||||
assertIn('class0', res)
|
||||
assertIn('class1', res)
|
||||
assertIn('class2', res)
|
||||
|
||||
def test_hyphenated_attributes(self):
|
||||
res = render_field_from_tag('with_cls', 'data-foo="bar"')
|
||||
assertIn('data-foo="bar"', res)
|
||||
assertIn('class="class0"', res)
|
||||
|
||||
|
||||
class RenderFieldWidgetClassesTest(TestCase):
|
||||
def test_use_widget_required_class(self):
|
||||
res = render_form('{% render_field form.simple %}',
|
||||
WIDGET_REQUIRED_CLASS='required_class')
|
||||
self.assertIn('class="required_class"', res)
|
||||
|
||||
def test_use_widget_error_class(self):
|
||||
res = render_form('{% render_field form.simple %}', form=MyForm({}),
|
||||
WIDGET_ERROR_CLASS='error_class')
|
||||
self.assertIn('class="error_class"', res)
|
||||
|
||||
def test_use_widget_error_class_with_other_classes(self):
|
||||
res = render_form('{% render_field form.simple class="blue" %}',
|
||||
form=MyForm({}), WIDGET_ERROR_CLASS='error_class')
|
||||
self.assertIn('class="blue error_class"', res)
|
||||
|
||||
def test_use_widget_required_class_with_other_classes(self):
|
||||
res = render_form('{% render_field form.simple class="blue" %}',
|
||||
form=MyForm({}), WIDGET_REQUIRED_CLASS='required_class')
|
||||
self.assertIn('class="blue required_class"', res)
|
||||
|
||||
|
||||
class RenderFieldTagFieldReuseTest(TestCase):
|
||||
def test_field_double_rendering_simple(self):
|
||||
res = render_form('{{ form.simple }}{% render_field form.simple foo="bar" %}{% render_field form.simple %}')
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
def test_field_double_rendering_simple_css(self):
|
||||
res = render_form('{% render_field form.simple %}{% render_field form.simple class+="bar" %}{% render_field form.simple class+="baz" %}')
|
||||
self.assertEqual(res.count("baz"), 1)
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
def test_field_double_rendering_attrs(self):
|
||||
res = render_form('{% render_field form.with_cls %}{% render_field form.with_cls class+="bar" %}{% render_field form.with_cls %}')
|
||||
self.assertEqual(res.count("class0"), 3)
|
||||
self.assertEqual(res.count("bar"), 1)
|
||||
|
||||
|
||||
class RenderFieldTagUseTemplateVariableTest(TestCase):
|
||||
def test_use_template_variable_in_parametrs(self):
|
||||
res = render_form('{% render_field form.with_attrs egg+="pahaz" placeholder=form.with_attrs.label %}')
|
||||
assertIn('egg="spam pahaz"', res)
|
||||
assertIn('placeholder="With attrs"', res)
|
||||
|
||||
|
||||
class RenderFieldFilter_field_type_widget_type_Test(TestCase):
|
||||
def test_field_type_widget_type_rendering_simple(self):
|
||||
res = render_form('<div class="{{ form.simple|field_type }} {{ form.simple|widget_type }} {{ form.simple.html_name }}">{{ form.simple }}</div>')
|
||||
assertIn('class="charfield textinput simple"', res)
|
||||
Reference in New Issue
Block a user