Skip to content

Commit

Permalink
Merge branch 'master' into git-regex
Browse files Browse the repository at this point in the history
* master: (40 commits)
  merging in some i18thn fun
  test update
  Adding improved stufdf
  tiny bits of change to accomodate Steve Holden's thing
  troubleshooting tweak
  nixing the sanitize
  reread edits of contrib docs about branching
  Docs cleanup
  Added the PyCon video to the FAQ
  Doc tweak
  MOAR wrestling with RTD
  [djangopackages-zz#79] I18n main templates
  Trying out the virtualenv action on RTD
  nixing reference.rst generation for now since it borks RTD. Will talk to Eric Holscher about this and get his help
  Factored out style_repo_description to use truncatewords filter instead of custom string parsing code.
  Commented out usage of grid_detail2.html and made note. Uncomment if you are working with grids and need to test with the @sontek new grids.
  [djangopackages-zz#79] I18n package templates
  Drop the version to 0.9.0
  Tweaking docs generation to make it so it SHOULD run on read-the-docs
  Ignoring the rendered static and html directories in git to help everyone out
  ...
  • Loading branch information
ptone committed Apr 6, 2011
2 parents 1a59305 + 6124725 commit 420bf0e
Show file tree
Hide file tree
Showing 63 changed files with 948 additions and 299 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,6 @@ dev.db*
*.log
local_settings.py
lp-cache
coverage
docs/_build
docs/_static
2 changes: 2 additions & 0 deletions apps/__init__.py
@@ -0,0 +1,2 @@
"""Module containing the django applications
that together make up the packaginator site."""
4 changes: 4 additions & 0 deletions apps/apiv1/__init__.py
@@ -0,0 +1,4 @@
"""Restful api for the packaginator, based on `django-tastypie`_.
.. _django-tastypie: http://pypi.python.org/pypi/django-tastypie/
"""
3 changes: 3 additions & 0 deletions apps/feeds/__init__.py
@@ -0,0 +1,3 @@
"""This application defines RSS and Atom feeds
that are made available to the users of the
packaginator"""
10 changes: 9 additions & 1 deletion apps/feeds/feeds.py
@@ -1,24 +1,32 @@
"""Contains classes for the feeds"""

from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from package.models import Package

class RssLatestPackagesFeed(Feed):
"""RSS Feed for the packages"""
title = "Latest Django packages added"
link = "/packages/latest/"
description = "The last 15 packages added"

def items(self):
"""Returns 15 most recently created repositories"""
return Package.objects.all().order_by("-created")[:15]

def item_title(self, item):
"""Get title of the repository"""
return item.title

def item_description(self, item):
"""Get description of the repository"""
return item.repo_description

def item_pubdate(self, item):
"""Get publication date"""
return item.created

class AtomLatestPackagesFeed(RssLatestPackagesFeed):
"""Atom feed for the packages"""
feed_type = Atom1Feed
subtitle = RssLatestPackagesFeed.description
subtitle = RssLatestPackagesFeed.description
2 changes: 2 additions & 0 deletions apps/feeds/urls.py
@@ -1,3 +1,5 @@
"""url patterns for the feeds"""

from django.conf.urls.defaults import *

from feeds import *
Expand Down
2 changes: 2 additions & 0 deletions apps/grid/__init__.py
@@ -0,0 +1,2 @@
"""Grid application - displays and
manipulates the package grid"""
18 changes: 17 additions & 1 deletion apps/grid/forms.py
@@ -1,30 +1,46 @@
"""Forms for the :mod:`grid` app
"""

from django.forms import ModelForm

from grid.models import Element, Feature, Grid, GridPackage

class GridForm(ModelForm):
"""collects data for the new grid - a
django ``ModelForm`` for :class:`grid.models.Grid`
"""

def clean_slug(self):
"""returns lower-cased slug"""
return self.cleaned_data['slug'].lower()

class Meta:
model = Grid
fields = ['title', 'slug', 'description']

class ElementForm(ModelForm):
"""collects data for a new grid element -
a ``ModelForm`` for :class:`grid.models.Element`
"""

class Meta:
model = Element
fields = ['text',]

class FeatureForm(ModelForm):
"""collects data for the feature -
a ``ModelForm`` for :class:`grid.models.Feature`
"""

class Meta:
model = Feature
fields = ['title', 'description',]

class GridPackageForm(ModelForm):
"""collects data for a new package -
a ``ModelForm`` for :class:`grid.models.GridPackage`
"""

class Meta:
model = GridPackage
fields = ['package']
fields = ['package']
19 changes: 15 additions & 4 deletions apps/grid/models.py
Expand Up @@ -6,6 +6,17 @@


class Grid(BaseModel):
"""Grid object, inherits form :class:`package.models.BaseModel`
* :attr:`~grid.models.Grid.title` - grid title
* :attr:`~grid.models.Grid.slug` - grid slug for SEO
* :attr:`~grid.models.Grid.description` - description of the grid
with line breaks and urlized links
* :attr:`~grid.models.Grid.is_locked` - boolean field accessible
to moderators
* :attr:`~grid.models.Grid.packages` - many-to-many relation
with :class:~`grid.models.GridPackage` objects
"""

title = models.CharField(_('Title'), max_length=100)
slug = models.SlugField(_('Slug'), help_text="Slugs will be lowercased", unique=True)
Expand All @@ -31,9 +42,9 @@ class Meta:
ordering = ['title']

class GridPackage(BaseModel):
""" These are Packages on one side of the grid
Have to make this intermediary table to get things to work right
Otherwise would have used ManyToMany field
"""These are Packages on one side of the grid
Have to make this intermediary table to get things to work right
Otherwise would have used ManyToMany field
"""

grid = models.ForeignKey(Grid)
Expand Down Expand Up @@ -66,7 +77,7 @@ def __unicode__(self):
"""

class Element(BaseModel):
""" The individual table elements """
""" The individual grid table elements """

grid_package = models.ForeignKey(GridPackage)
feature = models.ForeignKey(Feature)
Expand Down
53 changes: 47 additions & 6 deletions apps/grid/templatetags/grid_tags.py
@@ -1,10 +1,12 @@
"""template tags and filters
for the :mod:`apps.grid` app"""
from django import template
from django.conf import settings
from django.template.defaultfilters import escape
from django.template.defaultfilters import escape, truncatewords
from grid.models import Element
import re

from django.template.loader import render_to_string

import re

register = template.Library()

Expand Down Expand Up @@ -59,9 +61,48 @@ def style_element(text):

@register.filter
def hash(h, key):
'''
Function leaves considerable overhead in the grid_detail views.
"""Function leaves considerable overhead in the grid_detail views.
each element of the list results in two calls to this hash function.
Code there, and possible here, should be refactored.
'''
"""
return h.get(key, {})

@register.filter
def style_attribute(attribute_name, package):
mappings = {
'title': style_title,
'repo_description': style_repo_description,
'commits_over_52': style_commits,
}

value = getattr(package, attribute_name, '')

if hasattr(value, '__call__'):
value = value()

if attribute_name in mappings.keys():
return mappings[attribute_name](value)

return style_default(value)

@register.filter
def style_title(value):
value = value[:20]
return render_to_string('grid/snippets/_title.html', { 'value': value })

def style_commits(value):
return render_to_string('grid/snippets/_commits.html', { 'value': value })

@register.filter
def style_description(value):
return style_default(value[:20])

@register.filter
def style_default(value):
return value

@register.filter
def style_repo_description(var):
truncated_desc = truncatewords(var, 20)
return truncated_desc

6 changes: 6 additions & 0 deletions apps/grid/urls.py
@@ -1,3 +1,4 @@
"""grid url patterns"""
from django.conf.urls.defaults import *
from django.views.generic.date_based import archive_index

Expand Down Expand Up @@ -38,6 +39,11 @@
regex = '^g/(?P<slug>[-\w]+)/$',
view = grid_detail,
name = 'grid',
# Note: Uncomment the following if you are working on grid rotation, grid permissions,
# or other grid detail related code. This is @sontek's new grid detail template.
# The grid_detail2.html file will replace grid_detail.html once it is fully stable
# in all browsers and production-ready.
# kwargs = {'template_name': 'grid/grid_detail2.html'},
),

url(
Expand Down

0 comments on commit 420bf0e

Please sign in to comment.