Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ralphbean/statatat
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: develop
Choose a base ref
...
head repository: pep8bot/statatat
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 24 files changed
  • 1 contributor

Commits on Dec 13, 2012

  1. (Auto commit from PEP8 Bot)

    PEP8 Bot authored and ralphbean committed Dec 13, 2012

    Verified

    This commit was signed with the committer’s verified signature.
    Qix- Josh Junon
    Copy the full SHA
    313685f View commit details
60 changes: 30 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os

from setuptools import setup, find_packages
@@ -6,7 +8,10 @@
README = open(os.path.join(here, 'README.txt')).read()
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()

requires = [
requires = [ # This breaks with the latest "requests"
# https://github.com/copitux/python-github3/issues/26
# only because 2.1.2 is busted
# only because 2.1.2 is busted
'pyramid',
'SQLAlchemy',
'transaction',
@@ -16,45 +21,40 @@
'waitress',
'weberror',
'velruse',

'requests <= 0.14.0',
# This breaks with the latest "requests"
# https://github.com/copitux/python-github3/issues/26
'pygithub3',

'moksha.hub',
'moksha.wsgi',

'tw2.core <= 2.1.1', # only because 2.1.2 is busted
'tw2.forms <= 2.1.1', # only because 2.1.2 is busted
'tw2.core <= 2.1.1',
'tw2.forms <= 2.1.1',
'tw2.bootstrap.forms',
'tw2.d3',
]

setup(name='statatat',
version='0.0',
description='statatat',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pylons",
"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='statatat',
install_requires=requires,
entry_points="""\
setup(
name='statatat',
version='0.0',
description='statatat',
long_description=README + '''
''' + CHANGES,
classifiers=['Programming Language :: Python', 'Framework :: Pylons'
, '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='statatat',
install_requires=requires,
entry_points="""\
[paste.app_factory]
main = statatat:main
[console_scripts]
initialize_statatat_db = statatat.scripts.initializedb:main
""",
)

)
29 changes: 19 additions & 10 deletions statatat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pyramid.config import Configurator
from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.authentication import AuthTktAuthenticationPolicy
#from pyramid.authorization import ACLAuthorizationPolicy

# from pyramid.authorization import ACLAuthorizationPolicy

from pyramid.security import authenticated_userid
from sqlalchemy import engine_from_config

import statatat.models
import statatat.traversal

# TODO -- replace this with pyramid_beaker
crappy_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')

crappy_session_factory = \
UnencryptedCookieSessionFactoryConfig('itsaseekreet')
authn_policy = AuthTktAuthenticationPolicy(secret='verysecret')
#authz_policy = ACLAuthorizationPolicy()


# authz_policy = ACLAuthorizationPolicy()

def get_user(request):
""" A utility property hanging on 'request' """

username = authenticated_userid(request)
query = statatat.models.User.query.filter_by(username=username)
if username and query.count() > 0:
@@ -25,16 +33,17 @@ def get_user(request):
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""

engine = engine_from_config(settings, 'sqlalchemy.')
statatat.models.DBSession.configure(bind=engine)
config = Configurator(
settings=settings,
root_factory=statatat.traversal.make_root,
session_factory=crappy_session_factory,
authentication_policy=authn_policy,
#authorization_policy=authz_policy,
)
config = Configurator(settings=settings,
root_factory=statatat.traversal.make_root,
session_factory=crappy_session_factory,
authentication_policy=authn_policy)

# authorization_policy=authz_policy,
# Make it so we can do "request.user" in templates.

config.set_request_property(get_user, 'user', reify=True)

config.include('velruse.providers.github')
21 changes: 13 additions & 8 deletions statatat/events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pyramid.threadlocal import get_current_request
from pyramid.events import subscriber
from pyramid.events import BeforeRender
@@ -13,33 +15,36 @@

from statatat.widgets.graph import PopupNotification


# TODO -- move this into tw2.bootstrap like tw2.jqplugins.ui
#bootstrap_css = tw2.core.CSSLink(
# bootstrap_css = tw2.core.CSSLink(
# filename="static/bootswatch/united/bootstrap.min.css",
# modname=__name__,
#)

# )

@subscriber(BeforeRender)
def inject_globals(event):
request = get_current_request()

# TODO -- fix this.
# This is a terrible way of doing things.
request.on_profile = request.user and request.url.endswith(request.user.username)

request.on_profile = request.user \
and request.url.endswith(request.user.username)
request.on_stats = request.url.endswith('/stats')
request.on_docs = request.url.endswith('/docs')

# Expose these as global attrs for our templates
event['moksha_socket'] = get_moksha_socket(request.registry.settings)

event['moksha_socket'] = \
get_moksha_socket(request.registry.settings)
event['identity'] = authenticated_userid(request)

PopupNotification.display()

# Register bootstrap for injection with the tw2 middleware

bootstrap_css.inject()
bootstrap_responsive_css.inject()
bootstrap_js.inject()
when_ready(
"$('.dropdown-toggle').dropdown();"
)
when_ready("$('.dropdown-toggle').dropdown();")
3 changes: 3 additions & 0 deletions statatat/hub.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import moksha.hub.hub

_hub = None


def make_moksha_hub(settings):
""" Global singleton. """

global _hub
if not _hub:
_hub = moksha.hub.hub.MokshaHub(settings)
62 changes: 34 additions & 28 deletions statatat/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
from sqlalchemy import (
Column,
Integer,
DateTime,
Boolean,
UnicodeText,
ForeignKey,
)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sqlalchemy import Column, Integer, DateTime, Boolean, UnicodeText, \
ForeignKey

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import (
scoped_session,
sessionmaker,
relation,
backref,
)
from sqlalchemy.orm import scoped_session, sessionmaker, relation, \
backref

import pyramid.threadlocal
import statatat.traversal
import datetime
import uuid
from hashlib import md5
from .jsonifiable import JSONifiable
from jsonifiable import JSONifiable

from zope.sqlalchemy import ZopeTransactionExtension

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
DBSession = \
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base(cls=JSONifiable)
Base.query = DBSession.query_property()


def keygen(*args, **kw):
""" This is how we generate new source keys. """

return md5(str(uuid.uuid4())).hexdigest()


class SourceKey(Base):

__tablename__ = 'source_keys'
id = Column(Integer, primary_key=True)
notes = Column(UnicodeText, nullable=False)
value = Column(UnicodeText, unique=True, nullable=False, default=keygen)
value = Column(UnicodeText, unique=True, nullable=False,
default=keygen)
revoked = Column(Boolean, default=False)
user_id = Column(Integer, ForeignKey('users.id'))


class User(Base):

__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(UnicodeText, unique=True, nullable=False)
emails = Column(UnicodeText, nullable=False)
created_on = Column(DateTime, default=datetime.datetime.now)
widget_configurations = relation('WidgetConfiguration', backref=('user'))
repos = relation('Repo', backref=('user'))
source_keys = relation('SourceKey', backref=('user'))
widget_configurations = relation('WidgetConfiguration',
backref='user')
repos = relation('Repo', backref='user')
source_keys = relation('SourceKey', backref='user')

# TODO -- store their fullname
name = "TODO -- implement full name"

name = 'TODO -- implement full name'

@property
def total_enabled_repos(self):
@@ -69,7 +68,7 @@ def percent_enabled_repos(self):
def avatar(self):
email = self.emails.split(',')[0]
digest = md5(email).hexdigest()
return "http://www.gravatar.com/avatar/%s" % digest
return 'http://www.gravatar.com/avatar/%s' % digest

avatar_url = avatar

@@ -97,29 +96,35 @@ def created_on_fmt(self):

def __getitem__(self, key):
if key == 'source_key':

# Traversal is ridiculous.

return dict([(k.value, k) for k in self.source_keys])

for r in self.repos:
if r.name == key:
return r

raise KeyError("No such repo associated with %s" % self.username)
raise KeyError('No such repo associated with %s'
% self.username)

def repo_by_name(self, repo_name):
return self[repo_name]

def widget_link(self, source_key):
prefix = pyramid.threadlocal.get_current_request().resource_url(None)
tmpl = "{prefix}widget/{username}/embed.js" + \
"?width=400&height=55&duration=1600&n=100" + \
"&topic={source_key}"
prefix = \
pyramid.threadlocal.get_current_request().resource_url(None)
tmpl = '{prefix}widget/{username}/embed.js' \
+ '?width=400&height=55&duration=1600&n=100' \
+ '&topic={source_key}'
link = tmpl.format(prefix=prefix, username=self.username,
source_key=source_key)
return "<script type='text/javascript' src='%s'></script>" % link
return "<script type='text/javascript' src='%s'></script>" \
% link


class Repo(Base):

__tablename__ = 'repos'
id = Column(Integer, primary_key=True)
name = Column(UnicodeText, nullable=False)
@@ -128,6 +133,7 @@ class Repo(Base):


class WidgetConfiguration(Base):

__tablename__ = 'widget_configurations'
id = Column(Integer, primary_key=True)
name = Column(UnicodeText, unique=True, nullable=False)
21 changes: 11 additions & 10 deletions statatat/models/jsonifiable.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
import time

from sqlalchemy.orm import (
class_mapper,
)
from sqlalchemy.orm import class_mapper

from sqlalchemy.orm.properties import RelationshipProperty


class JSONifiable(object):

""" A mixin for sqlalchemy models providing a .__json__ method. """

def __json__(self, seen=None):
@@ -20,12 +22,10 @@ def __json__(self, seen=None):
seen = []

properties = list(class_mapper(type(self)).iterate_properties)
relationships = [
p.key for p in properties if type(p) is RelationshipProperty
]
attrs = [
p.key for p in properties if p.key not in relationships
]
relationships = [p.key for p in properties if type(p)
is RelationshipProperty]
attrs = [p.key for p in properties if p.key
not in relationships]

d = dict([(attr, getattr(self, attr)) for attr in attrs])

@@ -36,7 +36,8 @@ def __json__(self, seen=None):
d['avatar'] = self.avatar

# Serialize datetime objects
for k, v in d.items():

for (k, v) in d.items():
if isinstance(v, datetime.datetime):
d[k] = time.mktime(v.timetuple())

Loading