Commit 182d3fef authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch '43-python-3' into 'upgrade-django'

Resolve "Port to Python 3"

See merge request !13
parents 058b07c3 b7dd94fa
Pipeline #1216 passed with stage
in 23 seconds
......@@ -13,3 +13,4 @@ whats_open/secret_key.py
whats_open/assets/
static/admin/
data
whats_open/website/migrations
\ No newline at end of file
......@@ -15,5 +15,17 @@ whats-open-py2.7:
type: test
script:
- python manage.py test
whats-open-py3.5:
image: library/python:3.5
type: test
script:
- python manage.py test
whats-open-py3.6:
image: library/python:3.6
type: test
script:
- python manage.py test
- coverage run --source=website --omit=*migrations/*,*admin.py,*__init__.py,*.pyc manage.py test
- coverage html -i && grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
......@@ -18,7 +18,7 @@
# (You'll need to reverse proxy port 8000 via nginx)
# Set the base image to Ubuntu
FROM python:2.7
FROM python:3.6
ENV PYTHONUNBUFFERED 1
# File Author / Maintainer
......
......@@ -160,18 +160,19 @@ Open a terminal and run the following command:
Next, with:
sudo apt install python python-dev python-pip
sudo pip install virtualenv
sudo apt install python3 python3-dev python3-pip
sudo pip3 install virtualenv
you install `python`, `pip`, and `virtualenv`.
Next with,
virtualenv venv
source venv/bin/activate
virtualenv -p python3 whats_open
source whats_open/bin/activate
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
cd whats_open/
python3 manage.py makemigrations
python3 manage.py migrate
you setup the project.
......@@ -179,7 +180,7 @@ you setup the project.
Now that everything is set-up you can run the server on your computer.
python manage.py runserver
python3 manage.py runserver
Go to [http://127.0.0.1:8000/]() in your browser and you should see the website.
......
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Django Imports
from django.contrib import admin
# App Imports
from .models import Facility, Schedule, OpenTime, Category
class OpenTimeInline(admin.TabularInline):
......
from models import Facility
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Python stdlib Imports
import re
# App Imports
from .models import Facility
def export_data():
facilities = list()
......
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Python stdlib Imports
import datetime
# Django Imports
from django.db import models
from django.contrib.auth.models import User
from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField
import datetime
class Category(TimeStampedModel):
name = models.CharField(max_length=100)
......@@ -13,7 +20,7 @@ class Category(TimeStampedModel):
# Sort by name in admin view
ordering = ['name']
def __unicode__(self):
def __str__(self):
return '%s' % self.name
class Facility(TimeStampedModel):
......@@ -60,7 +67,7 @@ class Facility(TimeStampedModel):
return True
return False
def __unicode__(self):
def __str__(self):
return self.name
class Schedule(TimeStampedModel):
......@@ -88,7 +95,7 @@ class Schedule(TimeStampedModel):
return True
return False
def __unicode__(self):
def __str__(self):
return self.name
......@@ -144,7 +151,7 @@ class OpenTime(TimeStampedModel):
return False
return True
def __unicode__(self):
def __str__(self):
weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday']
return '%s %s to %s %s' % (weekdays[self.start_day],
......
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# App Imports
from .models import Category, Facility, Schedule, OpenTime
# Other Imports
from rest_framework import serializers
from website.models import Category, Facility, Schedule, OpenTime
class CategorySerializer(serializers.ModelSerializer):
class Meta:
......
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Django Imports
from django.conf.urls import include, url
......
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Python stdlib Imports
import hashlib
import json
# Django Imports
from django.template import RequestContext
from website.models import Facility, OpenTime
from website.api import export_data
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.views.decorators.http import condition
from django.views.generic import ListView, DetailView
from model_utils.models import TimeStampedModel
from website.models import Facility, OpenTime, Category, Schedule
from website.api import export_data
from website.serializers import CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
# App Imports
from .models import Facility, OpenTime, Category, Schedule
from .api import export_data
from .serializers import CategorySerializer, FacilitySerializer, ScheduleSerializer, OpenTimeSerializer
# Other Imports
from rest_framework import viewsets, status
from rest_framework.response import Response
from rest_framework.decorators import api_view
import hashlib
import json
# Rest Framework Class Views
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Category.objects.all()
......@@ -33,9 +39,9 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
if open_now is not None:
results = []
for fac in queryset:
print fac
print(fac)
if fac.isOpen():
print True
print(True)
results.append(fac)
return results
else:
......
......@@ -15,7 +15,7 @@ def get_env_setting(setting):
""" Get the environment setting or return exception """
try:
return environ[setting]
except KeyError:
except KeyError as ex:
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
......
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# Django Imports
from django.conf.urls import include, url
from django.contrib import admin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment