Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added forms.py check for proper variable names #7

Open
wants to merge 1 commit into from

2 participants

@jaywhy13

Just added a check in the forms.py to ensure that no weird characters like spaces are used in variable names. The only thing allowed is (A-Z, a-z, 0-9, _).

@jaywhy13 jaywhy13 Checked to make sure that the variable name chosen doesn't have chara…
…cters outside of (A-Z, 0-9, _). Memcache complains bitterly about this
db08880
@jqb
Owner

Thank you very much for contribution :)
However could you please explain to me why you think limiting variables names to just A-Z,a-z,0-9 words is better?

@jaywhy13

Oh, I didn't get to run some more tests and pinpoint exactly what the problem was. I was in a bit of a rush. I had set up my cache backend to use Memcache. Memcache complained about the keys with spaces in them though, which I found to be a bit strange. When I try to create a key with spaces from the admin I got an error.

@jqb
Owner

Oh.... you are right! But one little thing - I found it really common to use ":" (colon) and "-" (minus) as a separator for "namespaces" in memcache key names. Please add the possibility to use them.

And don't forget to add your self to "contributor" section as well! :)

@jaywhy13

Huh? Could you explain a little more. By the way, this is my first ever pull request :) so baby steps :D

@jqb
Owner

Ok. It's really common to use memcache keys like: "global:my_setting_1", or "more-concrete-options:setting_2". Also it would be nice to be able to use "-" in key names (like "my-fancy-memcache-key").
So please add both ":" and "-" signs as a possible characters in key names.

And the other thing is: add yourself to README "contributor" section - you can find some other people there - so just and yourself there in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2013
  1. @jaywhy13

    Checked to make sure that the variable name chosen doesn't have chara…

    jaywhy13 authored
    …cters outside of (A-Z, 0-9, _). Memcache complains bitterly about this
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 django_settings/forms.py
View
13 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 _
@@ -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()
Something went wrong with that request. Please try again.