Skip to content
Browse files

fixed validator so it won't break login

  • Loading branch information...
1 parent 6bfef3c commit 0e86eea18facd373c027b7ae16e47858168b37dc user committed
Showing with 67 additions and 6 deletions.
  1. +17 −0 r2/r2/.project
  2. +10 −0 r2/r2/.pydevproject
  3. +38 −5 r2/r2/controllers/validator/validator.py
  4. +1 −1 r2/r2/templates/createsubreddit.html
  5. +1 −0 r2/run.ini
View
17 r2/r2/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>reddit</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.python.pydev.PyDevBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.python.pydev.pythonNature</nature>
+ </natures>
+</projectDescription>
View
10 r2/r2/.pydevproject
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
+<path>/reddit</path>
+</pydev_pathproperty>
+</pydev_project>
View
43 r2/r2/controllers/validator/validator.py
@@ -99,10 +99,43 @@ def __call__(self, url):
else:
val = self.default
a.append(val)
- if len(a) > 1:
- return self.run(a)
+ return self.run(*a)
+
+class Validator1(object):
+ default_param = None
+ def __init__(self, param=None, default=None, post=True, get=True, url=True):
+ if param:
+ self.param = param
else:
- return self.run(*a)
+ self.param = self.default_param
+
+ self.default = default
+ self.post, self.get, self.url = post, get, url
+
+ def set_error(self, error, msg_params = {}, field = False):
+ """
+ Adds the provided error to c.errors and flags that it is come
+ from the validator's param
+ """
+ if field is False:
+ field = self.param
+
+ c.errors.add(error, msg_params = msg_params, field = field)
+
+ def __call__(self, url):
+ a = []
+ if self.param:
+ for p in utils.tup(self.param):
+ if self.post and request.post.get(p):
+ val = request.post[p]
+ elif self.get and request.get.get(p):
+ val = request.get[p]
+ elif self.url and url.get(p):
+ val = url[p]
+ else:
+ val = self.default
+ a.append(val)
+ return self.run(a)
def build_arg_list(fn, env):
@@ -426,14 +459,14 @@ def run(self, text, text2 = ''):
else:
return text
-class VTest(Validator):
+class VTest(Validator1):
only_whitespace = re.compile(r"\A\s*\Z", re.UNICODE)
def __init__(self, param, max_length,
empty_error = errors.NO_TEXT,
length_error = errors.TOO_LONG,
**kw):
- Validator.__init__(self, param, **kw)
+ Validator1.__init__(self, param, **kw)
self.max_length = max_length
self.length_error = length_error
self.empty_error = empty_error
View
2 r2/r2/templates/createsubreddit.html
@@ -250,7 +250,7 @@
var list = document.getElementById("menu-links");
- li.innerHTML = "<input type=\"text\" id=\"link-url-"+i+"\" value=\"${thing.site.link_urls_0}\" />";
+ li.innerHTML = "<input type=\"text\" id=\"link-url-"+i+"\" value=\"${''}\" />";
list.appendChild(li);
if(i >= 1){
View
1 r2/run.ini

0 comments on commit 0e86eea

Please sign in to comment.
Something went wrong with that request. Please try again.