Skip to content

Loading…

불필요한 import 제거 #4

Merged
merged 3 commits into from

2 participants

@Kroisse
LangDev member

불필요한 import문과 web 패키지 밑의 from ... import * 구문들을 없애고, 덤으로 잠재적인 이름 오류도 하나 잡았습니다.

@Kroisse Kroisse commented on the diff
langdev/web/forum.py
@@ -165,7 +166,7 @@ def get_comment(comment_id, post_id=None):
def write_comment(post_id, comment_id=None):
if comment_id:
parent = get_comment(comment_id, post_id)
- post_object = comment_object.post
+ post_object = parent.post
@Kroisse LangDev member
Kroisse added a note

주변에 comment_object로 예상되는 게 parent밖에 없어서 저기다 붙였는데 맞게 고친 건지 잘 모르겠네요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dahlia dahlia merged commit ec81d49 into langdev:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
1 langdev/objsimplify.py
@@ -2,7 +2,6 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-import types
import collections
import langdev.util.visitor
import langdev.user
View
52 langdev/web/__init__.py
@@ -6,16 +6,16 @@
.. seealso::
- Module :mod:`langdev.web.home`
+ Blueprint :mod:`langdev.web.home`
Website home.
- Module :mod:`langdev.web.user`
+ Blueprint :mod:`langdev.web.user`
User authentications, personal pages, and so on.
- Module :mod:`langdev.web.forum`
+ Blueprint :mod:`langdev.web.forum`
Forum post pages and comments.
- Module :mod:`langdev.web.thirdparty`
+ Blueprint :mod:`langdev.web.thirdparty`
Third-party applications.
Module :mod:`langdev.web.pager`
@@ -53,16 +53,16 @@
import langdev.orm
-#: The :class:`dict` of modules to be registered by default.
+#: The :class:`dict` of blueprints to be registered by default.
#: Keys are import names in string, and values are keyword arguments for
-#: :meth:`flask.Flask.register_module()` method. ::
+#: :meth:`flask.Flask.register_blueprint()` method. ::
#:
-#: modules = {'module.name:var': {'url_prefix': '/path'},
-#: 'module.name2:var2': {}}
+#: blueprints = {'module.name:blueprint': {'url_prefix': '/path'},
+#: 'module.name2:blueprint2': {}}
#:
-#: It can be extended by ``MODULES`` configuration also::
+#: It can be extended by ``BLUEPRINTS`` configuration also::
#:
-#: MODULES = {'module.name:var': {}}
+#: BLUEPRINTS = {'module.name:var': {}}
#:
#: .. seealso::
#:
@@ -70,15 +70,15 @@
#: The function that imports an object based on a string, provided by
#: Werkzeug_.
#:
-#: Flask --- :ref:`working-with-modules`
-#: Flask_ provides 'module' facilities for large applications.
+#: Flask --- :ref:`modular-applications-with-blueprints`
+#: Flask_ provides 'blueprint' facilities for large applications.
#:
#: .. _Werkzeug: http://werkzeug.pocoo.org/
#: .. _Flask: http://flask.pocoo.org/
-modules = {'langdev.web.home:home': {},
- 'langdev.web.user:user': {'url_prefix': '/users'},
- 'langdev.web.forum:forum': {'url_prefix': '/posts'},
- 'langdev.web.thirdparty:thirdparty': {'url_prefix': '/apps'}}
+blueprints = {'langdev.web.home:home': {},
+ 'langdev.web.user:user': {'url_prefix': '/users'},
+ 'langdev.web.forum:forum': {'url_prefix': '/posts'},
+ 'langdev.web.thirdparty:thirdparty': {'url_prefix': '/apps'}}
#: The list of WSGI middlewares to hook in. Its elements are import names in
#: string. ::
@@ -189,11 +189,11 @@ def app(app):
else:
raise TypeError('modifier must be a callable object, not ' +
repr(modifier))
- mods = dict(modules)
- mods.update(app.config.get('MODULES', {}))
- for import_name, kwargs in modules.iteritems():
- modobj = werkzeug.utils.import_string(import_name)
- app.register_module(modobj, **(kwargs or {}))
+ mods = dict(blueprints)
+ mods.update(app.config.get('BLUEPRINTS', {}))
+ for import_name, kwargs in mods.iteritems():
+ bp = werkzeug.utils.import_string(import_name)
+ app.register_blueprint(bp, **(kwargs or {}))
app.before_request_funcs.setdefault(None, []).extend(before_request_funcs)
app.after_request_funcs.setdefault(None, []).extend(after_request_funcs)
app.error_handlers.update(error_handlers)
@@ -290,12 +290,10 @@ def method_for(endpoint):
"""
ctx = flask.globals._request_ctx_stack.top
- if '.' not in endpoint:
- mod = ctx.request.module
- if mod is not None:
- endpoint = mod + '.' + endpoint
- elif endpoint.startswith('.'):
- endpoint = endpoint[1:]
+ if endpoint.startswith('.'):
+ bp = ctx.request.blueprint
+ if bp is not None:
+ endpoint = bp + endpoint
methods = ctx.app.url_map._rules_by_endpoint[endpoint][0].methods
try:
return iter(methods.difference(['HEAD', 'OPTIONS'])).next()
View
43 langdev/web/forum.py
@@ -4,8 +4,9 @@
"""
import re
import math
-from flask import *
-from flaskext.wtf import *
+from flask import (Blueprint, request, g, abort, render_template,
+ make_response, redirect, url_for)
+from flask.ext import wtf
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from langdev.forum import Post, Comment
from langdev.web import render
@@ -13,10 +14,10 @@
import langdev.web.pager
-#: Forum web pages module.
+#: Forum web pages blueprint.
#:
-#: .. seealso:: Flask --- :ref:`working-with-modules`
-forum = Module(__name__)
+#: .. seealso:: Flask --- :ref:`modular-applications-with-blueprints`
+forum = Blueprint('forum', __name__)
def get_post(post_id):
@@ -71,22 +72,22 @@ def atom():
return response
-class PostForm(Form):
+class PostForm(wtf.Form):
- title = TextField('Title', validators=[Required()],
- description='This will be shown on the list.')
- body = TextAreaField('Body', validators=[Required()],
- description='Markdown format enabled.')
- sticky = BooleanField('Sticky',
- description='Show this post always on top.')
- submit = SubmitField('Submit')
+ title = wtf.TextField('Title', validators=[wtf.Required()],
+ description='This will be shown on the list.')
+ body = wtf.TextAreaField('Body', validators=[wtf.Required()],
+ description='Markdown format enabled.')
+ sticky = wtf.BooleanField('Sticky',
+ description='Show this post always on top.')
+ submit = wtf.SubmitField('Submit')
-class CommentForm(Form):
+class CommentForm(wtf.Form):
@Kroisse LangDev member
Kroisse added a note

주변에 comment_object로 예상되는 게 parent밖에 없어서 저기다 붙였는데 맞게 고친 건지 잘 모르겠네요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
parent = QuerySelectField('Reply to', allow_blank=True)
- body = TextAreaField('Comment', validators=[Required()])
- submit = SubmitField('Submit')
+ body = wtf.TextAreaField('Comment', validators=[wtf.Required()])
+ submit = wtf.SubmitField('Submit')
def fill_comments(self, post):
self.parent.query = post.comments
@@ -117,7 +118,7 @@ def write():
form.populate_obj(post)
with g.session.begin():
g.session.add(post)
- return redirect(url_for('post', post_id=post.id), 302)
+ return redirect(url_for('.post', post_id=post.id), 302)
return write_form(form=form)
@@ -147,7 +148,7 @@ def delete(post_id):
langdev.web.user.ensure_signin(post.author)
with g.session.begin():
g.session.delete(post)
- return redirect(url_for('posts'), 302)
+ return redirect(url_for('.posts'), 302)
def get_comment(comment_id, post_id=None):
@@ -165,7 +166,7 @@ def get_comment(comment_id, post_id=None):
def write_comment(post_id, comment_id=None):
if comment_id:
parent = get_comment(comment_id, post_id)
- post_object = comment_object.post
+ post_object = parent.post
else:
post_object = get_post(post_id)
parent = None
@@ -187,7 +188,7 @@ def comment(post_id, comment_id):
response = render('forum/base', comment, comment=comment)
if re.match(r'^(application/xhtml\+xml|text/html)\s*($|;)',
response.content_type):
- return redirect(url_for('post', post_id=post_id) +
+ return redirect(url_for('.post', post_id=post_id) +
'#comment-{0}'.format(comment.id))
return response
@@ -198,5 +199,5 @@ def delete_comment(post_id, comment_id):
langdev.web.user.ensure_signin(comment.author)
with g.session.begin():
g.session.delete(comment)
- return redirect(url_for('post', post_id=post_id), 302)
+ return redirect(url_for('.post', post_id=post_id), 302)
View
8 langdev/web/home.py
@@ -2,13 +2,13 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-from flask import *
+from flask import Blueprint, redirect, url_for
-#: Home module.
+#: Home blueprint.
#:
-#: .. seealso:: Flask --- :ref:`working-with-modules`
-home = Module(__name__)
+#: .. seealso:: Flask --- :ref:`modular-applications-with-blueprints`
+home = Blueprint('home', __name__)
@home.route('/')
View
3 langdev/web/serializers.py
@@ -6,8 +6,7 @@
import datetime
import plistlib
import flask
-import langdev.user
-from langdev.objsimplify import *
+from langdev.objsimplify import simplify, camelCase, PascalCase
def json(value):
View
2 langdev/web/templates/base.html
@@ -1,6 +1,6 @@
{% from 'macro.html' import only_for_style %}
{%- macro static_url_for(filename) -%}
- {%- set url = url_for('.static', filename=filename) -%}
+ {%- set url = url_for('static', filename=filename) -%}
{%- if config['DEBUG'] -%} {{ url.replace('.min.', '.') }}
{%- else -%} {{ url }} {%- endif -%}
{%- endmacro -%}
View
8 langdev/web/templates/forum/atom.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <id>{{ url_for('posts', _external=True) }}</id>
+ <id>{{ url_for('.posts', _external=True) }}</id>
<title>LangDev</title>
- <link href="{{ url_for('posts', _external=True) }}" rel="alternate" />
+ <link href="{{ url_for('.posts', _external=True) }}" rel="alternate" />
<link href="{{ request.url }}" rel="self" />
{% for post in posts %}
@@ -10,9 +10,9 @@
<updated>{{ post.modified_at.isoformat() }}</updated>
{% endif %}
<entry>
- <id>{{ url_for('post', post_id=post.id, _external=True) }}</id>
+ <id>{{ url_for('.post', post_id=post.id, _external=True) }}</id>
<title>{{ post.title }}</title>
- <link href="{{ url_for('post', post_id=post.id, _external=True) }}"
+ <link href="{{ url_for('.post', post_id=post.id, _external=True) }}"
rel="alternate" />
<author>
<name>{{ post.author }}</name>
View
2 langdev/web/templates/forum/edit_form.html
@@ -4,5 +4,5 @@
{% if form.errors %}
{{ form.errors }}
{% endif %}
- {{ render_form(form, 'edit', post_id=post.id) }}
+ {{ render_form(form, '.edit', post_id=post.id) }}
{% endblock %}
View
10 langdev/web/templates/forum/post.html
@@ -4,7 +4,7 @@
{{ post }} &#8212; {{ super() }}
{%- endblock %}
{% block head %}
- <link rel="canonical" href="{{ url_for('post', post_id=post.id,
+ <link rel="canonical" href="{{ url_for('.post', post_id=post.id,
_external=True) }}" />
{% endblock %}
{% block body %}
@@ -15,15 +15,15 @@
<time datetime="{{ post.created_at.isoformat() }}">
{{- post.created_at }}</time>
{% if post.author == current_user %}
- <a href="{{ url_for('edit_form', post_id=post.id) }}">Edit</a>
- {% call render_raw_form('delete', post_id=post.id) %}
+ <a href="{{ url_for('.edit_form', post_id=post.id) }}">Edit</a>
+ {% call render_raw_form('.delete', post_id=post.id) %}
<button type="submit">Delete</button>
{% endcall %}
{% endif %}
<div class="body">{{ post.body_html|safe }}</div>
{{ comments(post) }}
{% if current_user %}
- {{ render_form(comment_form, 'write_comment', post_id=post.id) }}
+ {{ render_form(comment_form, '.write_comment', post_id=post.id) }}
{% endif %}
</article>
{% endblock %}
@@ -41,7 +41,7 @@
<time datetime="{{ comment.created_at.isoformat() }}">
{{- comment.created_at }}</time>
{% if comment.author == current_user %}
- {% call render_raw_form('delete_comment', post_id=comment.post_id,
+ {% call render_raw_form('.delete_comment', post_id=comment.post_id,
comment_id=comment.id) %}
<button type="submit">Delete</button>
{% endcall %}
View
14 langdev/web/templates/forum/posts.html
@@ -2,16 +2,16 @@
{% from 'pager.html' import render_pager %}
{% block head %}
<link rel="alternate"
- href="{{ config.get('FORUM_FEED_HREF', url_for('atom', _external=True)) }}"
+ href="{{ config.get('FORUM_FEED_HREF', url_for('.atom', _external=True)) }}"
type="{{ config.get('FORUM_FEED_TYPE', 'application/atom+xml') }}" />
{% if next %}
- <link rel="next" href="{{ url_for('posts', next=next.id,
+ <link rel="next" href="{{ url_for('.posts', next=next.id,
limit=limit, view=view) }}" />
{% endif %}
{% endblock %}
{% block body %}
{% if current_user %}
- <a href="{{ url_for('write_form') }}"
+ <a href="{{ url_for('.write_form') }}"
class="btn large">Write a post</a>
{% endif %}
{% if view == 'summary' %}
@@ -42,7 +42,7 @@
</a>
</td>
<td class="title">
- <a href="{{ url_for('post', post_id=post.id) }}">{{ post }}</a>
+ <a href="{{ url_for('.post', post_id=post.id) }}">{{ post }}</a>
</td>
<td class="created-at">
<time datetime="{{ post.created_at.isoformat() }}">
@@ -71,14 +71,14 @@
{{- post.created_at.date() -}}
</time></dd>
<dt class="title">Title:</dt>
- <dd class="title"><h1><a href="{{ url_for('post', post_id=post.id) }}">
+ <dd class="title"><h1><a href="{{ url_for('.post', post_id=post.id) }}">
{{- post -}}
</a></h1></dd>
</dl>
</header>
<section class="content">{{ post.body_html|safe }}</section>
<footer>
- <a href="{{ url_for('post', post_id=post.id) -}}
+ <a href="{{ url_for('.post', post_id=post.id) -}}
{% if post.replies.first() -%}
#comment-{{ post.replies.first().id }}
{%- else -%}
@@ -90,5 +90,5 @@
{% endfor %}
</div>
{% endif %}
- {{ render_pager(pager, limit, 'posts') }}
+ {{ render_pager(pager, limit, '.posts') }}
{% endblock %}
View
2 langdev/web/templates/forum/write_form.html
@@ -1,5 +1,5 @@
{% extends '/forum/base.html' %}
{% from 'form.html' import render_form %}
{% block body %}
- {{ render_form(form, 'write') }}
+ {{ render_form(form, '.write') }}
{% endblock %}
View
6 langdev/web/templates/thirdparty/app.html
@@ -41,7 +41,7 @@
<h2><abbr title="Single Sign-on">SSO</abbr></h2>
<h3><code>POST
- {{ url_for('sso', app_key='yourappkey', user_login='userlogin')
+ {{ url_for('.sso', app_key='yourappkey', user_login='userlogin')
| replace('yourappkey', '<var>YourAppKey</var>')
| replace('userlogin', '<var>UserLoginOrEmail</var>')
| safe}}</code></h3>
@@ -65,7 +65,7 @@
<p>HMAC+SHA1 hashed (when secret key is <code>{{ app.secret_key }}</code>)
hexadecimal digest of <code>5d41402abc4b2a76b9719d911017c592</code> is:
<code>{{ app.hmac('5d41402abc4b2a76b9719d911017c592') }}</code>.</p>
- <pre>POST {{ url_for('sso', app_key=app.key,
+ <pre>POST {{ url_for('.sso', app_key=app.key,
user_login=current_user.login) }} HTTP/1.1
Host: {{ request.host }}
Accept: application/json
@@ -115,7 +115,7 @@
{{ require('langdev.web.serializers').json(current_user) }}</pre>
<h2>Delete</h2>
- {% call render_raw_form('delete_app', app_key=app.key) %}
+ {% call render_raw_form('.delete_app', app_key=app.key) %}
<input type="submit" value="Delete" />
{% endcall %}
<script>
View
4 langdev/web/templates/thirdparty/register_form.html
@@ -1,12 +1,12 @@
{% extends 'thirdparty/base.html' %}
{% from 'form.html' import render_form %}
{% block body %}
- {{ render_form(form, 'register') }}
+ {{ render_form(form, '.register') }}
{% if current_user.applications %}
<h2>Your Applications</h2>
<ul class="applications">
{% for app in current_user.applications %}
- <li><a href="{{ url_for('app', app_key=app.key) }}">{{ app }}</a></li>
+ <li><a href="{{ url_for('.app', app_key=app.key) }}">{{ app }}</a></li>
{% endfor %}
</ul>
{% endif %}
View
2 langdev/web/templates/user/posts.html
@@ -21,5 +21,5 @@
{% endfor %}
</tbody>
</table>
- {{ render_pager(pager, limit, 'posts') }}
+ {{ render_pager(pager, limit, '.posts') }}
{% endblock %}
View
8 langdev/web/templates/user/profile.html
@@ -1,12 +1,12 @@
{% extends '/user/base.html' %}
{% from 'form.html' import render_form, render_raw_form %}
{% block head %}
- <link rel="canonical" href="{{ url_for('profile', user_login=user.login,
+ <link rel="canonical" href="{{ url_for('.profile', user_login=user.login,
_external=True) }}" />
{% endblock %}
{% block profile %}
{% if form %}
- {{ render_form(form, 'edit', user_login=user.login) }}
+ {{ render_form(form, '.edit', user_login=user.login) }}
{% else %}
<dl>
{% if user.url %}
@@ -19,8 +19,8 @@
</dl>
{% endif %}
{% if user == current_user %}
- {% call render_raw_form('leave', user_login=user.login,
- return_url=url_for('home.main')) %}
+ {% call render_raw_form('.leave', user_login=user.login,
+ return_url=url_for('home.main')) %}
<input type="submit" value="Leave" />
{% endcall %}
<script>
View
28 langdev/web/thirdparty.py
@@ -2,9 +2,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
-import re
-from flask import *
-from flaskext.wtf import *
+from flask import Blueprint, request, g, redirect, url_for, abort
+from flaskext import wtf
import werkzeug.exceptions
import sqlalchemy.orm.exc
from langdev.user import User
@@ -13,19 +12,20 @@
import langdev.web.user
-#: Third-party application pages module.
+#: Third-party application pages blueprint.
#:
-#: .. seealso:: Flask --- :ref:`working-with-modules`
-thirdparty = Module(__name__)
+#: .. seealso:: Flask --- :ref:`modular-applications-with-blueprints`
+thirdparty = Blueprint('thirdparty', __name__)
-class ApplicationForm(Form):
+class ApplicationForm(wtf.Form):
- title = TextField('Application title',
- validators=[Required(), Length(2, 100)])
- url = html5.URLField('Application website', validators=[Required()])
- description = TextAreaField('Description', validators=[Required()])
- submit = SubmitField('Create application')
+ title = wtf.TextField('Application title',
+ validators=[wtf.Required(), wtf.Length(2, 100)])
+ url = wtf.html5.URLField('Application website',
+ validators=[wtf.Required()])
+ description = wtf.TextAreaField('Description', validators=[wtf.Required()])
+ submit = wtf.SubmitField('Create application')
@thirdparty.route('/')
@@ -45,7 +45,7 @@ def register():
form.populate_obj(app)
with g.session.begin():
g.session.add(app)
- return redirect(url_for('app', app_key=app.key), 302)
+ return redirect(url_for('.app', app_key=app.key), 302)
return register_form(form=form)
@@ -80,7 +80,7 @@ def delete_app(app_key):
langdev.web.user.ensure_signin(app.owner)
with g.session.begin():
g.session.delete(app)
- return redirect(url_for('register'), 302)
+ return redirect(url_for('.register'), 302)
@thirdparty.route('/<app_key>/sso/<user_login>', methods=['GET', 'POST'])
View
115 langdev/web/user.py
@@ -13,20 +13,20 @@
import hmac
import hashlib
import textwrap
-from flask import *
-from flaskext.wtf import *
-from flaskext.mail import Message
+from flask import (Blueprint, request, session, g, abort, redirect,
+ url_for, current_app)
+from flask.ext import wtf
+from flask.ext.mail import Message
from sqlalchemy import orm
-import werkzeug.datastructures
from langdev.user import User
from langdev.web import before_request, errorhandler, render
from langdev.objsimplify import Result
-#: User web pages module.
+#: User web pages blueprint.
#:
-#: .. seealso:: Flask --- :ref:`working-with-modules`
-user = Module(__name__)
+#: .. seealso:: Flask --- :ref:`modular-applications-with-blueprints`
+user = Blueprint('user', __name__)
@before_request
@@ -110,18 +110,18 @@ def signout():
return redirect(return_url)
-class SignInForm(Form):
+class SignInForm(wtf.Form):
- login = TextField('Login name',
- validators=[Required(), Length(2, 45),
- Regexp(User.LOGIN_PATTERN)])
- password = PasswordField('Password', validators=[Required()])
- return_url = HiddenField(validators=[Optional()])
- submit = SubmitField('Login')
+ login = wtf.TextField('Login name',
+ validators=[wtf.Required(), wtf.Length(2, 45),
+ wtf.Regexp(User.LOGIN_PATTERN)])
+ password = wtf.PasswordField('Password', validators=[wtf.Required()])
+ return_url = wtf.HiddenField(validators=[wtf.Optional()])
+ submit = wtf.SubmitField('Login')
def validate_login(form, field):
if g.session.query(User).filter_by(login=field.data).count() < 1:
- raise ValidationError('There is no {0}.'.format(field.data))
+ raise wtf.ValidationError('There is no {0}.'.format(field.data))
def validate_password(form, field):
try:
@@ -130,7 +130,7 @@ def validate_password(form, field):
pass
else:
if user.password != field.data:
- raise ValidationError('Incorrect password.')
+ raise wtf.ValidationError('Incorrect password.')
@user.route('/f/signin')
@@ -150,55 +150,60 @@ def signin():
user = g.session.query(User).filter_by(login=form.login.data)[0]
set_current_user(user)
return_url = form.return_url.data or \
- url_for('profile', user_login=user.login)
+ url_for('.profile', user_login=user.login)
return redirect(return_url)
return signin_form(form=form)
-class SignUpForm(Form):
+class SignUpForm(wtf.Form):
- login = TextField('Login name',
- validators=[Required(), Length(2, 45),
- Regexp(User.LOGIN_PATTERN)])
- password = PasswordField(
+ login = wtf.TextField('Login name',
+ validators=[wtf.Required(), wtf.Length(2, 45),
+ wtf.Regexp(User.LOGIN_PATTERN)])
+ password = wtf.PasswordField(
'Password',
- validators=[Required(), EqualTo('confirm',
- message='Passwords must match.')]
+ validators=[wtf.Required(),
+ wtf.EqualTo('confirm', message='Passwords must match.')]
)
- confirm = PasswordField('Repeat Password', validators=[Required()])
- name = TextField('Screen name', validators=[Required(), Length(1, 45)])
- email = html5.EmailField('Email', validators=[Optional(), Email()])
- url = html5.URLField('Website', validators=[Optional(), URL()])
+ confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()])
+ name = wtf.TextField('Screen name',
+ validators=[wtf.Required(), wtf.Length(1, 45)])
+ email = wtf.html5.EmailField('Email',
+ validators=[wtf.Optional(), wtf.Email()])
+ url = wtf.html5.URLField('Website', validators=[wtf.Optional(), wtf.URL()])
@classmethod
def get_instance(cls, *args, **kwargs):
if ('RECAPTCHA_PUBLIC_KEY' in current_app.config and
'RECAPTCHA_PRIVATE_KEY' in current_app.config):
class SignUpForm_recaptcha(cls):
- recaptcha = RecaptchaField()
- submit = SubmitField('Sign up')
+ recaptcha = wtf.RecaptchaField()
+ submit = wtf.SubmitField('Sign up')
return SignUpForm_recaptcha(*args, **kwargs)
class SignUpForm_plain(cls):
- submit = SubmitField('Sign up')
+ submit = wtf.SubmitField('Sign up')
return SignUpForm_plain(*args, **kwargs)
def validate_login(form, field):
if g.session.query(User).filter_by(login=field.data).count():
- raise ValidationError('{0} is already taken.'.format(field.data))
+ raise wtf.ValidationError(
+ '{0} is already taken.'.format(field.data))
-class ProfileForm(Form):
+class ProfileForm(wtf.Form):
- password = PasswordField(
+ password = wtf.PasswordField(
'Password',
- validators=[Required(), EqualTo('confirm',
- message='Passwords must match.')]
+ validators=[wtf.Required(),
+ wtf.EqualTo('confirm', message='Passwords must match.')]
)
- confirm = PasswordField('Repeat Password', validators=[Required()])
- name = TextField('Screen name', validators=[Required(), Length(1, 45)])
- email = html5.EmailField('Email', validators=[Optional(), Email()])
- url = html5.URLField('Website', validators=[Optional(), URL()])
- submit = SubmitField('Save')
+ confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()])
+ name = wtf.TextField('Screen name',
+ validators=[wtf.Required(), wtf.Length(1, 45)])
+ email = wtf.html5.EmailField('Email',
+ validators=[wtf.Optional(), wtf.Email()])
+ url = wtf.html5.URLField('Website', validators=[wtf.Optional(), wtf.URL()])
+ submit = wtf.SubmitField('Save')
@user.route('/f/signup')
@@ -225,7 +230,7 @@ def signup():
with g.session.begin():
g.session.add(user)
set_current_user(user)
- return redirect(url_for('profile', user_login=user.login), 302)
+ return redirect(url_for('.profile', user_login=user.login), 302)
return signup_form(form=form)
@@ -283,16 +288,16 @@ def posts(user_login):
return render('user/posts', posts, user=user, posts=posts)
-class PasswordFindingForm(Form):
+class PasswordFindingForm(wtf.Form):
- login = TextField('Login name',
- validators=[Required(), Length(2, 45),
- Regexp(User.LOGIN_PATTERN)])
- submit = SubmitField('Find')
+ login = wtf.TextField('Login name',
+ validators=[wtf.Required(), wtf.Length(2, 45),
+ wtf.Regexp(User.LOGIN_PATTERN)])
+ submit = wtf.SubmitField('Find')
def validate_login(form, field):
if g.session.query(User).filter_by(login=field.data).count() < 1:
- raise ValidationError('There is no {0}.'.format(field.data))
+ raise wtf.ValidationError('There is no {0}.'.format(field.data))
@user.route('/f/orgot')
@@ -364,7 +369,7 @@ def request_find_password(user_login):
user = get_user(user_login, orm.undefer_group('profile'))
if user.email:
token, expired_at = generate_token(user)
- url = url_for('change_password_form',
+ url = url_for('.change_password_form',
user_login=user.login, token=token, _external=True)
expired_at = datetime.datetime.utcfromtimestamp(expired_at)
msg = Message('[LangDev.org] Change your password: ' + user.login,
@@ -387,15 +392,15 @@ def request_find_password(user_login):
return response
-class ChangePasswordForm(Form):
+class ChangePasswordForm(wtf.Form):
- password = PasswordField(
+ password = wtf.PasswordField(
'Password',
- validators=[Required(), EqualTo('confirm',
- message='Passwords must match.')]
+ validators=[wtf.Required(),
+ wtf.EqualTo('confirm', message='Passwords must match.')]
)
- confirm = PasswordField('Repeat Password', validators=[Required()])
- submit = SubmitField('Save')
+ confirm = wtf.PasswordField('Repeat Password', validators=[wtf.Required()])
+ submit = wtf.SubmitField('Save')
@user.route('/<user_login>/password-findings/<token>')
View
2 setup.py
@@ -34,7 +34,7 @@ def find_packages(where='.'):
include_package_data=True,
zip_safe=False,
install_requires=['SQLAlchemy >=0.7', 'markdown2',
- 'Flask', 'Werkzeug', 'Jinja2', 'Flask-WTF',
+ 'Flask >= 0.7', 'Werkzeug', 'Jinja2', 'Flask-WTF',
'Flask-Mail', 'Flask-Script'],
extras_require={'docs': ['Sphinx >=1.0',
'sphinxcontrib-httpdomain >=1.1.4']},
Something went wrong with that request. Please try again.