Skip to content
Permalink
Browse files

Upgrade to Django 1.11

NOTES:
- The next schema changes will NOT have South migrations, only plain Django migrations

DETAILS on the upgrade:

- [1.5] Non-form data in HTTP requests
https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest.POST
=> "to access the raw POST data for these cases, should use the request.body attribute instead."

- [1.5] simplejson no longer used
https://docs.djangoproject.com/en/2.2/releases/1.5/#system-version-of-simplejson-no-longer-used
=> import standard lib's json instead

- [1.5] deprecation of mimetype in HttpResponse*
https://docs.djangoproject.com/en/dev/internals/deprecation/#deprecation-removed-in-1-7
=> replace with content_type

- [1.6] Transaction refactoring
https://docs.djangoproject.com/en/2.2/releases/1.6/#transaction-management-apis
=> changes commit_on_success() to atomic()

- [1.7] Use Djangos built-in migrations instead of South
https://docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south

- [1.7] Don't use syncdb anymore
https://docs.djangoproject.com/en/2.2/releases/1.7/#schema-migrations

- [1.7] Use better way to run startup code
https://stackoverflow.com/questions/6791911/execute-code-when-django-starts-once-only
=> startup.run used for demo doesn't work anymore for some reason, but 1.7 has a new hook we can (ab)use

- [1.7] Reorg of contrib content types
https://docs.djangoproject.com/en/2.2/releases/1.7/#reorganization-of-django-contrib-contenttypes
=> change import for GenericForeignKey

- [1.8] TEMPLATE_ settings change
https://docs.djangoproject.com/en/2.2/releases/1.8/#template-related-settings

- [1.8] reverse doesn't take dotted path
https://docs.djangoproject.com/en/2.2/releases/1.8/#passing-a-dotted-path-to-reverse-and-url
=> use named url everywhere: defined them in urls.py, use them in reverse and {% url%}

- [1.8] dictionary and context_instance arguments of rendering functions
https://docs.djangoproject.com/en/dev/releases/1.8/#dictionary-and-context-instance-arguments-of-rendering-functions
=> replace render_to_response by render and change args

- [1.9] strip=True for CharField
https://docs.djangoproject.com/fr/1.9/ref/forms/fields/#django.forms.CharField.strip

- [1.11] TimeZONE none not allowed
https://docs.djangoproject.com/en/2.2/releases/1.11/#pytz-is-a-required-dependency-and-support-for-settings-time-zone-none-is-removed
  • Loading branch information...
tibonihoo committed May 19, 2019
1 parent 0a22a09 commit e6beb3969547d4617400c2cf47acefa6c80d845b
Showing with 533 additions and 314 deletions.
  1. +2 −0 .gitignore
  2. +2 −4 fabfile.py
  3. +0 −5 manage.py
  4. +1 −1 requirements_base.txt
  5. +27 −18 wateronmars/settings.py
  6. +70 −47 wateronmars/urls.py
  7. +0 −5 wateronmars/wsgi.py
  8. +41 −0 wom_classification/migrations/0001_initial.py
  9. 0 wom_classification/migrations/__init__.py
  10. +4 −3 wom_classification/models.py
  11. +28 −0 wom_pebbles/migrations/0001_initial.py
  12. 0 wom_pebbles/migrations/__init__.py
  13. +1 −1 wom_pebbles/tasks.py
  14. +27 −0 wom_river/migrations/0001_initial.py
  15. 0 wom_river/migrations/__init__.py
  16. +3 −3 wom_river/tasks.py
  17. +50 −0 wom_tributary/migrations/0001_initial.py
  18. 0 wom_tributary/migrations/__init__.py
  19. +1 −1 wom_tributary/tasks.py
  20. +2 −0 wom_user/__init__.py
  21. +19 −9 wateronmars/startup.py → wom_user/apps.py
  22. +7 −7 wom_user/forms.py
  23. +57 −0 wom_user/migrations/0001_initial.py
  24. 0 wom_user/migrations/__init__.py
  25. +5 −5 wom_user/tasks.py
  26. +8 −8 wom_user/templates/base_nojs.html
  27. +2 −2 wom_user/templates/bookmark_addition.html
  28. +1 −1 wom_user/templates/bookmark_edit.html
  29. +1 −1 wom_user/templates/bookmarks_import.html
  30. +4 −4 wom_user/templates/collection.html
  31. +5 −5 wom_user/templates/home.html
  32. +1 −1 wom_user/templates/login.html
  33. +1 −1 wom_user/templates/nsbmk_upload.html
  34. +1 −1 wom_user/templates/opml_upload.html
  35. +9 −9 wom_user/templates/profile.html
  36. +1 −1 wom_user/templates/sieve.html
  37. +2 −2 wom_user/templates/source_addition.html
  38. +4 −4 wom_user/templates/sources.html
  39. +2 −2 wom_user/templates/tributary_twitter.html
  40. +1 −1 wom_user/templates/twitter_source_addition.html
  41. +1 −1 wom_user/templates/user_creation.html
  42. +35 −34 wom_user/test_collection.py
  43. +47 −46 wom_user/test_river.py
  44. +2 −2 wom_user/test_tributary.py
  45. +2 −2 wom_user/test_userprofile.py
  46. +56 −77 wom_user/views.py
@@ -1,5 +1,7 @@
fabhosts.cfg

static

twitter_app_key
twitter_app_secret

@@ -76,15 +76,15 @@ def schema_reset(app_name):
print("Cleanup past migrations for {0}".format(app_name))
shutil.rmtree(migration_dir)
print("Initialize the migration data for {0}".format(app_name))
local("python manage.py schemamigration {0} --initial".format(app_name))
local("python manage.py makemigrations {0} --initial".format(app_name))
print("""Don't forget that to cancel previous migrations of the actual db (if any) with:
python manage.py migrate {0} zero""".format(app_name))

def schema_update(app_name=None):
app_selection = [app_name] if app_name else DJANGO_APPS
for app in app_selection:
try:
local("python manage.py schemamigration {0} --auto".format(app))
local("python manage.py makemigrations {0} --auto".format(app))
except:
if app_name is None:
pass
@@ -104,11 +104,9 @@ def db_reset():
print("Remove db.sql3")
os.remove("./db.sql3")
print("Setup the base db")
local("python manage.py syncdb")
local("python manage.py migrate")

def db_update():
local("python manage.py syncdb")
local("python manage.py migrate")

def transl_gen(lang):
@@ -25,11 +25,6 @@
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wateronmars.settings")

if "runserver" in sys.argv[1:]:
# Use Eldarion/Pinax's trick to get an entry point at startup
# (see http://eldarion.com/blog/2013/02/14/entry-point-hook-django-projects/)
import wateronmars.startup as startup
startup.run()
if "test" in sys.argv[1:]:
# Make sure we're not in demo mode for the tests
from django.conf import settings
@@ -1,4 +1,4 @@
Django==1.4.20 # rq.filter: >=1.4,<1.5
Django==1.11
South==1.0.1
feedparser==5.1.3
beautifulsoup4
@@ -91,7 +91,6 @@

# DEBUG or not DEBUG
DEBUG = False
TEMPLATE_DEBUG = DEBUG


# Database setup
@@ -124,7 +123,7 @@
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = None
TIME_ZONE = "Europe/Paris"

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
@@ -157,7 +156,7 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ""
STATIC_ROOT = os.path.join(APP_BASE_DIR, "static")

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
@@ -180,13 +179,32 @@
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'q-@+zcucbl_@i7fjf@fm_gnqmifik8e&amp;l8j24x!r7z*z7cjls%'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]


MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
@@ -203,14 +221,6 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wateronmars.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
#"/home/thibauld/Development/wateronmars/wom-experiment/templates"
)



INSTALLED_APPS = (
'django.contrib.auth',
@@ -223,7 +233,6 @@
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'south',
'wom_pebbles',
'wom_river',
'wom_classification',
@@ -20,60 +20,83 @@


import settings
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^robots.txt$', 'wom_user.views.get_robots_txt'),
url(r'^humans.txt$', 'wom_user.views.get_humans_txt'),
url(r'^$', 'wom_user.views.home', name='home'),
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
url(r'^accounts/logout/$', 'wom_user.views.user_logout'),
url(r'^accounts/profile/$', 'wom_user.views.user_profile'),
url(r'^u/(?P<owner_name>[^/]*)/$', 'wom_user.views.user_root'),
url(r'^u/(?P<owner_name>[^/]*)/sources/opml/$', 'wom_user.views.user_upload_opml'),
url(r'^u/(?P<owner_name>[^/]*)/collection/$', 'wom_user.views.user_collection'),
url(r'^u/(?P<owner_name>[^/]*)/collection/nsbmk/$', 'wom_user.views.user_upload_nsbmk'),
url(r'^u/(?P<owner_name>[^/]*)/sources/$', 'wom_user.views.user_river_sources'),
url(r'^u/(?P<owner_name>[^/]*)/sources/add/$', 'wom_user.views.user_river_source_add'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/$', 'wom_user.views.user_tributary'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/twitter/$', 'wom_user.views.user_tributary_twitter'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/twitter/add/$', 'wom_user.views.user_tributary_twitter_add'),
url(r'^u/(?P<owner_name>[^/]*)/sources/item/(?P<source_url>.*)$', 'wom_user.views.user_river_source_item'),
url(r'^u/(?P<owner_name>[^/]*)/river/$', 'wom_user.views.user_river_view'),
url(r'^u/(?P<owner_name>[^/]*)/sieve/$', 'wom_user.views.user_river_sieve'),
url(r'^u/(?P<owner_name>[^/]*)/collection/add/$','wom_user.views.user_collection_add'),
url(r'^u/(?P<owner_name>[^/]*)/collection/item/(?P<reference_url>.*)$','wom_user.views.user_collection_item'),
# access to static files
url(r'^static/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
)

from wom_user.views import (
get_robots_txt,
get_humans_txt,
home,
user_logout,
user_profile,
user_root,
user_upload_opml,
user_collection,
user_upload_nsbmk,
user_river_sources,
user_river_source_add,
user_tributary,
user_tributary_twitter,
user_tributary_twitter_add,
user_river_source_item,
user_river_view,
user_river_sieve,
user_collection_add,
user_collection_item,
request_for_update,
request_for_cleanup,
user_creation,
user_auth_landing_twitter,
)

from django.contrib.auth.views import login
from django.views.static import serve as static_serve


urlpatterns = [
url(r'^robots.txt$', get_robots_txt),
url(r'^humans.txt$', get_humans_txt),
url(r'^$', home, name='home'),
url(r'^accounts/login/$', login, {'template_name': 'login.html'}, name='user_login'),
url(r'^accounts/logout/$', user_logout, name='user_logout'),
url(r'^accounts/profile/$', user_profile, name='user_profile'),
url(r'^u/(?P<owner_name>[^/]*)/$', user_root, name='user_root'),
url(r'^u/(?P<owner_name>[^/]*)/sources/opml/$', user_upload_opml, name='user_upload_opml'),
url(r'^u/(?P<owner_name>[^/]*)/collection/$', user_collection, name='user_collection'),
url(r'^u/(?P<owner_name>[^/]*)/collection/nsbmk/$', user_upload_nsbmk, name='user_upload_nsbmk'),
url(r'^u/(?P<owner_name>[^/]*)/sources/$', user_river_sources, name='user_river_sources'),
url(r'^u/(?P<owner_name>[^/]*)/sources/add/$', user_river_source_add, name='user_river_source_add'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/$', user_tributary, name='user_tributary'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/twitter/$', user_tributary_twitter, name='user_tributary_twitter'),
url(r'^u/(?P<owner_name>[^/]*)/sources/tributary/twitter/add/$', user_tributary_twitter_add, name='user_tributary_twitter_add'),
url(r'^u/(?P<owner_name>[^/]*)/sources/item/(?P<source_url>.*)$', user_river_source_item, name='user_river_source_item'),
url(r'^u/(?P<owner_name>[^/]*)/river/$', user_river_view, name='user_river_view'),
url(r'^u/(?P<owner_name>[^/]*)/sieve/$', user_river_sieve, name='user_river_sieve'),
url(r'^u/(?P<owner_name>[^/]*)/collection/add/$', user_collection_add, name='user_collection_add'),
url(r'^u/(?P<owner_name>[^/]*)/collection/item/(?P<reference_url>.*)$',user_collection_item, name='user_collection_item'),
# access to static files
url(r'^static/(?P<path>.*)$', static_serve, {'document_root': settings.STATIC_ROOT}),
]

if not settings.USE_CELERY:
urlpatterns += patterns('',
# temporary hack to avoid depending too much on
# background tasks
url(r'^houston/we_ve_got_an_update_request/$',
'wom_user.views.request_for_update'),
url(r'^houston/we_ve_got_a_cleanup_request/$',
'wom_user.views.request_for_cleanup'),
)
urlpatterns += [
# temporary hack to avoid depending too much on
# background tasks
url(r'^houston/we_ve_got_an_update_request/$', request_for_update),
url(r'^houston/we_ve_got_a_cleanup_request/$', request_for_cleanup),
]

if not settings.READ_ONLY:
urlpatterns += patterns('',
url(r'^accounts/new/$',
'wom_user.views.user_creation'),
url(r'^accounts/auth_landing/twitter/$',
'wom_user.views.user_auth_landing_twitter'),
url(r'^admin/',
include(admin.site.urls)),
# Uncomment the admin/doc line below to
# enable admin documentation
url(r'^admin/doc/',
include('django.contrib.admindocs.urls')),
)
urlpatterns += [
url(r'^accounts/new/$', user_creation),
url(r'^accounts/auth_landing/twitter/$', user_auth_landing_twitter, name='user_auth_landing_twitter'),
url(r'^admin/', include(admin.site.urls)),
# Uncomment the admin/doc line below to
# enable admin documentation
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
]

@@ -37,11 +37,6 @@

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wateronmars.settings")

# Use Eldarion/Pinax's trick to get an entry point at startup
# (see http://eldarion.com/blog/2013/02/14/entry-point-hook-django-projects/)
import wateronmars.startup as startup
startup.run()


# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-05-19 19:41
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='ClassificationData',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('object_id', models.PositiveIntegerField()),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(db_index=True, max_length=100, unique=True)),
],
),
migrations.AddField(
model_name='classificationdata',
name='tags',
field=models.ManyToManyField(to='wom_classification.Tag'),
),
]
No changes.
@@ -22,7 +22,8 @@
from django.db import transaction

from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.fields import GenericForeignKey


from django.contrib.auth.models import User

@@ -59,7 +60,7 @@ class ClassificationData(models.Model):

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
content_object = GenericForeignKey('content_type', 'object_id')

def __unicode__(self):
return u"%s>%s: %s" % (self.owner.username,
@@ -129,7 +130,7 @@ def set_item_tag_names(user,item,names):
else:
t = Tag(name=tag_name)
new_tags.append(t)
with transaction.commit_on_success():
with transaction.atomic():
for t in new_tags:
t.save()
return set_item_tags(user,item,tag_list+new_tags)
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-05-19 19:41
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Reference',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.CharField(max_length=255, unique=True)),
('title', models.CharField(max_length=150)),
('description', models.TextField(blank=True, default=b'')),
('pub_date', models.DateTimeField(verbose_name=b'date published')),
('pin_count', models.IntegerField(default=0)),
('sources', models.ManyToManyField(related_name='productions', to='wom_pebbles.Reference')),
],
),
]
No changes.
@@ -165,7 +165,7 @@ def import_references_from_ns_bookmark_list(nsbmk_txt):
set(bmk_info.get("tags","").split(",")),
bmk_info.get("private","0")=="0")
ref_and_metadata.append((ref,meta))
with transaction.commit_on_success():
with transaction.atomic():
for ref in new_refs:
ref.save()
ref.sources.add(common_source)

0 comments on commit e6beb39

Please sign in to comment.
You can’t perform that action at this time.