Skip to content

Commit

Permalink
Merge pull request #213 from domino14/improvement/196/spa
Browse files Browse the repository at this point in the history
Improvement/196/spa
  • Loading branch information
domino14 authored Mar 13, 2017
2 parents 43adbfa + b5fff6a commit 980a23a
Show file tree
Hide file tree
Showing 110 changed files with 3,580 additions and 3,525 deletions.
36 changes: 0 additions & 36 deletions config/supervisord_dev.conf

This file was deleted.

32 changes: 0 additions & 32 deletions dc-dev.yml

This file was deleted.

19 changes: 17 additions & 2 deletions djAerolith/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import json
import uuid

from datetime import datetime
from django.db import models
from django.contrib.auth.models import User

from base.validators import word_list_format_validator
from lib.dates import pretty_date

EXCLUDED_LEXICA = [
'OWL2',
'CSW07',
Expand Down Expand Up @@ -182,7 +185,12 @@ def to_python(self):
'temporary': self.is_temporary
}

def to_python_reduced(self):
def date_to_str(self, dt, human):
if not human:
return dt.strftime('%Y-%m-%d %H:%M')
return pretty_date(datetime.now(), dt)

def to_python_reduced(self, last_saved_human=False):
"""
Converts to a Python object, but this is a reduced form. This
should be used for "get_all" type responses.
Expand All @@ -198,7 +206,14 @@ def to_python_reduced(self):
'goneThruOnce': self.goneThruOnce,
'questionIndex': self.questionIndex,
'version': self.version,
'lastSaved': self.lastSaved.strftime('%Y-%m-%d %H:%M'),
# Note: This time is given in the Django installation's local
# time (which happens to be Los Angeles). It is probably better
# to make the local time UTC, and then do the transformation
# client side. In this case, we'll have to transform the
# time client side from Los Angeles time >.<
# XXX: We should turn on time zone support, etc.
'lastSaved': self.date_to_str(self.lastSaved, last_saved_human),
'lastSavedDT': self.date_to_str(self.lastSaved, False),
'id': self.pk,
'temporary': self.is_temporary
}
Expand Down
1 change: 1 addition & 0 deletions djAerolith/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ def quiz_response(quiz):
'questionIndex': quiz.questionIndex,
'id': quiz.id
}

28 changes: 25 additions & 3 deletions djAerolith/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,36 @@ def saved_lists_get(request):
query_params = request.GET
qargs = {'user': request.user}
lexicon = query_params.get('lexicon')
lexicon_id = query_params.get('lexicon_id')
temporary = query_params.get('temp')
last_saved_human = False
order_by = 'id'
if lexicon:
# Search by name
qargs['lexicon__lexiconName'] = lexicon
elif lexicon_id:
# Search by id
qargs['lexicon__pk'] = lexicon_id
if temporary:
qargs['is_temporary'] = temporary == '1'
lists = WordList.objects.filter(**qargs)
return response({'lists': [sl.to_python_reduced() for sl in lists],
'count': lists.count()})
if query_params.get('order_by') == 'modified':
order_by = '-lastSaved'
if query_params.get('last_saved') == 'human':
last_saved_human = True

lists = WordList.objects.filter(**qargs).order_by(order_by)
profile = request.user.aerolithprofile
limit = 0
if not profile.member:
limit = settings.SAVE_LIST_LIMIT_NONMEMBER
return response({'lists': [sl.to_python_reduced(last_saved_human)
for sl in lists],
'count': lists.count(),
'limits': {
'total': limit,
'current': profile.wordwallsSaveListSize,
}
})


def saved_lists_delete(request):
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/current_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_VERSION = '0.9.1.0'
CURRENT_VERSION = '0.10.0.0'
43 changes: 43 additions & 0 deletions djAerolith/lib/dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext


def pretty_date(now, time):
"""
Get a datetime object and return a
pretty string like 'an hour ago', 'Yesterday', '3 months ago',
'just now', etc
"""

diff = now - time
second_diff = diff.seconds
day_diff = diff.days

if day_diff < 0:
return ''

if day_diff == 0:
if second_diff < 10:
return _("just now")
if second_diff < 60:
return _("%(seconds)s seconds ago") % {'seconds': second_diff}
if second_diff < 120:
return _("a minute ago")
if second_diff < 3600:
return _("%(minutes)s minutes ago") % {'minutes': second_diff / 60}
if second_diff < 7200:
return _("an hour ago")
if second_diff < 86400:
return _("%(hours)s hours ago") % {'hours': second_diff / 3600}
if day_diff == 1:
return _("Yesterday")
if day_diff < 7:
return _("%(day_diff)s days ago") % {'day_diff': day_diff}
if day_diff < 31:
return ungettext('%(week)d week ago', '%(week)d weeks ago',
day_diff / 7) % {'week': day_diff / 7}
if day_diff < 365:
return ungettext('%(month)d month ago', '%(month)d months ago',
day_diff / 30) % {'month': day_diff / 30}
return ungettext('%(year)d year ago', '%(year)d years ago',
day_diff / 365) % {'year': day_diff / 365}
6 changes: 5 additions & 1 deletion djAerolith/lib/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class StatusCode(object):
# returns an HttpResponse with a json-dump of obj
def response(obj, status=StatusCode.OK):
resp = HttpResponse(json.dumps(obj, ensure_ascii=False),
content_type="application/javascript; charset=utf-8",
content_type="application/json; charset=utf-8",
status=status)
return resp


def bad_request(obj):
return response(obj, StatusCode.BAD_REQUEST)
7 changes: 6 additions & 1 deletion djAerolith/lib/word_db_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def get_questions_for_probability_range(self, probability_min,
repeatedly.
"""
import time
t = time.time()
c = self.conn.cursor()
query = """
SELECT lexicon_symbols, definition, front_hooks, back_hooks,
Expand All @@ -318,7 +320,10 @@ def get_questions_for_probability_range(self, probability_min,
query = query + "ORDER BY alphagrams.probability"
c.execute(query, (length, probability_min, probability_max))
rows = c.fetchall()
return self.process_question_query(rows)
questions = self.process_question_query(rows)
logger.debug('Time taken: %s s. (params: %s, %s-%s)', time.time() - t,
length, probability_min, probability_max)
return questions

def get_questions_from_alph_dicts(self, alph_objects):
"""
Expand Down
54 changes: 31 additions & 23 deletions djAerolith/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,14 @@ def tobool(val):

ACCOUNT_ACTIVATION_DAYS = 2
LOGIN_REDIRECT_URL = "/"
# Used by social auth.
LOGIN_ERROR_URL = '/login_error/'
EMAIL_HOST = "smtp.mailgun.org"
EMAIL_PORT = 587
EMAIL_HOST_USER = 'postmaster@aerolith.mailgun.org'
EMAIL_HOST_USER = 'postmaster@mg.aerolith.org'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PW')
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '[email protected].org'
DEFAULT_FROM_EMAIL = '[email protected].org'

LOGIN_URL = "/accounts/login"

Expand All @@ -249,7 +250,7 @@ def tobool(val):

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'disable_existing_loggers': False,
'filters': {
'skip_suspicious_operations': {
'()': 'django.utils.log.CallbackFilter',
Expand All @@ -266,14 +267,10 @@ def tobool(val):
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
'formatter': 'verbose'
},
'mail_admins': {
'level': 'ERROR',
Expand All @@ -285,7 +282,12 @@ def tobool(val):
'loggers': {
'django.db': {
'handlers': ['console'],
'level': 'INFO'
'level': 'INFO',
},
'social': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
'': { # catch-all
'handlers': ['console', 'mail_admins'],
Expand All @@ -303,21 +305,27 @@ def tobool(val):
'formatter': 'verbose',
'backupCount': 10
}
LOGGING['loggers']['django.db'] = {
'handlers': ['log_file'],
'level': 'INFO'
}
LOGGING['loggers']['django.request'] = {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
}
LOGGING['loggers'][''] = {
'handlers': ['log_file', 'mail_admins'],
'level': 'DEBUG',
'propagate': True,

LOGGING['loggers'] = {
'django.db': {
'handlers': ['log_file', 'mail_admins'],
'level': 'INFO'
},
'': {
'handlers': ['log_file', 'mail_admins'],
'level': 'DEBUG',
}
}
LOGGING['disable_existing_loggers'] = False
# We might swallow errors if we uncomment the following. The
# issue is that the social exception middleware does a logger.error
# even though it handles the exception, and this causes the mailer
# to mail us.
# LOGGING['loggers']['social'] = {
# 'handlers': ['log_file'],
# 'level': 'ERROR',
# 'propagate': False,
# }


USE_MX = tobool(os.environ.get('USE_MX'))
USE_GA = tobool(os.environ.get('USE_GA'))
Expand Down
Loading

0 comments on commit 980a23a

Please sign in to comment.