Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
applied @quantifiedcode suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Dec 6, 2015
1 parent e5cd13a commit cf7bdaf
Show file tree
Hide file tree
Showing 29 changed files with 180 additions and 113 deletions.
32 changes: 32 additions & 0 deletions etc/fixtures/demo_data.json
Expand Up @@ -31,6 +31,38 @@
"order" : 0
}
]
},
{
"name" : "author",
"email" : "author@example.com",
"gravatar_email": "rochacbruno+quokka@gmail.com",
"password" : "author",
"roles" : [ "author" ],
"bio": "Quokka Example Author",
"tagline": "It is nice to write in Quokka CMS!",
"links": [
{
"title" : "facebook",
"link" : "http://facebook.com/quokkaproject",
"icon" : "facebook",
"css_class" : "facebook",
"order" : 0
},
{
"title" : "github",
"link" : "http://github.com/quokkaproject",
"icon" : "github",
"css_class" : "github",
"order" : 0
},
{
"title" : "twitter",
"link" : "http://twitter.com/quokkaproject",
"icon" : "twitter",
"css_class" : "twitter",
"order" : 0
}
]
}
],
"configs": [
Expand Down
32 changes: 32 additions & 0 deletions etc/fixtures/initial_data.json
Expand Up @@ -31,6 +31,38 @@
"order" : 0
}
]
},
{
"name" : "author",
"email" : "author@example.com",
"gravatar_email": "rochacbruno+quokka@gmail.com",
"password" : "author",
"roles" : [ "author" ],
"bio": "Quokka Example Author",
"tagline": "It is nice to write in Quokka CMS!",
"links": [
{
"title" : "facebook",
"link" : "http://facebook.com/quokkaproject",
"icon" : "facebook",
"css_class" : "facebook",
"order" : 0
},
{
"title" : "github",
"link" : "http://github.com/quokkaproject",
"icon" : "github",
"css_class" : "github",
"order" : 0
},
{
"title" : "twitter",
"link" : "http://twitter.com/quokkaproject",
"icon" : "twitter",
"css_class" : "twitter",
"order" : 0
}
]
}
],
"configs": [
Expand Down
18 changes: 9 additions & 9 deletions quokka/__init__.py
Expand Up @@ -11,13 +11,12 @@
__copyright__ = "Copyright 2014, Quokka Project"


try:
from .core.admin import create_admin
from .core.app import QuokkaApp
# from .core.middleware import HTTPMethodOverrideMiddleware
admin = create_admin()
except:
pass
from quokka.core.admin import create_admin
from quokka.core.app import QuokkaApp
from quokka.core.middleware import HTTPMethodOverrideMiddleware
from quokka.ext import configure_extensions

admin = create_admin()


def create_app_base(config=None, test=False, admin_instance=None, **settings):
Expand All @@ -32,9 +31,10 @@ def create_app(config=None, test=False, admin_instance=None, **settings):
app = create_app_base(
config=config, test=test, admin_instance=admin_instance, **settings
)
from .ext import configure_extensions

configure_extensions(app, admin_instance or admin)
# app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)
if app.config.get("HTTP_PROXY_METHOD_OVERRIDE"):
app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)
return app


Expand Down
19 changes: 9 additions & 10 deletions quokka/core/admin/__init__.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*

import logging
from werkzeug.utils import import_string

from flask import request, session
Expand All @@ -26,8 +24,6 @@
'''
_n # noqa

logger = logging.getLogger()


class QuokkaAdmin(Admin):
registered = []
Expand Down Expand Up @@ -85,8 +81,8 @@ def get_locale():
return session.get('lang', 'en')

admin.locale_selector(get_locale)
except:
pass # Exception: Can not add locale_selector second time.
except Exception as e:
app.logger.info('Cannot add locale_selector. %s' % e)

for entry in app.config.get('FILE_ADMIN', []):
try:
Expand All @@ -102,8 +98,7 @@ def get_locale():
)
)
except Exception as e:
logger.info(e)
# need to check blueprint endpoisnt colision
app.logger.info(e)

# register all themes in file manager
for k, theme in app.theme_manager.themes.items():
Expand Down Expand Up @@ -142,8 +137,12 @@ def get_locale():
'DEFAULT_EDITABLE_EXTENSIONS')
)
)
except:
pass
except Exception as e:
app.logger.warning(
'Error registering %s folder to file admin %s' % (
theme.identifier, e
)
)

# adding views
admin.add_view(InspectorView(category=_l("Settings"),
Expand Down
21 changes: 12 additions & 9 deletions quokka/core/admin/fields.py
Expand Up @@ -21,15 +21,18 @@ class ThumbWidget(ImageUploadInput):
' <img %(image)s>'
'</div>')

def get_url(self, field):
if field.thumbnail_size:
filename = field.thumbnail_fn(field.data)
else:
filename = field.data

if field.url_relative_path:
filename = urljoin(field.url_relative_path, filename)

@staticmethod
def get_url(field):
'''
This meethod is not used, but is here for compatibility
'''
# if field.thumbnail_size:
# filename = field.thumbnail_fn(field.data)
# else:
# filename = field.data
#
# if field.url_relative_path:
# filename = urljoin(field.url_relative_path, filename)
return field.data


Expand Down
6 changes: 3 additions & 3 deletions quokka/core/admin/models.py
Expand Up @@ -39,7 +39,7 @@ def render(self, template, **kwargs):
kwargs['h'] = h
# Contribute extra arguments
kwargs.update(self._template_args)
theme = current_app.config.get('ADMIN_THEME', None)
theme = current_app.config.get('ADMIN_THEME')
return render_template(template, theme=theme, **kwargs)


Expand All @@ -49,7 +49,7 @@ def is_accessible(self):
roles_accepted = getattr(self, 'roles_accepted', None)
return is_accessible(roles_accepted=roles_accepted, user=current_user)

def _handle_view(self, name, *args, **kwargs):
def _handle_view(self, *args, **kwargs):
if not current_user.is_authenticated():
return redirect(url_for_security('login', next="/admin"))
if not self.is_accessible():
Expand Down Expand Up @@ -107,7 +107,7 @@ def format_status(self, request, obj, fieldname, *args, **kwargs):
def get_url(self, request, obj, fieldname, *args, **kwargs):
column_formatters_args = getattr(self, 'column_formatters_args', {})
_args = column_formatters_args.get('get_url', {}).get(fieldname, {})
attribute = _args.get('attribute', None)
attribute = _args.get('attribute')
method = _args.get('method', 'get_absolute_url')
text = getattr(obj, fieldname, '')
if attribute:
Expand Down
12 changes: 9 additions & 3 deletions quokka/core/config.py
@@ -1,8 +1,12 @@
import os
import logging
import quokka.core.models as m
from flask.config import Config
from quokka.utils import parse_conf_data
from cached_property import cached_property_ttl, cached_property

logger = logging.getLogger()


class QuokkaConfig(Config):
"""A Config object for Flask that tries to ger vars from
Expand All @@ -26,12 +30,14 @@ def all_setings_from_db(self):
and Make it possible to use REDIS as a cache
"""
try:
from quokka.core.models import Config
return {
item.name: item.value
for item in Config.objects.get(group='settings').values
for item in m.config.Config.objects.get(
group='settings'
).values
}
except:
except Exception as e:
logger.warning('Error reading all settings from db: %s' % e)
return {}

def get_from_db(self, key, default=None):
Expand Down
3 changes: 2 additions & 1 deletion quokka/core/fields.py
Expand Up @@ -9,7 +9,8 @@ class MultipleObjectsReturned(Exception):


def match_all(i, kwargs):
return all([getattr(i, k) == v for k, v in kwargs.items()])
# use generator expression?
return all(getattr(i, k) == v for k, v in kwargs.items())


def getinstance(_instance):
Expand Down
2 changes: 1 addition & 1 deletion quokka/core/middleware.py
Expand Up @@ -40,7 +40,7 @@ def _get_from_querystring(self, environ):
return None

def _get_method_override(self, environ):
return environ.get(self.header_name, None) or \
return environ.get(self.header_name) or \
self._get_from_querystring(environ) or ''

def __call__(self, environ, start_response):
Expand Down
2 changes: 1 addition & 1 deletion quokka/core/models/channel.py
Expand Up @@ -162,7 +162,7 @@ def get_canonical_url(self, *args, **kwargs):

def get_http_url(self):
site_url = Config.get('site', 'site_domain', request.url_root)
return u"{}{}".format(site_url, self.get_absolute_url())
return u"{0}{1}".format(site_url, self.get_absolute_url())

def clean(self):
homepage = Channel.objects(is_homepage=True)
Expand Down
2 changes: 1 addition & 1 deletion quokka/core/models/content.py
Expand Up @@ -106,7 +106,7 @@ def get_http_url(self):
site_url = get_site_url()
absolute_url = self.get_absolute_url()
absolute_url = absolute_url[1:]
return u"{}{}".format(site_url, absolute_url)
return u"{0}{1}".format(site_url, absolute_url)

def get_absolute_url(self, endpoint='quokka.core.detail'):
if self.channel.is_homepage:
Expand Down
2 changes: 1 addition & 1 deletion quokka/core/models/signature.py
Expand Up @@ -37,7 +37,7 @@ class Owned(object):
last_updated_by = db.ReferenceField(User)
authors = db.ListField(db.ReferenceField(User))

def get_authors(self, sortedf=None):
def get_authors(self):
return set(self.authors + [self.created_by])

@property
Expand Down
16 changes: 11 additions & 5 deletions quokka/core/views.py
Expand Up @@ -219,15 +219,17 @@ def get_template_names(self):

return names

def get_filters(self):
@staticmethod
def get_filters():
now = datetime.now()
filters = {
'published': True,
'available_at__lte': now
}
return filters

def check_if_is_accessible(self, content):
@staticmethod
def check_if_is_accessible(content):
if not content.channel.is_available:
return abort(404)

Expand Down Expand Up @@ -283,10 +285,13 @@ def get(self, long_slug, render_content=False):


class ContentDetailPreview(ContentDetail):
def get_filters(self):

@staticmethod
def get_filters():
return {}

def check_if_is_accessible(self, content):
@staticmethod
def check_if_is_accessible(content):
if not content.channel.published:
return abort(404)

Expand Down Expand Up @@ -357,7 +362,8 @@ def cdata(data):

class BaseFeed(MethodView):

def make_external_url(self, url):
@staticmethod
def make_external_url(url):
return urljoin(request.url_root, url)

def make_atom(self, feed_name, contents):
Expand Down
16 changes: 4 additions & 12 deletions quokka/ext/__init__.py
Expand Up @@ -17,33 +17,25 @@ def configure_extensions(app, admin):
Mail(app)
error_handlers.configure(app)
db.init_app(app)

themes.configure(app, db) # Themes should be configured after db

themes.configure(app)
context_processors.configure(app)
template_filters.configure(app)

security.configure(app, db)

fixtures.configure(app, db)
blueprints.load_from_packages(app)
# blueprints.load_from_packages(app)
blueprints.load_from_folder(app)

# enable .pdf support for posts
weasyprint.configure(app)

configure_admin(app, admin)

if app.config.get('DEBUG_TOOLBAR_ENABLED'):
try:
from flask_debugtoolbar import DebugToolbarExtension
DebugToolbarExtension(app)
except:
pass
app.logger.info('flask_debugtoolbar is not installed')

before_request.configure(app)
views.configure(app)

oauthlib.configure(app)

if app.config.get('SENTRY_ENABLED', False):
Expand All @@ -53,7 +45,7 @@ def configure_extensions(app, admin):
return app


def configure_extensions_min(app, admin):
def configure_extensions_min(app, *args, **kwargs):
db.init_app(app)
security.init_app(app, db)
return app
4 changes: 2 additions & 2 deletions quokka/ext/blueprints.py
Expand Up @@ -4,8 +4,8 @@
from quokka.ext.commands_collector import CommandsCollector


def load_from_packages(app):
pass
# def load_from_packages(app):
# pass


def load_from_folder(app):
Expand Down

0 comments on commit cf7bdaf

Please sign in to comment.