Skip to content
Browse files

follow pep8 documentation guidelines

  • Loading branch information...
1 parent becd060 commit 993931507e125e7f8d698cacb62be4a230960f1e Justine Tunney committed
View
52 occupywallst/api.py
@@ -76,8 +76,7 @@ def _too_many_caps(text):
def forumlinks(after, count, **kwargs):
- """Used for continuous stream of forum post links
- """
+ """Used for continuous stream of forum post links"""
after, count = int(after), int(count)
if after < 0 or count <= 0:
raise APIException(_("bad arguments"))
@@ -91,8 +90,7 @@ def forumlinks(after, count, **kwargs):
def attendees(bounds, **kwargs):
- """Find all people going who live within visible map area.
- """
+ """Find all people going who live within visible map area"""
if bounds:
bbox = _str_to_bbox(bounds)
qset = (db.UserInfo.objects
@@ -110,8 +108,7 @@ def attendees(bounds, **kwargs):
def rides(bounds=None, **kwargs):
- """Find all rides within visible map area.
- """
+ """Find all rides within visible map area"""
if bounds:
bbox = _str_to_bbox(bounds)
qset = (db.Ride.objects
@@ -142,8 +139,7 @@ def ride_request_update(request_id, status, user=None, **kwargs):
def attendee_info(username, **kwargs):
- """Get information for displaying attendee bubble
- """
+ """Get information for displaying attendee bubble"""
user = (db.User.objects
.select_related("userinfo")
.get(username=username))
@@ -158,8 +154,7 @@ def attendee_info(username, **kwargs):
def _check_post(user, post):
- """Ensure user-submitted forum content is kosher
- """
+ """Ensure user-submitted forum content is kosher"""
if user.is_staff:
return
if len(post.content) < 3:
@@ -299,8 +294,7 @@ def article_delete(user, article_slug, **kwargs):
def article_remove(user, article_slug, action, **kwargs):
- """Makes an article unlisted and invisible to search engines
- """
+ """Makes an article unlisted and invisible to search engines"""
if not (user and user.id):
raise APIException(_("you're not logged in"))
if not user.is_staff:
@@ -320,8 +314,7 @@ def article_remove(user, article_slug, action, **kwargs):
def article_get(user, article_slug=None, **kwargs):
- """Get article information
- """
+ """Get article information"""
try:
article = db.Article.objects.get(slug=article_slug, is_deleted=False)
except db.Article.DoesNotExist:
@@ -331,9 +324,9 @@ def article_get(user, article_slug=None, **kwargs):
'user': user})
return [article.as_dict({'html': html})]
+
def article_get_comments(user, article_slug=None, **kwargs):
- """Get all comments for an article
- """
+ """Get all comments for an article"""
try:
article = db.Article.objects.get(slug=article_slug, is_deleted=False)
comments = article.comment_set.all()
@@ -418,8 +411,7 @@ def comment_depth(id):
def comment_get(user, comment_id=None, **kwargs):
- """Fetch a single comment information
- """
+ """Fetch a single comment information"""
try:
comment = db.Comment.objects.get(id=comment_id, is_deleted=False)
except db.Comment.DoesNotExist:
@@ -444,8 +436,7 @@ def comment_get(user, comment_id=None, **kwargs):
def comment_edit(user, comment_id, content, **kwargs):
- """Edit a comment's content
- """
+ """Edit a comment's content"""
if not (user and user.id):
raise APIException(_("you're not logged in"))
content = content.strip()
@@ -465,8 +456,7 @@ def comment_edit(user, comment_id, content, **kwargs):
def comment_remove(user, comment_id, action, **kwargs):
- """Allows moderator to remove a comment
- """
+ """Allows moderator to remove a comment"""
if not (user and user.id):
raise APIException(_("you're not logged in"))
if not user.is_staff:
@@ -542,20 +532,17 @@ def comment_vote(user, comment, vote, **kwargs):
def comment_upvote(user, comment, **kwargs):
- """Upvotes a comment
- """
+ """Upvotes a comment"""
return comment_vote(user, comment, "up", **kwargs)
def comment_downvote(user, comment, **kwargs):
- """Downvotes a comment
- """
+ """Downvotes a comment"""
return comment_vote(user, comment, "down", **kwargs)
def message_send(user, to_username, content, **kwargs):
- """Send a private message.
- """
+ """Send a private message"""
if not (user and user.id):
raise APIException(_("you're not logged in"))
content = content.strip()
@@ -603,8 +590,7 @@ def message_delete(user, message_id, **kwargs):
def check_username(username, check_if_taken=True, **kwargs):
- """Check if a username is valid and available
- """
+ """Check if a username is valid and available"""
if len(username) < 3:
raise APIException(_("username too short"))
if len(username) > 30:
@@ -652,8 +638,7 @@ def signup(request, username, password, email, **kwargs):
def login(request, username, password, **kwargs):
- """Login user
- """
+ """Login user"""
if request.user.is_authenticated():
raise APIException(_("you're already logged in"))
user = auth.authenticate(username=username, password=password)
@@ -664,7 +649,6 @@ def login(request, username, password, **kwargs):
def logout(request, **kwargs):
- """Logout user
- """
+ """Logout user"""
auth.logout(request)
return []
View
3 occupywallst/fields.py
@@ -24,5 +24,6 @@ def clean(self, values):
check_captcha = captcha.submit(recaptcha_challenge_value,
recaptcha_response_value, settings.RECAPTCHA_PRIVATE_KEY, {})
if not check_captcha.is_valid:
- raise forms.util.ValidationError(self.error_messages['captcha_invalid'])
+ raise forms.util.ValidationError(
+ self.error_messages['captcha_invalid'])
return values[0]
View
6 occupywallst/geo.py
@@ -88,8 +88,7 @@ def geocode(address):
def address_to_latlng(address):
- """Shortcut function to just get lat/lng from geocode()
- """
+ """Shortcut function to just get lat/lng from geocode()"""
results = geocode(address)
if not results:
return None, None
@@ -99,8 +98,7 @@ def address_to_latlng(address):
def haversine(lat1, lng1, lat2, lng2):
- """Calculate kilometer distance between two places on earth
- """
+ """Calculate kilometer distance between two places on earth"""
# convert to radians
lng1 = float(lng1) * pi / 180
lng2 = float(lng2) * pi / 180
View
24 occupywallst/models.py
@@ -118,8 +118,7 @@ def save(self):
class UserInfo(models.Model):
- """Extra DB information to associate with a Django auth user
- """
+ """Extra DB information to associate with a Django auth user"""
ATTENDANCE_CHOICES = (
('yes', 'Yes'),
('no', 'No'),
@@ -313,8 +312,7 @@ def __unicode__(self):
@models.permalink
def get_absolute_url(self):
- """Returns absolute canonical path for article
- """
+ """Returns absolute canonical path for article"""
if self.is_forum:
return ('forum-post', [self.slug])
else:
@@ -322,8 +320,7 @@ def get_absolute_url(self):
@models.permalink
def get_forum_url(self):
- """Returns non-canonical url to view article on forum
- """
+ """Returns non-canonical url to view article on forum"""
return ('forum-post', [self.slug])
def delete(self):
@@ -431,8 +428,7 @@ def get_query_set(self):
class NewsArticle(Article):
- """View of Article table that doesn't show forum posts
- """
+ """View of Article table that doesn't show forum posts"""
objects = NewsArticleManager()
class Meta:
@@ -452,8 +448,7 @@ def get_query_set(self):
class ForumPost(Article):
- """View of Article table that doesn't news articles
- """
+ """View of Article table that doesn't news articles"""
objects = ForumPostManager()
class Meta:
@@ -467,8 +462,7 @@ def save(self, *args, **kwargs):
class Comment(models.Model):
- """Users can leave comments on articles reddit style
- """
+ """Users can leave comments on articles reddit style"""
article = models.ForeignKey(Article, editable=False, help_text="""
The article to which this comment belongs.""")
user = models.ForeignKey(User, null=True, blank=True, editable=False,
@@ -610,8 +604,7 @@ def prune(days_old=30):
class Message(models.Model):
- """One user sending a message to another.
- """
+ """One user sending a message to another"""
from_user = models.ForeignKey(User, editable=False,
related_name="messages_sent", help_text="""
The user who sent the message.""")
@@ -678,8 +671,7 @@ def is_spam(msg):
class Ride(models.Model):
- """Info about a person or bus driving to Event for carpooling
- """
+ """Info about a person or bus driving to Event for carpooling"""
RIDETYPE_CHOICES = (
('car', 'Car'),
('bus', 'Bus'),
View
24 occupywallst/templatetags/ows.py
@@ -79,8 +79,7 @@ def timesince_short(timestamp):
@register.filter
def synopsis(text, max_words=10, max_chars=40):
- """
- Creates a shortened version of content
+ """Creates a shortened version of content
We only care about the first line. If the text begins with a
markdown quotation, it will be excluded unless the whole thing is
@@ -100,8 +99,7 @@ def synopsis(text, max_words=10, max_chars=40):
def mortify(text, url, funk):
- """
- Extracts specified synopsis in markdown article
+ """Extracts specified synopsis in markdown article
There are two ways to specify a synopsis:
@@ -146,8 +144,7 @@ def _markup(text, transform):
@register.filter
def markup(text):
- """Runs text through markdown, no html allowed
- """
+ """Runs text through markdown, no html allowed"""
return _markup(text, markdown_safe.convert)
markup.is_safe = True
@@ -162,17 +159,14 @@ def strip_annoying_html(html):
@register.filter
def markup_unsafe(text):
- """Runs text through markdown allowing custom html
- """
+ """Runs text through markdown allowing custom html"""
return _markup(text, markdown_unsafe.convert)
markup_unsafe.is_safe = True
@register.filter
def userlink(user):
- """
- Display a username in HTML with a link to their profile
- """
+ """Display a username in HTML with a link to their profile"""
if not user or not user.id:
return ugettext('anonymous')
res = ugettext('<a title="View %(user)s\'s profile" class="user"'
@@ -184,9 +178,7 @@ def userlink(user):
@register.simple_tag
def translate_object(obj, lang):
- """
- If possible, replaces certain fields with translated text
- """
+ """If possible, replaces certain fields with translated text"""
if obj:
obj.translate(lang)
return ''
@@ -194,9 +186,7 @@ def translate_object(obj, lang):
@register.simple_tag(takes_context=True)
def show_comments(context, user, comments):
- """
- I wrote this because template includes don't recurse properly
- """
+ """I wrote this because template includes don't recurse properly"""
res = []
depth = context.get('depth', -1) + 1
can_reply = depth + 1 < settings.OWS_MAX_COMMENT_DEPTH
View
18 occupywallst/tests.py
@@ -42,9 +42,7 @@ def assert_and_get_valid_json(response):
def random_words(N):
- """
- Choose N random words for content
- """
+ """Choose N random words for content"""
words = ('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed '
'do eiusmod tempor incididunt ut labore et dolore magna aliqua. '
'Ut enim ad minim veniam, quis nostrud exercitation ullamco '
@@ -57,8 +55,7 @@ def random_words(N):
def add_content(N):
- """ add N articles and comments to the database, for testing
- etc"""
+ """Add N articles and comments to the database, for testing etc."""
settings.DEBUG = True
users = [u for u in db.User.objects.all()]
@@ -86,7 +83,7 @@ class OWS(TestCase):
fixtures = ['verbiage', 'example_data']
def create_users(self):
- """ Create users for functional testing of access control.
+ """Create users for functional testing of access control.
It seems easier to create the users with a code block than as
json fixtures, because the password is clearer before it is
@@ -126,9 +123,7 @@ def setUp(self):
# tests of models
def test_verbiage(self):
- """
- Test verbiage model
- """
+ """Test verbiage model"""
assert db.Verbiage.get('title') != None, 'should have a title'
assert db.Verbiage.get('title') != None, \
'should cache title for second request'
@@ -322,8 +317,8 @@ def get_several_ways(url):
* second request when not logged in (uses cache)
* using a language other than english
* logged in
- """
+ """
response = self.client.get(url)
assert_success(response)
assert 'Welcome' in response.content
@@ -404,7 +399,8 @@ def test_signup(self):
response = self.client.get(url)
assert_success(response)
- # clear the cache to avoid code that prevents many signups from same ip address
+ # clear the cache to avoid code that prevents many signups
+ # from same ip address
from django.core.cache import cache
cache.clear()
View
16 occupywallst/utils.py
@@ -26,8 +26,7 @@
class APIException(Exception):
- """Causes API wrapper to return an error result.
- """
+ """Causes API wrapper to return an error result"""
def __init__(self, message, results=[]):
self.message = message
self.results = results
@@ -91,8 +90,7 @@ def _api_view(request):
def _as_json(data):
- """Turns API result into JSON data
- """
+ """Turns API result into JSON data"""
data['results'] = sanitize_json(data['results'])
if settings.DEBUG:
content = json.dumps(data, indent=2) + '\n'
@@ -126,9 +124,7 @@ def sanitize_json(value):
def timesince(d, now=None):
- """
- Shortened version of django.utils.timesince.timesince
- """
+ """Shortened version of django.utils.timesince.timesince"""
chunks = (
(60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)),
(60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)),
@@ -162,8 +158,10 @@ def timesince(d, now=None):
def jstime(dt):
- """Convert datetime object to javascript timestamp (milliseconds
- since UTC UNIX epoch)
+ """Convert datetime object to javascript timestamp
+
+ In javascript, timestamps are represented as milliseconds since
+ the UNIX epoch in UTC.
"""
ts = int(time.mktime(dt.timetuple())) * 1000
if hasattr(dt, 'microsecond'):
View
3 occupywallst/views.py
@@ -88,8 +88,7 @@ def forum(request):
def bonus(request, page):
- """Render page based on Verbiage table entry
- """
+ """Render page based on Verbiage table entry"""
try:
res = db.Verbiage.get('/' + page, request.LANGUAGE_CODE)
except ObjectDoesNotExist:
View
3 occupywallst/widgets.py
@@ -8,7 +8,8 @@ class ReCaptcha(forms.widgets.Widget):
recaptcha_response_name = 'recaptcha_response_field'
def render(self, name, value, attrs=None):
- return mark_safe(u'%s' % captcha.displayhtml(settings.RECAPTCHA_PUBLIC_KEY))
+ return mark_safe(u'%s' % captcha.displayhtml(
+ settings.RECAPTCHA_PUBLIC_KEY))
def value_from_datadict(self, data, files, name):
return [data.get(self.recaptcha_challenge_name, None),

0 comments on commit 9939315

Please sign in to comment.
Something went wrong with that request. Please try again.