Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from arvindsraj/master
Browse files Browse the repository at this point in the history
Space characters must be lowercase, digits or underscore
  • Loading branch information
oscarcp committed Mar 19, 2012
2 parents f7881e1 + f0e43d4 commit 7fc65a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/e_cidadania/apps/spaces/forms.py
Expand Up @@ -24,11 +24,20 @@
from the data models.
"""

import re

from django import forms
from django.forms import ModelForm
from django.forms.models import modelformset_factory

from e_cidadania.apps.spaces.models import Space, Document, Event, Entity

def is_valid_space_url(space_url):
if re.match('^[a-z0-9_]+$', space_url):
return True
else:
return False

class SpaceForm(ModelForm):

"""
Expand All @@ -42,6 +51,13 @@ class SpaceForm(ModelForm):
class Meta:
model = Space

def clean_url(self):
space_url = self.cleaned_data['url']
if not is_valid_space_url(space_url):
raise forms.ValidationError("Invalid characters in the space URL.")
else:
return space_url

# Create a formset for entities. This formset can be attached to any other form
# but will be usually attached to SpaceForm
EntityFormSet = modelformset_factory(Entity, extra=3)
Expand Down
2 changes: 1 addition & 1 deletion src/e_cidadania/apps/spaces/models.py
Expand Up @@ -49,7 +49,7 @@ class Space(models.Model):
name = models.CharField(_('Name'), max_length=250, unique=True,
help_text=_('Max: 250 characters'))
url = models.CharField(_('URL'), max_length=100, unique=True,
help_text=_('All lowercase. This will be the \
help_text=_('Valid characters are lowercase, digits and underscores. This will be the \
accesible URL'))
description = models.TextField(_('Description'),
default=_('Write here your description.'))
Expand Down

0 comments on commit 7fc65a1

Please sign in to comment.