Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jart/occupywallst
Browse files Browse the repository at this point in the history
Conflicts:
	occupywallst/api.py
	occupywallst/views.py
  • Loading branch information
thirtyseven committed Oct 6, 2011
1 parent c30d064 commit 70c0ab4
Show file tree
Hide file tree
Showing 72 changed files with 1,097 additions and 389 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ core
*~
*.rej
*.orig
*.mo
.figleaf*
*.egg-info
*.egg
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Now install the project and the database schema::

sudo python setup.py develop
occupywallst-dev syncdb --noinput
occupywallst-dev loaddata verbiage
occupywallst-dev loaddata example_data
occupywallst-dev runserver 127.0.0.1:9001

Expand Down
42 changes: 32 additions & 10 deletions occupywallst/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from django.contrib import messages
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.conf.urls.defaults import patterns
Expand All @@ -24,6 +24,7 @@ def __init__(self, *args, **kwargs):
BaseAdminSite.__init__(self, *args, **kwargs)
self.register(db.User, UserAdmin)
self.register(db.Group, GroupAdmin)
self.register(db.Verbiage, VerbiageAdmin)
self.register(db.NewsArticle, ArticleAdmin)
self.register(db.ForumPost, ArticleAdmin)
self.register(db.UserInfo, UserInfoAdmin)
Expand All @@ -43,14 +44,28 @@ class GeoAdmin(OSMGeoAdmin):
map_height = 500


def content_field(obj):
if not obj.content:
return '!BLANK!'
elif len(obj.content) < 30:
return obj.content
else:
return obj.content[:30] + "..."
content_field.short_description = 'Content'
def content_field(maxlen):
def _content_field(obj):
if not obj.content:
return '!BLANK!'
elif len(obj.content) < maxlen:
return obj.content
else:
return obj.content[:maxlen] + "..."
_content_field.short_description = 'Content'
return _content_field


class VerbiageTranslationInline(admin.StackedInline):
model = db.VerbiageTranslation
extra = 1


class VerbiageAdmin(GeoAdmin):
inlines = (VerbiageTranslationInline,)
ordering = ('name',)
search_fields = ('name', 'content')
list_display = ('name', content_field(100))


class UserAdmin(BaseUserAdmin):
Expand All @@ -62,13 +77,20 @@ def save_model(self, request, user, form, change):
userinfo.save()


class ArticleTranslationInline(admin.StackedInline):
model = db.ArticleTranslation
extra = 1


class ArticleAdmin(GeoAdmin):
date_hierarchy = 'published'
list_display = ('title', 'author', 'published', 'comment_count',
'is_visible', 'is_deleted')
list_filter = ('is_visible', 'is_deleted')
search_fields = ('title', 'content', 'author__username')
ordering = ('-published',)
prepopulated_fields = {"slug": ("title",)}
inlines = (ArticleTranslationInline,)

def get_urls(self):
urls = super(ArticleAdmin, self).get_urls()
Expand Down Expand Up @@ -100,7 +122,7 @@ def view_convert(self, request, id_):

class CommentAdmin(GeoAdmin):
date_hierarchy = 'published'
list_display = (content_field, 'published', 'user', 'karma', 'ups',
list_display = (content_field(30), 'published', 'user', 'karma', 'ups',
'downs', 'is_removed', 'is_deleted')
list_filter = ('is_removed', 'is_deleted')
search_fields = ('content', 'user__username')
Expand Down
27 changes: 25 additions & 2 deletions occupywallst/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"""

import re
from datetime import datetime, date
from datetime import datetime, date, timedelta

from django.conf import settings
from django.contrib import auth
Expand Down Expand Up @@ -61,7 +61,22 @@ def _to_bool(val):
str(val).lower() == "true")


def attendees(bounds=None, **kwargs):
def forumlinks(after, count, **kwargs):
"""Used for continuous stream of forum post links
"""
after, count = int(after), int(count)
if after < 0 or count <= 0:
raise APIException("bad arguments")
articles = (db.Article.objects
.select_related("author")
.filter(is_visible=True, is_deleted=False)
.order_by('-published'))
for article in articles[after:after + count]:
yield render_to_string('occupywallst/forumpost_synopsis.html',
{'article': article})


def attendees(bounds, **kwargs):
"""Find all people going who live within visible map area.
"""
if bounds:
Expand Down Expand Up @@ -463,6 +478,14 @@ def message_send(user, to_username, content, **kwargs):
if last:
if (datetime.now() - last[0].published).seconds < 30:
raise APIException("hey slow down a little!")
if not user.is_staff:
hours24 = datetime.now() - timedelta(hours=24)
rec = db.Message.objects.filter(from_user=user, published__gt=hours24)
sentusers = set(m.to_user.username for m in rec)
max_ = settings.OWS_MAX_PRIVMSG_USER_DAY
if len(sentusers) > max_:
raise APIException("you can't private message more than %d users "
"in one day" % (max_))
msg = db.Message.objects.create(from_user=user,
to_user=to_user,
content=content)
Expand Down
4 changes: 2 additions & 2 deletions occupywallst/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RSSForumFeed(RSSNewsFeed):
title = "OccupyWallSt Forum"
link = settings.OWS_CANONICAL_URL
description = "Public discussion pertaining to the occupation"
delay = timedelta(seconds=60 * 5)
delay = timedelta(seconds=60 * 60 * 2)

def items(self):
return (db.Article.objects
Expand All @@ -75,7 +75,7 @@ class RSSCommentFeed(Feed):
link = settings.OWS_CANONICAL_URL
description = "All comments submitted to the website"
description_template = 'occupywallst/feed-comment.html'
delay = timedelta(seconds=60 * 5)
delay = timedelta(seconds=60 * 60 * 2)

def items(self):
return (db.Comment.objects
Expand Down
Loading

0 comments on commit 70c0ab4

Please sign in to comment.