Skip to content

Commit

Permalink
Merge pull request #303 from domino14/django2.0
Browse files Browse the repository at this point in the history
upgrade to django 2.0
  • Loading branch information
domino14 authored Dec 25, 2018
2 parents cc856ca + d2909ef commit ca5a14a
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 64 deletions.
6 changes: 4 additions & 2 deletions base_pkg.dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Base image that we can base the prod image on.

FROM python:3-alpine
MAINTAINER Cesar Del Solar <delsolar@gmail.com>
LABEL maintainer="Cesar Del Solar <delsolar@gmail.com>"

ENV PYTHONUNBUFFERED 1

RUN apk add --update gettext postgresql-dev postgresql gcc musl-dev libffi-dev make
RUN apk add --update gettext postgresql-dev postgresql gcc musl-dev \
libffi-dev make python-dev jpeg-dev zlib-dev

COPY djAerolith/prod_requirements.txt /opt/prod_requirements.txt
ENV LIBRARY_PATH=/lib:/usr/lib
RUN pip install --upgrade pip
RUN pip install -r /opt/prod_requirements.txt

Expand Down
4 changes: 2 additions & 2 deletions djAerolith/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Migration(migrations.Migration):
('wordwallsMedals', models.TextField(null=True, blank=True)),
('avatarUrl', models.CharField(max_length=512, null=True, blank=True)),
('additional_data', models.TextField(default=b'{}', blank=True)),
('defaultLexicon', models.ForeignKey(default=accounts.models.getLexicon, to='base.Lexicon')),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
('defaultLexicon', models.ForeignKey(default=accounts.models.getLexicon, to='base.Lexicon', on_delete=models.SET_DEFAULT)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
]
6 changes: 4 additions & 2 deletions djAerolith/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def getLexicon(request=None):


class AerolithProfile(models.Model):
user = models.OneToOneField(User)
user = models.OneToOneField(User,
on_delete=models.CASCADE)

coins = models.IntegerField(default=0)
profile = models.CharField(max_length=2000, blank=True)
Expand Down Expand Up @@ -63,7 +64,8 @@ class AerolithProfile(models.Model):
wordwallsSaveListSize = models.IntegerField(default=0)

# project-wide
defaultLexicon = models.ForeignKey(Lexicon, default=getLexicon)
defaultLexicon = models.ForeignKey(Lexicon, default=getLexicon,
on_delete=models.SET_DEFAULT)
avatarUrl = models.CharField(null=True, blank=True, max_length=512)
additional_data = models.TextField(default='{}', blank=True)

Expand Down
6 changes: 3 additions & 3 deletions djAerolith/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

# To contact the author, please email delsolar at gmail dot com

from django.conf.urls import url
from django.urls import path, re_path
from accounts.views import editProfile, viewProfile

urlpatterns = [
url(r'^$', editProfile, name='accounts_edit_profile'),
url(r'^(?P<username>.+)/$', viewProfile, name='accounts_view_profile'),
re_path(r'^$', editProfile, name='accounts_edit_profile'),
path(r'<str:username>', viewProfile, name='accounts_view_profile'),
]
10 changes: 5 additions & 5 deletions djAerolith/base/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Migration(migrations.Migration):
('curQuestions', models.TextField()),
('missed', models.TextField()),
('firstMissed', models.TextField()),
('lexicon', models.ForeignKey(to='base.Lexicon')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('lexicon', models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
options={
'db_table': 'wordwalls_savedlist',
Expand All @@ -65,14 +65,14 @@ class Migration(migrations.Migration):
('back_hooks', models.CharField(max_length=26)),
('inner_front_hook', models.BooleanField(default=False)),
('inner_back_hook', models.BooleanField(default=False)),
('alphagram', models.ForeignKey(to='base.Alphagram')),
('lexicon', models.ForeignKey(to='base.Lexicon')),
('alphagram', models.ForeignKey(to='base.Alphagram', on_delete=models.CASCADE)),
('lexicon', models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE)),
],
),
migrations.AddField(
model_name='alphagram',
name='lexicon',
field=models.ForeignKey(to='base.Lexicon'),
field=models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE),
),
migrations.AlterUniqueTogether(
name='alphagram',
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/base/migrations/0008_savedlist_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='savedlist',
name='category',
field=models.CharField(choices=[(b'A', b'Anagram'), (b'B', b'Build'), (b'T', b'Through')], default=b'A', max_length=2),
field=models.CharField(choices=[('A', 'Anagram'), ('B', 'Build'), ('T', 'Through')], default='A', max_length=2),
),
]
8 changes: 4 additions & 4 deletions djAerolith/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class SavedList(models.Model):
(CATEGORY_THROUGH_TILES, 'Through')
)

lexicon = models.ForeignKey(Lexicon)
lexicon = models.ForeignKey(Lexicon, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
lastSaved = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=50)
user = models.ForeignKey(User)
user = models.ForeignKey(User, on_delete=models.CASCADE)

numAlphagrams = models.IntegerField()
numCurAlphagrams = models.IntegerField()
Expand Down Expand Up @@ -287,8 +287,8 @@ class AlphagramTag(models.Model):
('D2', 'Hard'),
('D1', 'Very Hard'),
)
user = models.ForeignKey(User)
lexicon = models.ForeignKey(Lexicon)
user = models.ForeignKey(User, on_delete=models.CASCADE)
lexicon = models.ForeignKey(Lexicon, on_delete=models.CASCADE)
alphagram = models.CharField(max_length=15)
tag = models.CharField(choices=WORD_TAGS, max_length=2)

Expand Down
4 changes: 2 additions & 2 deletions djAerolith/djaerolith/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def tobool(val):
)


MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -124,7 +124,7 @@ def tobool(val):
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'middleware.session_expiry.SessionIdleTimeout',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
)

ROOT_URLCONF = 'djaerolith.urls'
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/djaerolith/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_success_url(self, user):
url(r'^privacy/', TemplateView.as_view(template_name='privacy.html')),
url(r'^tos/', TemplateView.as_view(template_name='tos.html')),

url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),
url(r'^accounts/social/$', social),
url(r'^accounts/profile/', include('accounts.urls')),
url(r'^accounts/register/$', AerolithRegistrationView.as_view(
Expand Down
4 changes: 2 additions & 2 deletions djAerolith/flashcards/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Migration(migrations.Migration):
('difficulty', models.IntegerField(default=0)),
('next_scheduled', models.DateTimeField(null=True)),
('box', models.IntegerField(default=0)),
('alphagram', models.ForeignKey(to='base.Alphagram')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('alphagram', models.ForeignKey(to='base.Alphagram', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.AlterUniqueTogether(
Expand Down
14 changes: 10 additions & 4 deletions djAerolith/middleware/session_expiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@


class SessionIdleTimeout:
"""Middleware class to timeout a session after a specified time period.
"""
def process_request(self, request):
Middleware class to timeout a session after a specified time period.
"""
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
# Timeout is done only for authenticated logged in users.
if request.user.is_authenticated():
if request.user.is_authenticated:
current_datetime = datetime.datetime.now()
# Timeout if idle time period is exceeded.
if ('last_activity' in request.session and
Expand All @@ -19,4 +23,6 @@ def process_request(self, request):
# Set last activity time in current session.
else:
request.session['last_activity'] = current_datetime
return None

response = self.get_response(request)
return response
3 changes: 2 additions & 1 deletion djAerolith/prod_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are the requirements for the prod Docker file.

django>=1.11,<2.0
django>=2.0,<2.1
six >= 1.7
Markdown
django-registration-redux
Expand All @@ -18,3 +18,4 @@ gunicorn
# Not strictly a prod requirement. However, the main issue here
# is that we can't run tests in the docker container otherwise.
mock
wagtail
2 changes: 1 addition & 1 deletion djAerolith/tablegame/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Migration(migrations.Migration):
('text', models.TextField(help_text=b'A message, either typed in by a user or generated by the system.', null=True, blank=True)),
('unix_timestamp', models.FloatField(help_text=b'Unix timestamp when this message was inserted into the database.', editable=False)),
('created', models.DateTimeField(editable=False)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
]
6 changes: 4 additions & 2 deletions djAerolith/tablegame/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class GenericTableGameModel(models.Model):
(SINGLEPLAYER_GAME, "SinglePlayer"),
(MULTIPLAYER_GAME, "MultiPlayer"),
)
lexicon = models.ForeignKey(Lexicon)
host = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_host")
lexicon = models.ForeignKey(Lexicon, on_delete=models.CASCADE)
host = models.ForeignKey(User,
related_name="%(app_label)s_%(class)s_host",
on_delete=models.CASCADE)
inTable = models.ManyToManyField(
User, related_name="%(app_label)s_%(class)s_inTable")
lastActivity = models.DateTimeField(auto_now=True)
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def healthz(request):


def jwt_req(request):
if not request.user.is_authenticated():
if not request.user.is_authenticated:
return response({
'error': 'Must log in',
}, status=StatusCode.FORBIDDEN)
Expand Down
20 changes: 10 additions & 10 deletions djAerolith/wordwalls/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Migration(migrations.Migration):
('date', models.DateField()),
('alphagrams', models.TextField()),
('seconds', models.IntegerField()),
('lexicon', models.ForeignKey(to='base.Lexicon')),
('lexicon', models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
Expand All @@ -29,7 +29,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('maxScore', models.IntegerField()),
('medalsAwarded', models.BooleanField(default=False)),
('challenge', models.OneToOneField(to='wordwalls.DailyChallenge')),
('challenge', models.OneToOneField(to='wordwalls.DailyChallenge', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
Expand All @@ -40,17 +40,17 @@ class Migration(migrations.Migration):
('timeRemaining', models.IntegerField()),
('qualifyForAward', models.BooleanField(default=True)),
('additionalData', models.TextField(null=True)),
('board', models.ForeignKey(to='wordwalls.DailyChallengeLeaderboard')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('board', models.ForeignKey(to='wordwalls.DailyChallengeLeaderboard', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
name='DailyChallengeMissedBingos',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('numTimesMissed', models.IntegerField(default=0)),
('alphagram', models.ForeignKey(to='base.Alphagram')),
('challenge', models.ForeignKey(to='wordwalls.DailyChallenge')),
('alphagram', models.ForeignKey(to='base.Alphagram', on_delete=models.CASCADE)),
('challenge', models.ForeignKey(to='wordwalls.DailyChallenge', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
Expand All @@ -74,7 +74,7 @@ class Migration(migrations.Migration):
('wordLength', models.IntegerField()),
('isRange', models.BooleanField()),
('questions', models.TextField(default=b'')),
('lexicon', models.ForeignKey(to='base.Lexicon')),
('lexicon', models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE)),
],
),
migrations.CreateModel(
Expand All @@ -93,9 +93,9 @@ class Migration(migrations.Migration):
('missed', models.TextField()),
('numFirstMissed', models.IntegerField()),
('firstMissed', models.TextField()),
('host', models.ForeignKey(related_name='wordwalls_wordwallsgamemodel_host', to=settings.AUTH_USER_MODEL)),
('host', models.ForeignKey(related_name='wordwalls_wordwallsgamemodel_host', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
('inTable', models.ManyToManyField(related_name='wordwalls_wordwallsgamemodel_inTable', to=settings.AUTH_USER_MODEL)),
('lexicon', models.ForeignKey(to='base.Lexicon')),
('lexicon', models.ForeignKey(to='base.Lexicon', on_delete=models.CASCADE)),
],
options={
'abstract': False,
Expand All @@ -104,7 +104,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='dailychallenge',
name='name',
field=models.ForeignKey(to='wordwalls.DailyChallengeName'),
field=models.ForeignKey(to='wordwalls.DailyChallengeName', on_delete=models.CASCADE),
),
migrations.AlterUniqueTogether(
name='dailychallengemissedbingos',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='wordwallsgamemodel',
name='word_list',
field=models.ForeignKey(to='base.WordList', null=True),
field=models.ForeignKey(to='base.WordList', null=True, on_delete=models.SET_NULL),
),
]
2 changes: 1 addition & 1 deletion djAerolith/wordwalls/migrations/0004_auto_20151016_1822.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='dailychallengemissedbingos',
name='alphagram',
field=models.ForeignKey(to='base.Alphagram', null=True),
field=models.ForeignKey(to='base.Alphagram', null=True, on_delete=models.CASCADE),
),
migrations.AlterUniqueTogether(
name='dailychallengemissedbingos',
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/wordwalls/migrations/0007_auto_20160113_0944.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='wordwallsgamemodel',
name='word_list',
field=models.ForeignKey(default=1, to='base.WordList'),
field=models.ForeignKey(default=1, to='base.WordList', on_delete=models.SET_NULL),
preserve_default=False,
),
migrations.AlterUniqueTogether(
Expand Down
4 changes: 2 additions & 2 deletions djAerolith/wordwalls/migrations/0010_auto_20170301_0923.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('medal_type', models.CharField(max_length=2, choices=[(b'B', b'Bronze'), (b'S', b'Silver'), (b'G', b'Gold'), (b'PS', b'Platinum'), (b'GS', b'GoldStar')])),
('leaderboard', models.ForeignKey(to='wordwalls.DailyChallengeLeaderboard')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('leaderboard', models.ForeignKey(to='wordwalls.DailyChallengeLeaderboard', on_delete=models.CASCADE)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
],
),
migrations.AlterUniqueTogether(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='dailychallenge',
name='category',
field=models.CharField(choices=[(b'A', b'Anagram'), (b'B', b'Build'), (b'T', b'Through')], default=b'A', max_length=2),
field=models.CharField(choices=[('A', 'Anagram'), ('B', 'Build'), ('T', 'Through')], default='A', max_length=2),
),
]
Loading

0 comments on commit ca5a14a

Please sign in to comment.