Skip to content
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

Django upgrade #443

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
26 changes: 0 additions & 26 deletions Dockerfile-ARM

This file was deleted.

57 changes: 40 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,52 @@ These instructions will get you a copy of the project up and running on your loc

First, clone the repository:

$ git clone https://github.com/uw-it-aca/scout.git

```bash
git clone https://github.com/uw-it-aca/scout.git
```

If you wish to change the default settings, navigate to the repository and copy the sample environment variables into your own `.env` file:

```
```bash
cd scout
cp sample.env .env
```

Optionally, add custom 404 response to `docker/urls.py`:
## Development

### Setting up the correct environment variables

Settings `RESTCLIENTS_SPOTSEEKER_DAO_CLASS` to `Mock` will allow you to run the app without connecting to a live Spotseeker server. This is useful for testing and development. However, if you want to properly test the app against a live Spotseeker server, you will need to set up the following environment variables:

```bash
RESTCLIENTS_SPOTSEEKER_DAO_CLASS=Live
RESTCLIENTS_SPOTSEEKER_HOST=[your spotseeker server url]

SPOTSEEKER_OAUTH_CREDENTIAL=[your spotseeker server oauth credential]
```
handler404 = 'scout.views.custom_404_response'

You must go to your live spotseeker server instance to get the oauth credential. In spotseeker server, run the following command:

```bash
docker exec -ti spotseeker-server bin/python manage.py register_application [-s/--show-credential]
```

## Development
You will be prompted for an app name. The default name for this app is `scout`. You can change this name by setting the `APP_NAME` environment variable. The command will give you a credential. Copy and paste this credential into the `SPOTSEEKER_OAUTH_CREDENTIAL` environment variable and you should be good to go.

It is recommended that you keep the scope to read only as that is what scout is designed for.

### Running the App with Docker

Run the following command to build your docker container:

```
```bash
docker-compose up --build
```

### Running Unit Tests with Docker

```
docker-compose run --rm app bin/python manage.py test
```bash
docker exec -ti scout bin/python manage.py test
```

### Running the app against a Live Spotseeker Server ###
Expand Down Expand Up @@ -82,7 +98,7 @@ See also the list of [contributors](https://github.com/uw-it-aca/scout/contribut

## License

Copyright 2012-2016 UW Information Technology, University of Washington
Copyright 2012-2023 UW Information Technology, University of Washington

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -98,18 +114,25 @@ limitations under the License.

## List of settings

(To be moved to the wiki eventually.)

CAMPUS_URL_LIST

GOOGLE_ANALYTICS_KEY

GOOGLE_MAPS_API

COMPRESS_ENABLED

OAUTH_USER

SCOUT_SHOW_ALT_TECH

DEBUG_CACHING
- If set to True, will use a real cache even while in DEBUG=True. This is useful for testing.

RESTCLIENTS_SPOTSEEKER_DAO_CLASS

RESTCLIENTS_SPOTSEEKER_HOST = ''
RESTCLIENTS_SPOTSEEKER_HOST

SPOTSEEKER_OAUTH_CREDENTIAL

SPOTSEEKER_OAUTH_KEY = ''
SPOTSEEKER_OAUTH_SCOPE

SPOTSEEKER_OAUTH_SECRET = ''
APP_NAME
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ services:
container_name: scout
build:
context: .
dockerfile: ${DOCKERFILE:-Dockerfile}
target: app-container
volumes:
- ./scout:/app/scout
ports:
- "${PORT:-8000}:8000"
environment:
ENV: localdev
APP_NAME: ${APP_NAME:-"scout"}
SCOUT_SHOW_NEWSSPLASH: ${SCOUT_SHOW_NEWSSPLASH:-False}
RESTCLIENTS_SPOTSEEKER_HOST: ${RESTCLIENTS_SPOTSEEKER_HOST:-""}
SPOTSEEKER_OAUTH_KEY: ${SPOTSEEKER_OAUTH_KEY:-""}
SPOTSEEKER_OAUTH_SECRET: ${SPOTSEEKER_OAUTH_SECRET:-""}
SPOTSEEKER_OAUTH_CREDENTIAL: ${SPOTSEEKER_OAUTH_CREDENTIAL:-""}
SCOPE: ${SCOPE:-read}
DEBUG_CACHING: ${DEBUG_CACHING:-True}
RESTCLIENTS_SPOTSEEKER_DAO_CLASS: ${RESTCLIENTS_SPOTSEEKER_DAO_CLASS:-Mock}
OAUTH_USER: ${OAUTH_USER:-javerage}
SCOUT_SHOW_ALT_TECH: ${SCOUT_SHOW_ALT_TECH:-False}
COMPRESS_ENABLED: ${COMPRESS_ENABLED:-True}


12 changes: 5 additions & 7 deletions docker/prod-values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ environmentVariables:
value: 'False'
- name: SCOUT_SHOW_ALT_TECH
value: 'False'
- name: SPOTSEEKER_OAUTH_SCOPE
value: read
externalSecrets:
enabled: true
secrets:
Expand Down Expand Up @@ -108,11 +110,7 @@ environmentVariablesSecrets:
name: GOOGLE_MAPS_API
secretName: prod.scout.uw.edu-secrets
secretKey: google-maps-api-key
spotseekerOauthKey:
name: SPOTSEEKER_OAUTH_KEY
spotseekerOauthCredential:
name: SPOTSEEKER_OAUTH_CREDENTIAL
secretName: prod.scout.uw.edu-secrets
secretKey: spotseeker-oauth-key
spotseekerOauthSecret:
name: SPOTSEEKER_OAUTH_SECRET
secretName: prod.scout.uw.edu-secrets
secretKey: spotseeker-oauth-secret
secretKey: spotseeker-oauth-credential
22 changes: 20 additions & 2 deletions docker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"hybridize",
]

APP_NAME = os.getenv("APP_NAME", "scout")

MIDDLEWARE += ["django_user_agents.middleware.UserAgentMiddleware"]

COMPRESS_ROOT = "/static/"
Expand Down Expand Up @@ -51,10 +53,26 @@
CAMPUS_URL_LIST = ["seattle", "tacoma", "bothell"]
SCOUT_SHOW_NEWSSPLASH = os.getenv("SCOUT_SHOW_NEWSSPLASH") == "True"
RESTCLIENTS_SPOTSEEKER_HOST = os.getenv("RESTCLIENTS_SPOTSEEKER_HOST", "")
SPOTSEEKER_OAUTH_KEY = os.getenv("SPOTSEEKER_OAUTH_KEY", "")
SPOTSEEKER_OAUTH_SECRET = os.getenv("SPOTSEEKER_OAUTH_SECRET", "")
SPOTSEEKER_OAUTH_CREDENTIAL = os.getenv("SPOTSEEKER_OAUTH_CREDENTIAL", "")
SPOTSEEKER_OAUTH_SCOPE = os.getenv("SPOTSEEKER_OAUTH_SCOPE", "read")
RESTCLIENTS_SPOTSEEKER_DAO_CLASS = os.getenv(
"RESTCLIENTS_SPOTSEEKER_DAO_CLASS", "Mock"
)
OAUTH_USER = os.getenv("OAUTH_USER", "javerage")
SCOUT_SHOW_ALT_TECH = os.getenv("SCOUT_SHOW_ALT_TECH") == "True"

DEBUG_CACHING = os.getenv("DEBUG_CACHING", "True") == "True"

if DEBUG and not DEBUG_CACHING:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
}
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'scout',
}
}
12 changes: 5 additions & 7 deletions docker/test-values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ environmentVariables:
value: 'False'
- name: SCOUT_SHOW_ALT_TECH
value: 'False'
- name: SPOTSEEKER_OAUTH_SCOPE
value: read
externalSecrets:
enabled: true
secrets:
Expand Down Expand Up @@ -98,11 +100,7 @@ environmentVariablesSecrets:
name: GOOGLE_MAPS_API
secretName: test.scout.uw.edu-secrets
secretKey: google-maps-api-key
spotseekerOauthKey:
name: SPOTSEEKER_OAUTH_KEY
spotseekerOauthCredential:
name: SPOTSEEKER_OAUTH_CREDENTIAL
secretName: test.scout.uw.edu-secrets
secretKey: spotseeker-oauth-key
spotseekerOauthSecret:
name: SPOTSEEKER_OAUTH_SECRET
secretName: test.scout.uw.edu-secrets
secretKey: spotseeker-oauth-secret
secretKey: spotseeker-oauth-credential
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-e git+https://github.com/uw-it-aca/uw-restclients-spotseeker.git#egg=uw_restclients_spotseeker
-e git+https://github.com/uw-it-aca/uw-restclients-spotseeker.git@v2.0#egg=uw_restclients_spotseeker
-e git+https://github.com/uw-it-aca/django-hybridize/#egg=hybridize
-e .
13 changes: 4 additions & 9 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
#RESTCLIENTS_SPOTSEEKER_HOST=http://yourdns.edu:8001
#RESTCLIENTS_SPOTSEEKER_DAO_CLASS=Live

# Spotseeker oath variables
# Generate these with: ./manage.py create_consumer or
# docker exec -it bin/python manage.py create_consumer
#SPOTSEEKER_OAUTH_KEY=tempkey
#SPOTSEEKER_OAUTH_SECRET=tempsecret

# Alternate Dockerfile for ARM-based Macs
#DOCKERFILE=DOCKERFILE-ARM
# Spotseeker oauth variables
SPOTSEEKER_OAUTH_CREDENTIAL=credential
SPOTSEEKER_OAUTH_SCOPE=read

# Show alternate tech tab content
#SCOUT_SHOW_ALT_TECH=True

# Disable compressing CSS and JS files
#COMPRESS_ENABLED=False
#COMPRESS_ENABLED=False
2 changes: 1 addition & 1 deletion scout/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.conf import settings
Expand Down
2 changes: 1 addition & 1 deletion scout/dao/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from uw_spotseeker import Spotseeker
Expand Down
2 changes: 1 addition & 1 deletion scout/dao/item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from scout.dao.space import get_spots_by_filter, _get_spot_filters, \
Expand Down
5 changes: 3 additions & 2 deletions scout/dao/space.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.conf import settings
from uw_spotseeker import Spotseeker
from uw_spotseeker.models import Spot
from restclients_core.exceptions import DataFailureException
import datetime
import pytz
Expand Down Expand Up @@ -442,7 +443,7 @@ def _get_names_for_extended_info(prefix, mapping, info):
return names


def add_payment_names(spot):
def add_payment_names(spot) -> Spot:
PAYMENT_PREFIX = "s_pay"
PAYMENT_MAPPING = {
"s_pay_cash": "Cash",
Expand Down
2 changes: 1 addition & 1 deletion scout/templatetags/scout_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django import template
Expand Down
2 changes: 1 addition & 1 deletion scout/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.test import TestCase
Expand Down
2 changes: 1 addition & 1 deletion scout/test/dao/test_item_dao.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import copy
Expand Down
2 changes: 1 addition & 1 deletion scout/test/dao/test_space_dao.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import datetime
Expand Down
2 changes: 1 addition & 1 deletion scout/test/pageflow/test_content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion scout/test/pageflow/test_navigation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion scout/test/pageflow/test_page_load_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down
2 changes: 1 addition & 1 deletion scout/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.conf import settings
Expand Down
2 changes: 1 addition & 1 deletion scout/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.http import Http404, HttpResponse
Expand Down
2 changes: 1 addition & 1 deletion scout/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 UW-IT, University of Washington
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

import os
Expand Down
Loading