Skip to content

Commit

Permalink
Merge pull request #512 from countable-web/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jrcarretas authored Jun 26, 2024
2 parents c969936 + 8ee6917 commit 57d43fe
Show file tree
Hide file tree
Showing 55 changed files with 974 additions and 811 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ docker-compose exec web python manage.py test

```
## Linting
### Python
We use pylint to detect linting errors in Python. Disclaimer: pylint is only used to detect errors an does not automatically fix them. Linting fixes have to be manually applied by the developer.
```
# Linting for entire folder
docker-compose exec web sh pylint.sh <folder_name>

# Linting for specific file
docker-compose exec web sh pylint.sh <folder_name>/<file_name>/
```
### Notifications
The system sends users notifications weekly, including:
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
- back-tier
working_dir: /code/
command: ./command.sh
environment:
- MAPBOX_ACCESS_TOKEN=pk.eyJ1IjoiZnBjYyIsImEiOiJjbHJ6Y2RrZ2kxa3NlMndsemNqbTMwajk3In0.Ptmj4UY9iIzIO3UVPpaOUg
- MAPBOX_STYLE_URL=mapbox://styles/fpcc/cls0kyxqh00b301pvb06p0r07/?optimize=true

test:
image: alekzonder/puppeteer:latest
Expand Down
3 changes: 1 addition & 2 deletions frontend/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ export default {
},
data() {
return {
MAPBOX_ACCESS_TOKEN:
'pk.eyJ1IjoiY291bnRhYmxlLXdlYiIsImEiOiJjamQyZG90dzAxcmxmMndtdzBuY3Ywa2ViIn0.MU-sGTVDS9aGzgdJJ3EwHA',
MAPBOX_ACCESS_TOKEN: process.env.MAPBOX_ACCESS_TOKEN,
show: false,
searchQuery: '',
searchResultClicked: false,
Expand Down
2 changes: 2 additions & 0 deletions frontend/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module.exports = {
COGNITO_APP_CLIENT_ID: process.env.COGNITO_APP_CLIENT_ID,
COGNITO_URL: process.env.COGNITO_URL,
COGNITO_HOST: process.env.COGNITO_HOST,
MAPBOX_ACCESS_TOKEN: process.env.MAPBOX_ACCESS_TOKEN,
MAPBOX_STYLE_URL: process.env.MAPBOX_STYLE_URL,
HOST: process.env.HOST
},

Expand Down
6 changes: 2 additions & 4 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,9 @@ export default {
loggingIn: false,
showSearchOverlay: false,
showEventOverlay: false,
MAPBOX_ACCESS_TOKEN:
'pk.eyJ1IjoiY291bnRhYmxlLXdlYiIsImEiOiJjamQyZG90dzAxcmxmMndtdzBuY3Ywa2ViIn0.MU-sGTVDS9aGzgdJJ3EwHA',
MAPBOX_ACCESS_TOKEN: process.env.MAPBOX_ACCESS_TOKEN,
MAP_OPTIONS: {
style:
'mapbox://styles/countable-web/ck9osxbys0rr71io228y2zonf/draft?optimize=true',
style: process.env.MAPBOX_STYLE_URL,
maxZoom: 19,
minZoom: 3,
bounds
Expand Down
3 changes: 2 additions & 1 deletion web/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ignore-patterns=

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"


# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use.
Expand Down
2 changes: 1 addition & 1 deletion web/grants/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from .models import Grant, GrantCategory
from grants.models import Grant, GrantCategory


class GrantAdmin(admin.ModelAdmin):
Expand Down
2 changes: 1 addition & 1 deletion web/grants/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class GrantsConfig(AppConfig):
name = 'grants'
name = "grants"
Empty file.
37 changes: 19 additions & 18 deletions web/grants/management/commands/geocode_grants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import requests

from django.core.management.base import BaseCommand
Expand All @@ -9,6 +8,7 @@

class Command(BaseCommand):
help = "Load grants from old arts database."

def add_arguments(self, parser):
parser.add_argument("--starting_id", type=int)
parser.add_argument("--GOOGLE_API_KEY", type=str)
Expand All @@ -23,11 +23,11 @@ def geocode_grants(starting_id, google_api_key):
grants = Grant.objects.filter(id__gte=starting_id).order_by("id")

if not google_api_key:
return print('NO GOOGLE API KEY')
return print("NO GOOGLE API KEY")

for grant in grants:
full_address = []

if grant.address:
full_address.append(grant.address)
if grant.city:
Expand All @@ -36,32 +36,33 @@ def geocode_grants(starting_id, google_api_key):
full_address.append(grant.province)
if grant.postal_code:
full_address.append(grant.postal_code)

full_address_string = ', '.join(full_address).replace('#', '').replace('&', ' ')

r = requests.get(f"https://maps.googleapis.com/maps/api/geocode/json?address={full_address_string}&sensor=false&key={google_api_key}")

full_address_string = ", ".join(full_address).replace("#", "").replace("&", " ")

google_api_base_url = "https://maps.googleapis.com/maps/api/geocode/json/"
url = "{google_api_base_url}?address={address}&sensor=false&key={google_api_key}".format(
google_api_base_url=google_api_base_url,
address=full_address_string,
google_api_key=google_api_key,
)
r = requests.get(url)

data = r.json()
response_status = data.get("status")
results = data.get("results")
if response_status == "OK" and results:
first_result = results[0]

location = first_result.get("geometry").get("location")
if location is not None and \
location.get("lat") and \
location.get("lng"):
point = Point(
float(location.get("lng")),
float(location.get("lat"))
)
print(f'SAVING POINT -- {full_address_string}')
if location is not None and location.get("lat") and location.get("lng"):
point = Point(float(location.get("lng")), float(location.get("lat")))
print(f"SAVING POINT -- {full_address_string}")
grant.point = point
else:
print(f'--REMOVING POINT -- {full_address_string}')
print(f"--REMOVING POINT -- {full_address_string}")
grant.point = None
else:
print(f'--REMOVING POINT -- {full_address_string}')
print(f"--REMOVING POINT -- {full_address_string}")
grant.point = None

grant.save()
5 changes: 3 additions & 2 deletions web/grants/management/commands/import_amount_province.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Command(BaseCommand):
def handle(self, *args, **options):
import_amount_and_province()


def import_amount_and_province():
with open('./tmp/spreadsheets/amount_province.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
with open("./tmp/spreadsheets/amount_province.csv", encoding="utf-8") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")

for row in csv_reader:
grant = Grant.objects.get(pk=row[0])
Expand Down
39 changes: 1 addition & 38 deletions web/grants/management/commands/load_grants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pandas as pd

from django.core.management.base import BaseCommand

from grants.models import Grant, GrantCategory
from grants.utils import load_grants_from_spreadsheet


class Command(BaseCommand):
Expand All @@ -12,38 +10,3 @@ def handle(self, *args, **options):
def add_arguments(self, parser):
parser.add_argument("--file_name", type=str)
parser.add_argument("--test", type=bool)


def load_grants_from_spreadsheet(file_name, test=False):
# Convert excel into dataframe
grants_dataframe = pd.read_excel(file_name, sheet_name=0)

# Replace NaN values with empty string
grants_dataframe.fillna("", inplace=True)

for index, sheet_row in grants_dataframe.iterrows():
category_abbreviation = sheet_row["Grant"].strip().split(" ")[0]

grant_category = GrantCategory.objects.get(abbreviation=category_abbreviation)

if test:
print(sheet_row["Grant"])
continue
else:
print("Saving ", sheet_row["Grant"])

Grant.objects.create(
grant=sheet_row["Grant"],
language=sheet_row["Language"],
year=int(sheet_row["Year"]) if sheet_row["Year"] else None,
recipient=sheet_row["Recipient"],
community_affiliation=sheet_row["Community/Affiliation"],
title=sheet_row["Title"],
project_brief=sheet_row["Project Brief"],
amount=sheet_row["Amount"],
address=sheet_row["Address"],
city=sheet_row["City"],
province=sheet_row["Province"],
postal_code=sheet_row["Postal Code"],
grant_category=grant_category,
)
Loading

0 comments on commit 57d43fe

Please sign in to comment.