Self hosted FLOSS fitness/workout, nutrition and weight tracker
Allow non-admin users to submit exercises, this fixes issue #7
Roland Geiderd614c627cc24
diff --git a/wger/exercises/migrations/0002_auto__add_field_exercise_user__add_field_exercise_status.py b/wger/exercises/migrations/0002_auto__add_field_exercise_user__add_field_exercise_status.pynew file mode 100644index 000000000..629c4def0--- /dev/null+++ b/wger/exercises/migrations/0002_auto__add_field_exercise_user__add_field_exercise_status.py@@ -0,0 +1,104 @@+# -*- coding: utf-8 -*-+import datetime+from south.db import db+from south.v2 import SchemaMigration+from django.db import models+++class Migration(SchemaMigration):++ def forwards(self, orm):+ # Adding field 'Exercise.user'+ db.add_column('exercises_exercise', 'user',+ self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True),+ keep_default=False)++ # Adding field 'Exercise.status'+ db.add_column('exercises_exercise', 'status',+ self.gf('django.db.models.fields.CharField')(default=1, max_length=2),+ keep_default=False)+++ def backwards(self, orm):+ # Deleting field 'Exercise.user'+ db.delete_column('exercises_exercise', 'user_id')++ # Deleting field 'Exercise.status'+ db.delete_column('exercises_exercise', 'status')+++ models = {+ 'auth.group': {+ 'Meta': {'object_name': 'Group'},+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})+ },+ 'auth.permission': {+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})+ },+ 'auth.user': {+ 'Meta': {'object_name': 'User'},+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})+ },+ 'contenttypes.contenttype': {+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})+ },+ 'exercises.exercise': {+ 'Meta': {'ordering': "['name']", 'object_name': 'Exercise'},+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exercises.ExerciseCategory']"}),+ 'description': ('django.db.models.fields.TextField', [], {'max_length': '2000', 'blank': 'True'}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'muscles': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['exercises.Muscle']", 'symmetrical': 'False'}),+ 'muscles_secondary': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'secondary_muscles'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['exercises.Muscle']"}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),+ 'status': ('django.db.models.fields.CharField', [], {'default': '1', 'max_length': '2'}),+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'})+ },+ 'exercises.exercisecategory': {+ 'Meta': {'ordering': "['name']", 'object_name': 'ExerciseCategory'},+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'language': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exercises.Language']"}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})+ },+ 'exercises.exercisecomment': {+ 'Meta': {'object_name': 'ExerciseComment'},+ 'comment': ('django.db.models.fields.CharField', [], {'max_length': '200'}),+ 'exercise': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exercises.Exercise']"}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})+ },+ 'exercises.language': {+ 'Meta': {'object_name': 'Language'},+ 'full_name': ('django.db.models.fields.CharField', [], {'max_length': '30'}),+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'short_name': ('django.db.models.fields.CharField', [], {'max_length': '2'})+ },+ 'exercises.muscle': {+ 'Meta': {'ordering': "['name']", 'object_name': 'Muscle'},+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'is_front': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})+ }+ }++ complete_apps = ['exercises']\ No newline at end of filediff --git a/wger/exercises/models.py b/wger/exercises/models.pyindex 11b6d853c..95fedaf57 100644--- a/wger/exercises/models.py+++ b/wger/exercises/models.py@@ -18,6 +18,7 @@from django.db import modelsfrom django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!+from django.contrib.auth.models import Userfrom django.utils.translation import ugettext_lazy as _from django.core.urlresolvers import reverse@@ -98,10 +99,33 @@ class ExerciseCategory(models.Model):return False+EXERCISE_STATUS_PENDING = 1+EXERCISE_STATUS_ACCEPTED = 2+EXERCISE_STATUS_DECLINED = 3+EXERCISE_STATUS_ADMIN = 3++EXERCISE_STATUS = (+ (EXERCISE_STATUS_PENDING, _('Pending')),+ (EXERCISE_STATUS_ACCEPTED, _('Accepted')),+ (EXERCISE_STATUS_DECLINED, _('Declined')),+ (EXERCISE_STATUS_ADMIN, _('Submitted by administrator')),+)++class Exercise(models.Model):'''Model for an exercise'''++ # The user that submitted the exercise+ user = models.ForeignKey(User, verbose_name=_('User'), null=True, blank=True)++ # Status+ status = models.CharField(max_length=2,+ choices=EXERCISE_STATUS,+ default=EXERCISE_STATUS_PENDING)++ # Exercise descriptioncategory = models.ForeignKey(ExerciseCategory,verbose_name=_('Category'))description = models.TextField(max_length=2000,diff --git a/wger/exercises/templates/exercise/form.html b/wger/exercises/templates/exercise/form.htmlnew file mode 100644index 000000000..45570aa14--- /dev/null+++ b/wger/exercises/templates/exercise/form.html@@ -0,0 +1,12 @@+{% load i18n %}++{% if not perms.exercises %}+<h3>{% trans "Submitting an exercise" %}</h3>+<p><strong>{% blocktrans %}Thank you for submitting an exercise. This is much+appreciated!{% endblocktrans %}</strong></p>++<p>{% blocktrans %}After you submit the form, the administrators will be notified.+Once the exercise is reviewed, it will be added to the database. Till this happens,+it will not be visible in the overview or the search. In case you added your email+when you registered, you will get notified when the process is completed sucessfully.{% endblocktrans %}</p>+{% endif %}\ No newline at end of filediff --git a/wger/exercises/templates/overview.html b/wger/exercises/templates/overview.htmlindex 81ecc893b..ae718b2c2 100644--- a/wger/exercises/templates/overview.html+++ b/wger/exercises/templates/overview.html@@ -118,20 +118,22 @@ $(document).ready(function() {Side bar-->{% block sidebar %}+{% if user.is_authenticated and not user.get_profile.is_temporary %}+<h3>{% trans "Add new exercise" %}</h3>+<p>+ <a href="{% url 'exercise-add' %}">+ <img src="{% static 'images/icons/new.svg' %}"+ width="32"+ height="32"+ alt="{% trans 'Add new exercise' %}"+ title="{% trans 'Add new exercise' %}">+ {% trans "Add new exercise" %}+ </a>+ </p>+{% endif %}+{% if perms.exercises %}<h3>{% trans "Options" %}</h3>-- <p>- <a href="{% url 'exercise-add' %}"- class="modal-dialog">- <img src="{% static 'images/icons/new.svg' %}"- width="32"- height="32"- alt="{% trans 'Add new exercise' %}"- title="{% trans 'Add new exercise' %}">- {% trans "Add new exercise" %}- </a>- </p><p>{% with category=categories|first %}<a href="{% url 'exercisecategory-edit' category.id %}"diff --git a/wger/exercises/tests/exercise.py b/wger/exercises/tests/exercise.pyindex 90a9ef4d9..5a650ff62 100644--- a/wger/exercises/tests/exercise.py+++ b/wger/exercises/tests/exercise.py@@ -17,6 +17,10 @@ import jsonfrom django.core.urlresolvers import reversefrom wger.exercises.models import Exercise+from wger.exercises.models import EXERCISE_STATUS_PENDING+from wger.exercises.models import EXERCISE_STATUS_ACCEPTED+from wger.exercises.models import EXERCISE_STATUS_DECLINED+from wger.exercises.models import EXERCISE_STATUS_ADMINfrom wger.manager.tests.testcase import WorkoutManagerTestCasefrom wger.manager.tests.testcase import WorkoutManagerDeleteTestCase@@ -24,7 +28,7 @@ from wger.manager.tests.testcase import WorkoutManagerDeleteTestCaseclass ExerciseIndexTestCase(WorkoutManagerTestCase):- def exercise_index(self, editor=False):+ def exercise_index(self, logged_in=True, demo=False, admin=False):'''Tests the exercise overview page'''@@ -57,24 +61,29 @@ class ExerciseIndexTestCase(WorkoutManagerTestCase):self.assertEqual(exercise_2.name, "An exercise")# Only authorized users see the edit links- if editor:+ if admin:self.assertContains(response, 'Add new exercise')self.assertContains(response, 'Edit category')self.assertContains(response, 'Delete category')self.assertContains(response, 'Add category')else:- self.assertNotContains(response, 'Add new exercise')self.assertNotContains(response, 'Edit category')self.assertNotContains(response, 'Delete category')self.assertNotContains(response, 'Add category')+ if logged_in and not demo:+ self.assertContains(response, 'Add new exercise')++ if logged_in and demo:+ self.assertNotContains(response, 'Add new exercise')+def test_exercise_index_editor(self):'''Tests the exercise overview page as a logged in user with editor rights'''self.user_login('admin')- self.exercise_index(editor=True)+ self.exercise_index(admin=True)def test_exercise_index_non_editor(self):'''@@ -82,14 +91,22 @@ class ExerciseIndexTestCase(WorkoutManagerTestCase):'''self.user_login('test')- self.exercise_index(editor=False)+ self.exercise_index()++ def test_exercise_index_demo_user(self):+ '''+ Tests the exercise overview page as a logged in demo user+ '''++ self.user_login('demo')+ self.exercise_index(demo=True)def test_exercise_index_logged_out(self):'''Tests the exercise overview page as an anonymous (logged out) user'''- self.exercise_index(editor=False)+ self.exercise_index(logged_in=False)class ExerciseDetailTestCase(WorkoutManagerTestCase):@@ -180,16 +197,14 @@ class ExercisesTestCase(WorkoutManagerTestCase):# Exercise was not addedself.assertEqual(count_before, count_after)- self.assertTrue('login' in response['location'])- def test_add_exercise_user_no_rights(self):+ def test_add_exercise_temp_user(self):'''- Tests adding an exercise with a user without enough rights to do this+ Tests adding an exercise with a logged in demo user'''- self.user_login('test')+ self.user_login('demo')self.add_exercise_user_fail()- self.user_logout()def test_add_exercise_no_user(self):'''@@ -200,7 +215,7 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.add_exercise_user_fail()self.user_logout()- def test_add_exercise_administrator_user(self):+ def add_exercise_success(self, demo=False, admin=False):'''Tests adding/editing an exercise with a user with enough rights to do this'''@@ -223,6 +238,13 @@ class ExercisesTestCase(WorkoutManagerTestCase):exercise_id = response.context['exercise'].id# Exercise was saved+ exercise = Exercise.objects.get(pk=exercise_id)+ if demo:+ exercise.user_id = 3+ exercise.status = EXERCISE_STATUS_PENDING+ if admin:+ exercise.user_id = 1+ exercise.status = EXERCISE_STATUS_ADMINresponse = self.client.get(reverse('wger.exercises.views.exercises.view',kwargs={'id': exercise_id}))self.assertEqual(response.status_code, 200)@@ -262,6 +284,23 @@ class ExercisesTestCase(WorkoutManagerTestCase):self.assertTrue(response.context['form'].errors['muscles'])self.user_logout()+ def test_add_exercise_success(self):+ '''+ Tests adding/editing an exercise with a user with enough rights to do this+ '''++ # Log in as 'admin'+ self.user_login('admin')+ self.add_exercise_success()++ def test_add_exercise_user_no_rights(self):+ '''+ Tests adding an exercise with a user without enough rights to do this+ '''++ self.user_login('test')+ self.add_exercise_success()+def search_exercise(self, fail=True):'''Helper function to test searching for exercisesdiff --git a/wger/exercises/urls.py b/wger/exercises/urls.pyindex 1e52f39a5..439285ead 100644--- a/wger/exercises/urls.py+++ b/wger/exercises/urls.py@@ -1,5 +1,6 @@from django.conf.urls import patterns, urlfrom django.contrib.auth.decorators import permission_required+from django.contrib.auth.decorators import login_requiredfrom wger.exercises.views import exercisesfrom wger.exercises.views import comments@@ -15,7 +16,7 @@ urlpatterns = patterns('wger.exercises.views',url(r'^(?P<id>\d+)/view/(?P<slug>[-\w]+)/$', 'exercises.view'),url(r'^(?P<id>\d+)/view/$', 'exercises.view'),url(r'^add/$',- permission_required('exercises.change_exercise')(exercises.ExerciseAddView.as_view()),+ login_required(exercises.ExerciseAddView.as_view()),name='exercise-add'),url(r'^(?P<pk>\d+)/edit/$',permission_required('exercises.change_exercise')(exercises.ExerciseUpdateView.as_view()),diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.pyindex ae9ae83f4..44faead7f 100644--- a/wger/exercises/views/exercises.py+++ b/wger/exercises/views/exercises.py@@ -22,6 +22,7 @@ from django.shortcuts import render_to_responsefrom django.shortcuts import get_object_or_404from django.http import HttpResponsefrom django.http import HttpResponseRedirect+from django.http import HttpResponseForbiddenfrom django.forms import ModelFormfrom django.forms import ModelChoiceFieldfrom django.core.context_processors import csrf@@ -44,6 +45,10 @@ from wger.exercises.models import Exercisefrom wger.exercises.models import ExerciseCommentfrom wger.exercises.models import ExerciseCategoryfrom wger.exercises.models import Muscle+from wger.exercises.models import EXERCISE_STATUS_PENDING+from wger.exercises.models import EXERCISE_STATUS_ACCEPTED+from wger.exercises.models import EXERCISE_STATUS_DECLINED+from wger.exercises.models import EXERCISE_STATUS_ADMINfrom wger.workout_manager.generic_views import YamlFormMixinfrom wger.workout_manager.generic_views import YamlDeleteMixin@@ -138,6 +143,7 @@ class ExercisesEditAddView(YamlFormMixin):share all this settings'''model = Exercise+ sidebar = 'exercise/form.html'form_fields = ['name','category',@@ -157,11 +163,11 @@ class ExercisesEditAddView(YamlFormMixin):class ExerciseForm(ModelForm):language = load_language()category = ModelChoiceField(queryset=ExerciseCategory.objects.filter(- language=language.id)- )+ language=language.id))class Meta:model = Exercise+ exclude = ('status',)class Media:js = ('js/tinymce/tiny_mce.js',)@@ -189,6 +195,27 @@ class ExerciseAddView(ExercisesEditAddView, CreateView):form_action = reverse_lazy('exercise-add')+ def form_valid(self, form):+ '''+ Set the user that submitted the exercise+ '''++ # set the submitter, if admin, set approrpiate status+ form.instance.user = self.request.user+ if self.request.user.has_perm('exercises.add_exercise'):+ form.instance.status = EXERCISE_STATUS_ADMIN++ return super(ExerciseAddView, self).form_valid(form)++ def dispatch(self, request, *args, **kwargs):+ '''+ Demo users can't submit exercises+ '''+ if request.user.get_profile().is_temporary:+ return HttpResponseForbidden()++ return super(ExerciseAddView, self).dispatch(request, *args, **kwargs)+class ExerciseDeleteView(YamlDeleteMixin, DeleteView):'''diff --git a/wger/manager/fixtures/test-user-data.json b/wger/manager/fixtures/test-user-data.jsonindex a9791c440..4d9528819 100644--- a/wger/manager/fixtures/test-user-data.json+++ b/wger/manager/fixtures/test-user-data.json@@ -55,5 +55,53 @@"email": "","date_joined": "2012-09-26T19:11:43.114Z"}+ },+ {+ "pk": 3,+ "model": "auth.user",+ "fields": {+ "username": "demo",+ "first_name": "",+ "last_name": "",+ "is_active": true,+ "is_superuser": false,+ "is_staff": false,+ "last_login": "2013-03-30T00:23:21.592Z",+ "groups": [],+ "user_permissions": [],+ "password": "pbkdf2_sha256$10000$ncxgfFxHcKK3$oiXpDkxJ1ox765pRuMQh/s50yq7GUPayinBFb6ReeX4=",+ "email": "",+ "date_joined": "2013-03-30T00:23:21.592Z"+ }+ },+ {+ "pk": 1,+ "model": "manager.userprofile",+ "fields": {+ "is_temporary": false,+ "show_comments": false,+ "show_english_ingredients": false,+ "user": 1+ }+ },+ {+ "pk": 2,+ "model": "manager.userprofile",+ "fields": {+ "is_temporary": false,+ "show_comments": false,+ "show_english_ingredients": false,+ "user": 2+ }+ },+ {+ "pk": 3,+ "model": "manager.userprofile",+ "fields": {+ "is_temporary": true,+ "show_comments": false,+ "show_english_ingredients": false,+ "user": 3+ }}]diff --git a/wger/manager/templates/form.html b/wger/manager/templates/form.htmlindex e711a58f5..75d2c0050 100644--- a/wger/manager/templates/form.html+++ b/wger/manager/templates/form.html@@ -51,4 +51,4 @@<!--Side bar-->-{% block sidebar %}{{sidebar|safe}}{% endblock %}+{% block sidebar %}{% if sidebar %}{% include sidebar %}{% endif %}{% endblock %}diff --git a/wger/manager/templates/tags/yaml_form_element.html b/wger/manager/templates/tags/yaml_form_element.htmlindex 29fd0497c..a3d5a2953 100644--- a/wger/manager/templates/tags/yaml_form_element.html+++ b/wger/manager/templates/tags/yaml_form_element.html@@ -5,6 +5,7 @@<label for="{{field.auto_id}}">{% trans field.label %}</label>+ {% if not field.field.required %}<span style="font-size:90%;">— <em>{% trans "Optional" %}</em></span>{% endif %}{% if field.errors %}</span></div>{% endif %}</td><td>diff --git a/wger/manager/tests/demo_user.py b/wger/manager/tests/demo_user.pyindex 04498f01f..6a17f4112 100644--- a/wger/manager/tests/demo_user.py+++ b/wger/manager/tests/demo_user.py@@ -21,10 +21,13 @@ from wger.manager.tests.testcase import WorkoutManagerTestCaseclass DemoUserTestCase(WorkoutManagerTestCase):'''- Tests creating a demo user+ Tests the demo user'''def test_demo_user(self):+ '''+ Tests creating a demo user+ '''# Open the copy workout formresponse = self.client.get(reverse('demo-account'))@@ -41,4 +44,21 @@ class DemoUserTestCase(WorkoutManagerTestCase):# Check that the demo user was correctly createdself.assertEqual(count_before + 1, count_after)- self.assertTrue(User.objects.filter(userprofile__is_temporary=1).count(), 1)+ self.assertTrue(User.objects.filter(userprofile__is_temporary=1).count(), 2)++ def test_demo_user_notice(self):+ '''+ Tests that demo users see a notice on every page+ '''+ demo_notice_text = 'You are using a temporary account'+ self.user_login('demo')+ self.assertContains(self.client.get(reverse('dashboard')), demo_notice_text)+ self.assertContains(self.client.get(reverse('wger.manager.views.workout.overview')),+ demo_notice_text)+ self.assertContains(self.client.get(reverse('wger.exercises.views.exercises.overview')),+ demo_notice_text)+ self.assertContains(self.client.get(reverse('muscle-overview')), demo_notice_text)+ self.assertContains(self.client.get(reverse('wger.nutrition.views.plan.overview')),+ demo_notice_text)+ self.assertContains(self.client.get(reverse('software:issues')), demo_notice_text)+ self.assertContains(self.client.get(reverse('software:license')), demo_notice_text)diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex 20c22dd8d..2a2a0d3bc 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -14,6 +14,7 @@import osimport decimal+import loggingfrom django.core.urlresolvers import reversefrom django.core.urlresolvers import NoReverseMatch@@ -40,6 +41,7 @@ class WorkoutManagerTestCase(TestCase):Overwrite some of Django's settings here'''os.environ['RECAPTCHA_TESTING'] = 'True'+ logging.disable(logging.ERROR)def tearDown(self):'''diff --git a/wger/workout_manager/__init__.py b/wger/workout_manager/__init__.pyindex 22fe8c9de..7b4894882 100644--- a/wger/workout_manager/__init__.py+++ b/wger/workout_manager/__init__.py@@ -34,3 +34,5 @@ def get_version(version=None, release=None):sub = ''if not release:sub += '-dev'++ return main + subdiff --git a/wger/workout_manager/generic_views.py b/wger/workout_manager/generic_views.pyindex d716b5a74..d3b77d1f9 100644--- a/wger/workout_manager/generic_views.py+++ b/wger/workout_manager/generic_views.py@@ -36,14 +36,48 @@ class YamlFormMixin(ModelFormMixin):template_name = 'form.html'form_fields = []+ '''+ The form fields to be displayed. If left unset, the ones from the form+ will be used.+ '''+custom_js = ''+ '''+ Custom javascript to be executed.+ '''+form_action = ''form_action_urlname = ''+ sidebar = ''+ '''+ Name of a template that will be included in the sidebar+ '''+title = ''+ '''+ Title used in the form+ '''+owner_object = False+ '''+ The object that holds the owner information. This only needs to be set if+ the model doesn't provide a get_owner_object() method+ '''+submit_text = ugettext_lazy('Save')+ '''+ Text used in the submit button, default _('save')+ '''+clean_html = ()+ '''+ List of form fields that should be passed to bleach to clean the html+ '''+messages = ''+ '''+ A message to display on sucess+ '''def get_context_data(self, **kwargs):'''@@ -56,6 +90,8 @@ class YamlFormMixin(ModelFormMixin):# CSRF tokencontext.update(csrf(self.request))+ context['sidebar'] = self.sidebar+# Custom order for form fields. The list comprehension is to avoid# weird problems with django's template when accessing the fields with "form.fieldname"if self.form_fields:@@ -130,6 +166,13 @@ class YamlFormMixin(ModelFormMixin):'''return self.messages+ def form_invalid(self, form):+ '''+ Log form errors to the console+ '''+ logger.debug(form.errors)+ return super(YamlFormMixin, self).form_invalid(form)+def form_valid(self, form):'''Pre-process the form, cleaning up the HTML code found in the fields