Skip to content

Commit

Permalink
started reimplementing wals fuinctionality in new framework
Browse files Browse the repository at this point in the history
  • Loading branch information
xrotwang committed Jan 28, 2013
1 parent fc7222b commit 065bfa8
Show file tree
Hide file tree
Showing 111 changed files with 1,936 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
@@ -0,0 +1,4 @@
0.0
---

- Initial version
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,2 @@
include *.txt *.ini *.cfg *.rst
recursive-include wals3 *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
14 changes: 14 additions & 0 deletions README.txt
@@ -0,0 +1,14 @@
wals3 README
==================

Getting Started
---------------

- cd <directory containing this file>

- $venv/bin/python setup.py develop

- $venv/bin/initialize_wals3_db development.ini

- $venv/bin/pserve development.ini

72 changes: 72 additions & 0 deletions development.ini
@@ -0,0 +1,72 @@
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:wals3

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
# pyramid_debugtoolbar
pyramid_tm

#sqlalchemy.url = sqlite:///%(here)s/wals3.sqlite
sqlalchemy.url = postgresql://robert@/wals3

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1

###
# wsgi server configuration
###

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###

[loggers]
keys = root, wals3, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_wals3]
level = DEBUG
handlers =
qualname = wals3

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
27 changes: 27 additions & 0 deletions setup.cfg
@@ -0,0 +1,27 @@
[nosetests]
match=^test
nocapture=1
cover-package=wals3
with-coverage=1
cover-erase=1

[compile_catalog]
directory = wals3/locale
domain = clld
statistics = true

[extract_messages]
add_comments = TRANSLATORS:
output_file = wals3/locale/wals3.pot
width = 80

[init_catalog]
domain = clld
input_file = wals3/locale/wals3.pot
output_dir = wals3/locale

[update_catalog]
domain = clld
input_file = wals3/locale/wals3.pot
output_dir = wals3/locale
previous = true
45 changes: 45 additions & 0 deletions setup.py
@@ -0,0 +1,45 @@
import os

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.txt')).read()
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()

requires = [
'pyramid',
'SQLAlchemy',
'transaction',
'pyramid_tm',
'pyramid_debugtoolbar',
'zope.sqlalchemy',
'waitress',
]

setup(name='wals3',
version='0.0',
description='wals3',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
keywords='web wsgi bfg pylons pyramid',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
test_suite='wals3',
install_requires=requires,
entry_points="""\
[paste.app_factory]
main = wals3:main
[console_scripts]
initialize_wals3_db = wals3.scripts.initializedb:main
""",
)

77 changes: 77 additions & 0 deletions wals3/__init__.py
@@ -0,0 +1,77 @@
from pyramid.config import Configurator
from sqlalchemy import engine_from_config, desc
from sqlalchemy.orm import joinedload
from mako.template import Template
from markupsafe import Markup

from clld import interfaces
from clld.web import datatables
from clld.web.datatables.base import Col
from clld.web.adapters import GeoJson

from wals3.models import WalsLanguage, Genus, Family
from wals3.adapters import GeoJsonFeature
from wals3.maps import FeatureMap


def _(s, *args, **kw):
return s

_('Languages')


class GenusCol(Col):
def order(self, direction):
return desc(Genus.name) if direction == 'desc' else Genus.name

def search(self, qs):
return Genus.name.contains(qs)

def format(self, item):
return item.genus.name


class Languages(datatables.Languages):
def base_query(self, query):
return query.join(Genus).join(Family).options(joinedload(WalsLanguage.genus))

def col_defs(self):
cols = datatables.Languages.col_defs(self)
return cols[:2] + [GenusCol(self, 'genus')] + cols[2:]


def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['mako.directories'] = ['wals3:templates', 'clld:web/templates']
settings['clld.app_template'] = "wals3.mako"

config = Configurator(settings=settings)

#
# must add project specific translation dir first
#
config.add_translation_dirs('wals3:locale')

#
# then include clld, thereby adding the default translations
#
config.include('clld.web.app')

config.register_datatable('languages', Languages)
config.register_map('parameter', FeatureMap)

config.override_asset(
to_override='clld:web/templates/language/rdf.pt',
override_with='wals3:templates/language/rdf.pt')

config.register_adapter(
GeoJsonFeature,
interfaces.IParameter,
interfaces.IRepresentation,
GeoJson.mimetype)

config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.scan()
return config.make_wsgi_app()
15 changes: 15 additions & 0 deletions wals3/adapters.py
@@ -0,0 +1,15 @@
from clld.web.adapters import GeoJsonParameter


class GeoJsonFeature(GeoJsonParameter):

def feature_properties(self, ctx, req, feature):
language, values = feature
val = list(values)[0]
if val.domainelement.id == req.params.get('domainelement'):
res = GeoJsonParameter.feature_properties(self, ctx, req, feature)
res['icon_type'] = val.domainelement.icon_id[:1]
res['icon_color'] = '#%s' % ''.join(2*c for c in val.domainelement.icon_id[1:])
res['value_numeric'] = val.domainelement.numeric
res['value_name'] = val.domainelement.name
return res
23 changes: 23 additions & 0 deletions wals3/locale/en/LC_MESSAGES/wotw.po
@@ -0,0 +1,23 @@
# English translations for PROJECT.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-11-11 17:31+0100\n"
"PO-Revision-Date: 2012-11-11 17:30+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: en <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.0dev\n"

#: wals3/__init__.py:13
msgid "Languages"
msgstr "WALS Languages"

23 changes: 23 additions & 0 deletions wals3/locale/wals3.pot
@@ -0,0 +1,23 @@
# Translations template for wals3.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the wals3 project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: wals3 0.0\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-11-11 17:31+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 1.0dev\n"

#: wals3/__init__.py:13
msgid "Languages"
msgstr ""

14 changes: 14 additions & 0 deletions wals3/maps.py
@@ -0,0 +1,14 @@
from clld.web.maps import ParameterMap, Map
from clld.web.util.htmllib import HTML


class FeatureMap(ParameterMap):
def get_layers(self):
res = []
for layer, de in zip(ParameterMap.get_layers(self), self.ctx.domain):
layer['marker'] = HTML.img(src=self.req.static_url('wals3:static/icons/' + de.icon_id + '.png'))
res.append(layer)
return res

def options(self):
return {'style_map': 'wals_feature'}

0 comments on commit 065bfa8

Please sign in to comment.