Skip to content

Commit

Permalink
grab wordlist for Windows; speed up tests; .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
zackmdavis committed Oct 18, 2014
1 parent eb1a650 commit e1ed970
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ static/libs/jquery-2.1.1.min.js
static/libs/underscore-min.js
static/libs/underscore-min.map

# local wordlist
static/libs/words

# logs
logs/finetooth.log*

# Coverage reports
.coverage
htmlcov/

# the database
db.sqlite3
18 changes: 15 additions & 3 deletions core/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import random
from math import log, ceil
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
from datetime import datetime
from collections import OrderedDict
from urllib.request import urlretrieve

from django.utils.text import slugify

Expand All @@ -14,6 +16,19 @@

FACTORY_USER_PASSWORD = "f:O>r<5H%UsBu"

if os.name == "posix":
dictionary_path = '/usr/share/dict/words'
else:
# if we're not on a Unix-like system (!?)
dictionary_path = os.path.join('static', 'libs', 'words')
# and haven't already done so
if not os.path.exists(dictionary_path):
# let's just grab a wordlist from the internet
urlretrieve("http://www.cs.duke.edu/~ola/ap/linuxwords")

This comment has been minimized.

Copy link
@zackmdavis

zackmdavis Oct 18, 2014

Author Owner

@cookjw I think this should let you use the TagFactory (and tests that depend on it)?

This comment has been minimized.

Copy link
@zackmdavis

zackmdavis Oct 18, 2014

Author Owner

I spoke too soon (urlretrieve needs a second argument of dictionary_path; forthcoming in next commit to master)


with open(dictionary_path) as dictionary:
WORDS = [word for word in dictionary.read().split('\n') if "'" not in word]

def romanize_sort_of(n):
pseudo_digits = OrderedDict(
((100, 'C'), (50, 'L'), (10, 'X'), (5, 'V'), (1, 'I'))
Expand Down Expand Up @@ -64,9 +79,6 @@ class Meta:
published_at = datetime.now()


with open('/usr/share/dict/words') as dictionary:
WORDS = [word for word in dictionary.read().split('\n') if "'" not in word]

class TagFactory(factory.DjangoModelFactory):
class Meta:
model = Tag
Expand Down
5 changes: 2 additions & 3 deletions core/views/view_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def paginated_context(request, pageable_name, pageables, page_number, context):
return context

def tag_cloud_context(tags):
if not tags:
return {}
min_size = 9
max_size = 20
tags = tags.annotate(Count('posts')).order_by('posts__count')
# XXX TODO FIXME: handle edge cases of 0 or 1 tags
if not tags:
return {}
min_count = tags[0].posts__count
max_count = tags[tags.count()-1].posts__count
def font_size(count):
Expand Down
3 changes: 3 additions & 0 deletions core/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.http import HttpRequest

from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.debug import sensitive_post_parameters
from django.views.decorators.http import require_POST
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
Expand All @@ -22,6 +23,7 @@
scored_context, paginated_view, paginated_context, tag_cloud_context
)


@paginated_view
def home(request, page_number):
all_posts = Post.objects.all()
Expand All @@ -31,6 +33,7 @@ def home(request, page_number):
print(context['cloud'])
return render(request, "home.html", context)

@sensitive_post_parameters('password')
def sign_up(request):
if request.method == "POST":
try:
Expand Down
3 changes: 3 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

AUTH_REDIRECT_URL = "/"

if DEBUG:
PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',)

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
Expand Down

0 comments on commit e1ed970

Please sign in to comment.