aboutsummaryrefslogtreecommitdiff
path: root/budget/utils.py
diff options
context:
space:
mode:
authorArnaud Bos <arnaud.tlse@gmail.com>2011-09-11 05:25:42 +0200
committerArnaud Bos <arnaud.tlse@gmail.com>2011-09-11 05:30:28 +0200
commit88cd2f86751621d73574ac56a9d6c4bedcbdd3d5 (patch)
tree14a232f3be23e5785c3b9b37e6d05fbed8d0907f /budget/utils.py
parentf48fc22335f1011bcf376a4f266a35a888f47b2e (diff)
downloadihatemoney-mirror-88cd2f86751621d73574ac56a9d6c4bedcbdd3d5.zip
ihatemoney-mirror-88cd2f86751621d73574ac56a9d6c4bedcbdd3d5.tar.gz
ihatemoney-mirror-88cd2f86751621d73574ac56a9d6c4bedcbdd3d5.tar.bz2
Fix #24 on Authentication and New project forms usability.
- Do not display anymore the identifier field in home. - Let the user enter the id if the slug generated from project name already exists as a project id. - Moved get_billform_for from 'utils' to 'forms', to avoid issue (was 'from forms import ...' into utils, and 'from utils import ...' into forms, which causeed an error).
Diffstat (limited to 'budget/utils.py')
-rw-r--r--budget/utils.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/budget/utils.py b/budget/utils.py
index 262ebfe..f4003eb 100644
--- a/budget/utils.py
+++ b/budget/utils.py
@@ -1,24 +1,19 @@
+import re
from functools import wraps
from flask import redirect, url_for, session, request
from werkzeug.routing import HTTPException, RoutingException
-from models import Bill, Project
-from forms import BillForm
+def slugify(value):
+ """Normalizes string, converts to lowercase, removes non-alpha characters,
+ and converts spaces to hyphens.
-def get_billform_for(project, set_default=True):
- """Return an instance of BillForm configured for a particular project.
-
- :set_default: if set to True, on GET methods (usually when we want to
- display the default form, it will call set_default on it.
-
+ Copy/Pasted from ametaireau/pelican/utils itself took from django sources.
"""
- form = BillForm()
- form.payed_for.choices = form.payer.choices = [(str(m.id), m.name) for m in project.active_members]
- form.payed_for.default = [str(m.id) for m in project.active_members]
-
- if set_default and request.method == "GET":
- form.set_default()
- return form
+ if type(value) == unicode:
+ import unicodedata
+ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
+ value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
+ return re.sub('[-\s]+', '-', value)
class Redirect303(HTTPException, RoutingException):
"""Raise if the map requests a redirect. This is for example the case if