Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added forms.py check for proper variable names #7

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions django_settings/forms.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import re
from django import forms
from django.forms.models import modelform_factory
from django.utils.translation import ugettext_lazy as _
Expand All @@ -16,6 +17,18 @@ class Meta:

value = forms.CharField()

def clean_name(self):
""" Check for any other characters apart from alpha numeric chars
"""

name = self.cleaned_data['name']
res = re.search("[^A-Za-z0-9_]", name)
if res:
raise forms.ValidationError("No spaces or special characters allowed in the name")

return name


def __init__(self, *args, **kwargs):
super(SettingForm, self).__init__(*args, **kwargs)
self.fields['value'] = self.setting_model._meta.get_field('value').formfield()
Expand Down