Browse Source

Merge branch 'master' into new-theme

sh4nks 9 years ago
parent
commit
3d64b1a6b4

+ 1 - 0
.travis.yml

@@ -1,4 +1,5 @@
 language: python
+sudo: false
 python:
   - "2.7"
   - "3.3"

+ 17 - 13
Makefile

@@ -1,22 +1,26 @@
-.PHONY: clean
+.PHONY: clean install help test run dependencies
 
 help:
-	    @echo "  clean      remove unwanted stuff"
-	    @echo "  install    install testend"
-	    @echo "  tests       run the testsuite"
-	    @echo "  run        run the development server"
+	@echo "  clean      remove unwanted stuff"
+	@echo "  install    install flaskbb and setup"
+	@echo "  tests      run the testsuite"
+	@echo "  run        run the development server"
+
+dependencies:requirements.txt
+	pip install -r requirements.txt
 
 clean:
-	    find . -name '*.pyc' -exec rm -f {} +
-	    find . -name '*.pyo' -exec rm -f {} +
-	    find . -name '*~' -exec rm -f {} +
-	    find . -name '__pycache__' -exec rm -rf {} +
+	find . -name '*.pyc' -exec rm -f {} +
+	find . -name '*.pyo' -exec rm -f {} +
+	find . -name '*~' -exec rm -f {} +
+	find . -name '__pycache__' -exec rm -rf {} +
 
 test:
-	    py.test --cov=flaskbb --cov-report=term-missing tests
+	py.test --cov=flaskbb --cov-report=term-missing tests
 
 run:
-	    python manage.py runserver
+	python manage.py runserver -dr
 
-install:
-	    python manage.py install
+install:dependencies
+	clear
+	python manage.py install

+ 3 - 6
README.md

@@ -34,15 +34,12 @@ For a complete installation guide please visit the installation documentation
 [here](https://flaskbb.readthedocs.org/en/latest/installation.html).
 
 * Create a virtualenv
-* Install the dependencies
-    * `pip install -r requirements.txt`
 * Configuration (_adjust them accordingly to your needs_)
     * For development copy `flaskbb/configs/development.py.example` to `flaskbb/configs/development.py`
-* Create the database & populate it
-    * `python manage.py initdb`
-    * `python manage.py populate`
+* Install dependencies and FlaskBB
+    * `make install`
 * Run the development server
-    * `python manage.py runserver`
+    * `make runserver`
 * Visit [localhost:8080](http://localhost:8080)
 
 

+ 13 - 18
docs/installation.rst

@@ -46,7 +46,12 @@ Required Dependencies
 Now you can install the required dependencies.
 ::
 
-     $ pip install -r requirements.txt
+    $ pip install -r requirements.txt
+
+Alternatively, you can use the `make` command to install the dependencies.
+::
+
+    $ make dependencies
 
 
 Optional Dependencies
@@ -150,29 +155,19 @@ Both methods are included in the example configs.
 Installation
 ------------
 
-
-Development
-~~~~~~~~~~~
-
-For development you can create the database with the command below. This will
-additional to the database also create a few users with some example content.
+For a guided install, run
 ::
 
-    python manage.py createall
-
-To test if everything has worked, run the development server with
-``python manage.py runserver``.
-
-Production
-~~~~~~~~~~
+    $ make install
 
-Now, you can start the installation process with
-::
+or:
 
-    python manage.py initflaskbb
+    python manage.py install
 
 During the installation process you are asked about your username,
-your email address and the password for your administrator user.
+your email address and the password for your administrator user. Using the 
+`make install` command is recommended as it checks that the dependencies are also
+installed.
 
 
 Upgrading

+ 7 - 4
flaskbb/auth/forms.py

@@ -12,11 +12,10 @@ from datetime import datetime
 
 from flask_wtf import Form, RecaptchaField
 from wtforms import (StringField, PasswordField, BooleanField, HiddenField,
-                     SubmitField)
+                     SubmitField, SelectField)
 from wtforms.validators import (DataRequired, InputRequired, Email, EqualTo,
                                 regexp, ValidationError)
 from flask_babelex import lazy_gettext as _
-
 from flaskbb.user.models import User
 
 USERNAME_RE = r'^[\w.+-]+$'
@@ -52,6 +51,9 @@ class RegisterForm(Form):
 
     confirm_password = PasswordField(_('Confirm Password'))
 
+
+    language = SelectField(_('Language'))
+
     accept_tos = BooleanField(_("I accept the Terms of Service"), default=True)
 
     submit = SubmitField(_("Register"))
@@ -71,7 +73,8 @@ class RegisterForm(Form):
                     email=self.email.data,
                     password=self.password.data,
                     date_joined=datetime.utcnow(),
-                    primary_group_id=4)
+                    primary_group_id=4,
+                    language=self.language.data)
         return user.save()
 
 
@@ -80,7 +83,7 @@ class RegisterRecaptchaForm(RegisterForm):
 
 
 class ReauthForm(Form):
-    password = PasswordField(_('Password'), valdidators=[
+    password = PasswordField(_('Password'), validators=[
         DataRequired(message=_("A Password is required."))])
 
     submit = SubmitField(_("Refresh Login"))

+ 6 - 0
flaskbb/auth/views.py

@@ -19,6 +19,8 @@ from flaskbb.email import send_reset_token
 from flaskbb.auth.forms import (LoginForm, ReauthForm, ForgotPasswordForm,
                                 ResetPasswordForm)
 from flaskbb.user.models import User
+from flaskbb.fixtures.settings import available_languages
+from flaskbb.utils.settings import flaskbb_config
 
 auth = Blueprint("auth", __name__)
 
@@ -89,6 +91,10 @@ def register():
         from flaskbb.auth.forms import RegisterForm
         form = RegisterForm(request.form)
 
+    form.language.choices = available_languages()
+    form.language.default = flaskbb_config['DEFAULT_LANGUAGE']
+    form.process()  # needed because a default is overriden
+
     if form.validate_on_submit():
         user = form.save()
         login_user(user)

+ 4 - 1
flaskbb/configs/default.py

@@ -10,6 +10,9 @@
     :license: BSD, see LICENSE for more details.
 """
 import os
+import sys
+
+_VERSION_STR = '{0.major}{0.minor}'.format(sys.version_info)
 
 
 class DefaultConfig(object):
@@ -50,7 +53,7 @@ class DefaultConfig(object):
     WTF_CSRF_SECRET_KEY = "reallyhardtoguess"
 
     # Searching
-    WHOOSH_BASE = os.path.join(_basedir, "whoosh_index")
+    WHOOSH_BASE = os.path.join(_basedir, "whoosh_index", _VERSION_STR)
 
     # Auth
     LOGIN_VIEW = "auth.login"

+ 19 - 5
flaskbb/management/views.py

@@ -141,13 +141,27 @@ def edit_user(user_id):
         flash(_("You are not allowed to edit this user."), "danger")
         return redirect(url_for("management.users"))
 
-    secondary_group_query = Group.query.filter(
-        db.not_(Group.id == user.primary_group_id),
-        db.not_(Group.banned),
-        db.not_(Group.guest == True))
+    member_group = db.and_(*[db.not_(getattr(Group, p)) for p in ['admin',
+                                              'mod',
+                                              'super_mod',
+                                              'banned',
+                                              'guest'
+                                              ]])
+
+    filt = db.or_(Group.id.in_(g.id for g in user.groups),
+                   member_group)
+
+    if any(user.permissions[p] for p in ['super_mod', 'admin']):
+        filt = db.or_(filt, Group.mod)
+
+    if user.permissions['admin']:
+        filt = db.or_(filt, Group.admin, Group.super_mod)
+
+    group_query = Group.query.filter(filt)
 
     form = EditUserForm(user)
-    form.secondary_groups.query = secondary_group_query
+    form.primary_group.query = group_query
+    form.secondary_groups.query = group_query
     if form.validate_on_submit():
         form.populate_obj(user)
         user.primary_group_id = form.primary_group.data.id

+ 1 - 0
flaskbb/templates/auth/register.html

@@ -21,6 +21,7 @@
                 {{ horizontal_field(form.recaptcha) }}
             {% endif %}
 
+            {{ horizontal_field(form.language) }}
             {{ horizontal_field(form.accept_tos)}}
             {{ horizontal_field(form.submit)}}
         </form>

+ 1 - 1
flaskbb/templates/email/reset_password.txt

@@ -1,4 +1,4 @@
-{{ set link = url_for('auth.reset_password', token=token, _external=True) }}
+{% set link = url_for('auth.reset_password', token=token, _external=True) %}
 
 {% trans user=user.username, link=link %}Dear {{ user }},
 

+ 1 - 1
flaskbb/utils/helpers.py

@@ -377,7 +377,7 @@ def format_quote(username, content):
     """
     profile_url = url_for('user.profile', username=username)
     content = "\n> ".join(content.strip().split('\n'))
-    quote = "**[{username}]({profile_url}) wrote:**\n> {content}\n".\
+    quote = u"**[{username}]({profile_url}) wrote:**\n> {content}\n".\
             format(username=username, profile_url=profile_url, content=content)
 
     return quote