Skip to content

Django 2.0 - (incomplete) #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
e45a89a
!
Apr 5, 2019
e1ddaca
updates
Apr 5, 2019
05d66fd
add dockerfile hooks
Apr 5, 2019
c92a2fa
fix hook
Apr 5, 2019
14fad39
fix build
Apr 5, 2019
c934cc3
chore(circleci): 1.7.7
Apr 6, 2019
739e206
add circleci status badge
Apr 6, 2019
9413593
fix(circleci): add auth creds
Apr 6, 2019
a29e15f
fix(readme): build status icon
Apr 6, 2019
dd839bb
feat(middleware): log non-json requests as well
Apr 8, 2019
07f8737
Merge pull request #2 from jalMogo/jalmogo/update-logging
jalMogo Apr 8, 2019
016fe3d
refactor(django): upgrade to 1.10
Apr 6, 2019
92efd07
chore(migrations): add 1.10 migrations
Apr 6, 2019
01978e9
feat(django): upgrade 1.10
Apr 6, 2019
0aa6d35
fix(dataPermissions): update help text
Apr 6, 2019
5aa8c9b
fix(dockerfile): fix build
Apr 6, 2019
8801724
fix(dockerfile): build
Apr 6, 2019
e1162b4
fix(dockerfile): build
Apr 6, 2019
a0132b1
feat(circleci): bump version
Apr 6, 2019
be1a7b7
fix(settings): update templates
Apr 8, 2019
3f01fb9
fix(logger): 1.10 logger updates
Apr 8, 2019
b018e41
Merge pull request #1 from jalMogo/jalmogo/django-1.10
jalMogo Apr 9, 2019
e46f306
chore(middleware): upgrade middleware
Apr 9, 2019
1f2c42b
chore(dockerfile): bump version
Apr 9, 2019
3a03529
chore(settings.py): rename vars
Apr 9, 2019
3eed1ac
feat(middleware): log responses
Apr 9, 2019
3de01b3
refactor(middleware): renaming
Apr 9, 2019
a8dbf7d
fix(middleware): empty response content check
Apr 10, 2019
0700ed3
Merge pull request #3 from jalMogo/jalmogo/upgrade-middleware
jalMogo Apr 11, 2019
ac39325
fix(middleware): check content type
Apr 11, 2019
0ef781f
Merge pull request #5 from jalMogo/jalmogo/fix-logging
jalMogo Apr 11, 2019
5129ecf
fix(middleware): get response header
Apr 11, 2019
a16cb68
Merge pull request #6 from jalMogo/jalmogo/fix-logging
jalMogo Apr 11, 2019
6856015
feat(django-1.11): upgrade to 1.11, fix tests
Apr 10, 2019
fe95403
feat(Dockerfile): 1.9.0
Apr 10, 2019
2a1a381
feat(start.sh): show migrations on startup
Apr 11, 2019
bf087ff
fix(serializers): include request context in url representation
Apr 13, 2019
2d2076b
fix(serializerTests): url
Apr 13, 2019
777410c
Merge pull request #4 from jalMogo/jalmogo/django-1.11
jalMogo Apr 16, 2019
c095ca3
feat(serializers): create serializers core and dir
Apr 14, 2019
9f41241
feat(serializers): remove original serializers
Apr 14, 2019
c967d29
fix(serializers/core): import paths
Apr 14, 2019
9b22c8e
refactor(serializer/mixins): separate module
Apr 14, 2019
2ba0f7a
refactor(serializers/fields): separate module
Apr 14, 2019
43de22a
refactor(serializers/user): user module
Apr 15, 2019
79cbd75
Merge pull request #7 from jalMogo/jalmogo/refactor-serializers
jalMogo Apr 16, 2019
bd3a869
fix(UserSerializers): make provider_id a protected field
May 24, 2019
a6a30b0
refactor(TestPlaceViews): new module
May 24, 2019
41d92ad
refactor(TestPlaceListView): use setUpTestData
May 24, 2019
9dcba8c
refactor(TestViews): remove unused imports
May 24, 2019
1e2a195
refactor(TestPlaceInstanceView): new module
May 24, 2019
e6ca58f
temp
May 24, 2019
6f5ae40
refactor(TestPlaceListView): rename
May 24, 2019
a594e13
fix(UserSerializer): fix check
May 24, 2019
f8ad9fb
feat(tests): update tests with private user data
May 27, 2019
4ceedf1
Merge pull request #9 from jalMogo/jalmogo/fix-user-serializer-provid…
jalMogo May 27, 2019
e6f39da
feat: add support for JWT authorization (#10)
goldpbear Jul 2, 2019
ff65170
docs(MapseedApiRoot)
Jul 22, 2019
b8939f1
Merge pull request #12 from jalMogo/jalmogo/update-root-view
jalMogo Jul 22, 2019
98efa3f
chore(auth deps)
Jul 23, 2019
2845c4a
Merge pull request #13 from jalMogo/jalmogo/upgrade-auth
jalMogo Jul 23, 2019
1bf8ff3
Revert "chore(auth deps)"
Jul 24, 2019
5b1adbc
Revert "Revert "chore(auth deps)""
Jul 24, 2019
a7da746
fix(UserSerializer): google auths
Jul 24, 2019
8f2af32
cleanup
Jul 24, 2019
e3cfc6d
Merge pull request #14 from jalMogo/jalmogo/upgrade-auth-deps
jalMogo Jul 24, 2019
c5646c9
Revert "Merge pull request #14 from jalMogo/jalmogo/upgrade-auth-deps"
Jul 24, 2019
af97042
Jalmogo/upgrade social auth (#15)
jalMogo Jul 24, 2019
af16626
feat(BaseViews): login logger (#17)
jalMogo Aug 1, 2019
5eb34eb
feat(DiscourseAuthBackend) (#16)
jalMogo Aug 5, 2019
3f8b347
feat(Dataset): implement auth_required (#18)
jalMogo Aug 17, 2019
978227c
Jalmogo/update user serializer (#19)
jalMogo Aug 26, 2019
0f008b7
fix(social-core) (#21)
jalMogo Sep 27, 2019
214ca7c
Fix comment email notifications (#20)
goldpbear Sep 30, 2019
fda912a
Default notification email recipients (#22)
goldpbear Oct 1, 2019
6aee2b5
fix(EmailTemplateMixin): use in operator instead of hasattr (#23)
goldpbear Oct 2, 2019
3fc2256
Jalmogo/add forms (#8)
jalMogo Nov 22, 2019
3097150
Jalmogo/python3 (#24)
jalMogo Dec 6, 2019
b0a9a10
feat(django2.0): WIP
Dec 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/heroku/heroku-buildpack-python.git#v70
https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3
https://github.com/heroku/heroku-buildpack-python.git#v70
58 changes: 58 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
#
version: 2
jobs:
build:
docker:
- image: modulitos/api:release-1.11.2
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
environment:
PASS: test1234
USERNAME: testuser
DB_NAME: test_db
HOST: localhost
PORT: 5432
- image: kartoza/postgis:9.6-2.4
environment:
POSTGRES_PASS: test1234
POSTGRES_USER: testuser
POSTGRES_DBNAME: test_db
ALLOW_IP_RANGE: 0.0.0.0/0
working_directory: /api
steps:
- checkout
# TODO(luke): add this to the container itself:
- run: apt-get install netcat-openbsd
- run:
name: Waiting for Postgres to be ready
command: |
for i in `seq 1 15`;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
- run:
# TODO(luke): handle race condition where postgres is up,
# but DB is not yet ready
name: Waiting for Postgres DB creation
command: |
sleep 5
- run:
name: Run our code formatting tests
command: |
black --check .
- run:
name: Migrate DB
command: |
./src/manage.py migrate
- run:
name: Run our app tests
command: |
./src/manage.py test
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# user-specific
db/*.sqlite3
log/*.log
debug*
.idea
*.sw*
.vscode

# tmp
tmp/
.sass-cache/
profiling/
attachments/
build/

# cover_me generated
coverage
coverage.data
.coverage

# junk
.DS_Store
*~
*flymake.html
*flymake.py

# compiled files
*.py[co]
staticfiles

# environment
env*
.env/
.env

# Local project settings
# src/project/local_settings.py

# IDE project file
.project
*.pydevproject

setup.cfg
notes.org
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.6.8] - 2017-08-24
### Added
- Google OAuth login option
### Changed
- Fix Facebook OAuth login

## [0.6.7] - 2017-03-03
### Added
- Landmarks dataset migration script for 'vision' and 'restoration' datasets
- HTML Sanitizer for use with submitted fields containing raw html, rendered on client

## [0.6.6] - 2017-02-10
### Changed
- Updates for `smartercleanup` -> `mapseed` organization rename

## [0.6.5] - 2016-11-20
### Added
- Add Sentry logging to config
- Add `updateDatasetDevCreds` to Django mgmt commands to conveniently update dev-api creds from db dump.

## [0.6.4] - 2016-11-05
### Added
- Django loginas from upstream
### Changed
- Django 1.7.1 -> 1.7.11

## [0.6.3] - 2016-10-01
### Added
- Added CHANGELOG
### Changed
- Dockerfile updates

## [0.6.2] - 2016-03-06
### Changed
- Dependency updates
- Migration for attachments model

## [0.6.1] - 2016-03-03
### Added
- Dockerfile updates

## [0.6.0] - 2016-03-02

## 0.5.0 - 2015-09-25

[0.6.8]: https://github.com/mapseed/api/compare/0.6.7...0.6.8
[0.6.7]: https://github.com/mapseed/api/compare/0.6.6...0.6.7
[0.6.6]: https://github.com/mapseed/api/compare/0.6.5...0.6.6
[0.6.5]: https://github.com/mapseed/api/compare/0.6.4...0.6.5
[0.6.4]: https://github.com/mapseed/api/compare/0.6.3...0.6.4
[0.6.3]: https://github.com/mapseed/api/compare/0.6.2...0.6.3
[0.6.2]: https://github.com/mapseed/api/compare/0.6.1...0.6.2
[0.6.1]: https://github.com/mapseed/api/compare/0.6.0...0.6.1
[0.6.0]: https://github.com/mapseed/api/compare/0.5.0...0.6.0
73 changes: 73 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Set up private key using multi-stage Dockerfile:
# https://vsupalov.com/build-docker-image-clone-private-repo-ssh-key/

# this is our first build stage, it will not persist in the final image
FROM ubuntu as intermediate

# install git
RUN apt-get update
RUN apt-get install -y git

# add credentials on build
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa
RUN chmod 0600 /root/.ssh/id_rsa

# make sure your domain is accepted
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts

RUN git clone [email protected]:jalMogo/api.git
RUN cd api && git checkout jalmogo/python3


###########################################################
# Dockerfile to build Python WSGI Application Containers
# Based on Debian
############################################################

# Set the base image to Debian
FROM python:3.7.5-stretch

# File Author / Maintainer
MAINTAINER Luke Swart <[email protected]>

# Update the sources list
RUN apt-get update

# Install basic applications
RUN apt-get install -y tar curl wget dialog net-tools build-essential gettext

# Install Python and Basic Python Tools
RUN apt-get install -y python-dev python-distribute python-pip

# Install Postgres/PostGIS dependencies:
RUN apt-get install -y python-psycopg2 postgresql libpq-dev postgresql-9.6-postgis-2.3 postgis postgresql-9.6


# Move the repo from our intermediate image into our final image:
COPY --from=intermediate /api /api

# # for local testing, cd into project root and uncomment this line:
# ADD . api

# Get pip to download and install requirements:
RUN pip install -r /api/requirements.txt

# Expose ports
EXPOSE 8010

# Set the default directory where CMD will execute
WORKDIR /api

RUN mkdir static
VOLUME /api/static

# Set the default command to execute
# when creating a new container
# ex:
# CMD python server.py
# or:
# CMD sh -c "python src/manage.py collectstatic --noinput && gunicorn wsgi:application -w 3 -b 0.0.0.0:8010"
CMD /api/start.sh
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: newrelic-admin run-program gunicorn project.wsgi --pythonpath src --workers $WORKERS --config gunicorn.conf.py
worker: src/manage.py celery worker
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[![Build Status](https://circleci.com/gh/jalmogo/api.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/jalmogo/api.svg?style=shield&circle-token=:circle-token)

Mapseed API
===============

The Mapseed API is the data storage and data management component that
powers the Mapseed web application.
It is a REST API for flexibly storing data about places and an UI for managing
and exporting your data.

## Prereq's

* python 3.7
* virtualenv
* virtualenv can be made with the following command: `mkvirtualenv --python=python3.7 ms-api`
* Docker
* docker-compose


## Installation

### pip install deps

```
pip install -r requirements.txt
```

Note that on MacOS, if you are having error building psycopg2, you may need the following:

```
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
```
https://stackoverflow.com/a/39244687


might also need to run `pip install gitversion` so that our fork of django-closuretree can build. See here:
https://github.com/ocadotechnology/django-closuretree/pull/52 and here:
https://github.com/ocadotechnology/django-closuretree/pull/49

## contributing

We use [Black](https://github.com/psf/black) as our code formatter, along with [isort](https://pypi.org/project/isort/). Editor integration is encouraged.

You can format the entire project in one command with `black .` from the project root. Tests will be check by running `black --check .` from the project root.

*TOOD: consider using pre-commit hook as described [here](https://dev.to/notsag/python-code-formatting-using-black-2fe1) and [here](https://adamj.eu/tech/2019/06/20/all-is-turned-to-black/)*
31 changes: 31 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "Mapseed Data Server",
"description": "A standalone Mapseed data API server.",
"repository": "https://github.com/mapseed",

"scripts": {
"postdeploy": "scripts/postdeploy"
},

"addons": [
"heroku-postgresql:standard-0",
"rediscloud"
],

"env": {
"SHAREABOUTS_AWS_BUCKET": {"required": false, "description": "Where should uploaded attachments go?"},
"SHAREABOUTS_AWS_KEY": {"required": false, "description": ""},
"SHAREABOUTS_AWS_SECRET": {"required": false, "description": ""},
"SHAREABOUTS_FACEBOOK_KEY": {"required": false, "description": ""},
"SHAREABOUTS_FACEBOOK_SECRET": {"required": false, "description": ""},
"SHAREABOUTS_TWITTER_KEY": {"required": false, "description": ""},
"SHAREABOUTS_TWITTER_SECRET": {"required": false, "description": ""},

"BUILDPACK_URL": "https://github.com/ddollar/heroku-buildpack-multi.git",
"WORKERS": "4",
"SECRET_TOKEN": {
"description": "A secret key for verifying the integrity of signed cookies.",
"generator": "secret"
}
}
}
12 changes: 12 additions & 0 deletions dotcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
www:
type: python
config:
python_version: v2.7
systempackages:
- gdal-bin
- libgdal1-dev
db:
type: postgis

cache:
type: redis
6 changes: 6 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Allow all traffic to be forwarded to https
forwarded_allow_ips = "*"
x_forwarded_for_header = "X-FORWARDED-FOR"
secure_scheme_headers = {
"X-FORWARDED-PROTO": "https",
}
4 changes: 4 additions & 0 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# https://forums.docker.com/t/docker-cloud-build-environment-variables-not-being-passed-to-the-auto-build/24010/9

docker build -t $IMAGE_NAME . --build-arg SSH_PRIVATE_KEY="$SSH_PRIVATE_KEY"
Loading