Skip to content
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ celery-remote:
celery -A _main_.celery.app worker -l info

full-celery-local:
make -j 2 start celery
DJANGO_ENV="local" make -j 2 start celery
.PHONY: full-celery-local

beat-remote:
Expand Down
1 change: 0 additions & 1 deletion src/_main_/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os
import firebase_admin
from firebase_admin import credentials
from dotenv import load_dotenv
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
Expand Down
2 changes: 1 addition & 1 deletion src/api/handlers/deviceprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def platform_metrics(self, request):

if metric:
if metric == "anonymous_users":
metric, err = self.service.metric_anonymous_users(context, args)
metric, err = self.service.metric_anonymous_users()

elif community_id and metric == "anonymous_community_users":
metric, err = self.service.metric_anonymous_community_users(community_id)
Expand Down
9 changes: 0 additions & 9 deletions src/api/handlers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def registerRoutes(self) -> None:
self.add("/menus.remake", self.remake_navigation_menu)
self.add("/menus.list", self.navigation_menu_list)
self.add("/user.portal.menu.list", self.load_menu_items)
self.add("/data.backfill", self.backfill)
self.add("/data.carbonEquivalency.create", self.create_carbon_equivalency)
self.add("/data.carbonEquivalency.update", self.update_carbon_equivalency)
self.add("/data.carbonEquivalency.get", self.get_carbon_equivalencies)
Expand Down Expand Up @@ -81,14 +80,6 @@ def navigation_menu_list(self, request):
return err
return MassenergizeResponse(data=goal_info)

def backfill(self, request):
context: Context = request.context
args: dict = context.args
goal_info, err = self.service.backfill(context, args)
if err:
return err
return MassenergizeResponse(data=goal_info)

def actions_report(self, request):
context: Context = request.context
args: dict = context.args
Expand Down
4 changes: 0 additions & 4 deletions src/api/handlers/userprofile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
"""Handler file for all routes pertaining to users"""
from functools import wraps
from _main_.utils import context
from _main_.utils.route_handler import RouteHandler
from api.services.userprofile import UserService
from _main_.utils.massenergize_response import MassenergizeResponse
from _main_.utils.massenergize_errors import NotAuthorizedError
from _main_.utils.context import Context
from api.decorators import admins_only, super_admins_only, login_required
from api.store.common import create_pdf_from_rich_text
from database.models import Policy


class UserHandler(RouteHandler):
Expand Down
6 changes: 2 additions & 4 deletions src/api/services/deviceprofile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from _main_.utils.massenergize_errors import CustomMassenergizeError, MassEnergizeAPIError
from _main_.utils.common import serialize, serialize_all
from _main_.utils.massenergize_errors import MassEnergizeAPIError
from _main_.utils.common import serialize
from api.store.deviceprofile import DeviceStore
from _main_.utils.context import Context
from _main_.utils.massenergize_logger import log
from typing import Tuple

class DeviceService:
Expand Down
5 changes: 0 additions & 5 deletions src/api/services/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def navigation_menu_list(
return None, err
return serialize_all(main_menu_items), None

def backfill(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIError]:
result, err = self.store.backfill(context, args)
if err:
return None, err
return result, None
def actions_report(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIError]:
result, err = self.store.actions_report(context, args)
if err:
Expand Down
1 change: 0 additions & 1 deletion src/api/services/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from _main_.utils.pagination import paginate
from api.store.team import TeamStore
from api.store.message import MessageStore
from api.utils.api_utils import get_sender_email
from api.utils.filter_functions import sort_items
from database.models import TeamMember
from _main_.utils.context import Context
Expand Down
7 changes: 0 additions & 7 deletions src/api/services/technology.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ def list_technology_vendors(self, context: Context, args) -> Tuple[list, MassEn
return serialize_all(res), None


def list_technologies_for_admin(self, context: Context, args) -> Tuple[list, MassEnergizeAPIError]:
technologies, err = self.store.list_technologies_for_admin(context, args)
if err:
return None, err
return serialize_all(technologies), None


def create_technology_deal(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIError]:
res, err = self.store.create_technology_deal(context, args)
if err:
Expand Down
1 change: 0 additions & 1 deletion src/api/services/userprofile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from _main_.utils.massenergize_errors import CustomMassenergizeError, MassEnergizeAPIError
from _main_.utils.common import serialize, serialize_all
from _main_.utils.pagination import paginate
from api.decorators import login_required
from api.store.userprofile import UserStore
from _main_.utils.context import Context
from _main_.utils.emailer.send_email import send_massenergize_rich_email
Expand Down
2 changes: 1 addition & 1 deletion src/api/store/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _main_.utils.utils import is_not_null
from api.utils.api_utils import is_admin_of_community
from api.utils.filter_functions import get_super_admins_filter_params
from database.models import UserProfile, CommunityAdminGroup, Media, UserProfile, Message
from database.models import UserProfile, CommunityAdminGroup, Media, Message
from _main_.utils.massenergize_errors import MassEnergizeAPIError, CustomMassenergizeError, NotAuthorizedError
from _main_.utils.context import Context
from .utils import get_community, get_user, get_community_or_die, unique_media_filename
Expand Down
6 changes: 3 additions & 3 deletions src/api/store/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from _main_.settings import AWS_S3_REGION_NAME
from _main_.utils.common import custom_timezone_info, serialize, serialize_all
from api.constants import CSV_FIELD_NAMES
from api.store.utils import getCarbonScoreFromActionRel
from carbon_calculator.models import Action
from database.utils.common import calculate_hash_for_bucket_item
from database.models import Community, CommunityAdminGroup, Event, Media, Team, UserActionRel
from database.utils.common import calculate_hash_for_bucket_item, get_image_size_from_bucket
from carbon_calculator.carbonCalculator import getCarbonImpact

s3 = boto3.client("s3", region_name=AWS_S3_REGION_NAME)

Expand Down Expand Up @@ -104,7 +104,7 @@ def count_action_completed_and_todos(**kwargs):
for completed_action in completed_actions:
action_id = completed_action.action.id
action_name = completed_action.action.title
action_carbon = getCarbonScoreFromActionRel(completed_action)
action_carbon = getCarbonImpact(completed_action)
done = 1 if completed_action.status == "DONE" else 0
todo = 1 if completed_action.status == "TODO" else 0

Expand Down
98 changes: 23 additions & 75 deletions src/api/store/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,21 @@ def _update_locations(self, geography_type, locations, community):
zipcode = zipcodes.matching(location)
if len(zipcode) > 0:
city = zipcode[0].get("city", None)
county = zipcode[0].get("county", None)
state = zipcode[0].get("state", None)
else:
raise Exception("No zip code entry found for zip=" + location)

# get_or_create gives an error if multiple such locations exist (which can happen)
# loc, created = Location.objects.get_or_create(location_type='ZIP_CODE_ONLY', zipcode=location, city=city)
loc = Location.objects.filter(
location_type="ZIP_CODE_ONLY", zipcode=location, city=city
location_type="FULL_ADDRESS", zipcode=location, city=city, county=county, state=state
)
if not loc:
loc = Location.objects.create(
location_type="ZIP_CODE_ONLY", zipcode=location, city=city
location_type="FULL_ADDRESS", zipcode=location, city=city, county=county, state=state
)
print("Zipcode " + location + " created for town " + city)
else:
loc = loc.first()
print("Zipcode " + location + " found for town " + city)

self._check_geography_unique(community, geography_type, location)

else:
Expand All @@ -260,47 +258,28 @@ def _update_locations(self, geography_type, locations, community):
zips = zipcodes.filter_by(
city=town, state=state, zip_code_type="STANDARD"
)
print("Number of zipcodes = " + str(len(zips)))
if len(zips) > 0:
for zip in zips:
print(zip)
zipcode = zip["zip_code"]
zipcode = zip.get("zip_code")
county = zip.get("county")

# get_or_create gives an error if multiple such locations exist (which can happen)
# loc, created = Location.objects.get_or_create(location_type='ZIP_CODE_ONLY', zipcode=location, city=city)
loc = Location.objects.filter(
location_type="ZIP_CODE_ONLY",
zipcode=location,
city=town,
location_type="FULL_ADDRESS", zipcode=zipcode, city=town, county=county, state=state
)
if not loc:
loc = Location.objects.create(
location_type="ZIP_CODE_ONLY",
zipcode=location,
city=town,
location_type="FULL_ADDRESS", zipcode=location, city=city, county=county, state=state
)
print("Zipcode " + zipcode + " created")
else:
loc = loc.first()
print("Zipcode " + zipcode + " found")

self._check_geography_unique(
community, geography_type, zipcode
)
self._check_geography_unique(community, geography_type, zipcode)

else:
print(
"No zipcodes found corresponding to town "
+ town
+ ", "
+ state
)
raise Exception(
"No zipcodes found corresponding to city "
+ town
+ ", "
+ state
)
msg = "No zipcodes found corresponding to town " + town + ", " + state
raise Exception(msg)

elif geography_type == "CITY":
# check that this city is found in the zipcodes list
ss = location.split("-")
Expand All @@ -313,29 +292,21 @@ def _update_locations(self, geography_type, locations, community):
zips = zipcodes.filter_by(
city=city, state=state, zip_code_type="STANDARD"
)
print("Number of zipcodes = " + str(len(zips)))
if len(zips) > 0:
# get_or_create gives an error if multiple such locations exist (which can happen)
# loc, created = Location.objects.get_or_create(location_type='ZIP_CODE_ONLY', zipcode=location, city=city)
county = zips[0].get("county")
loc = Location.objects.filter(
location_type="CITY_ONLY", city=city, state=state
location_type="FULL_ADDRESS", zipcode=location, city=city, county=county, state=state
)
if not loc:
loc = Location.objects.create(
location_type="CITY_ONLY", city=city, state=state
location_type="FULL_ADDRESS", zipcode=location, city=city, county=county, state=state
)
print("City " + city + " created")
else:
loc = loc.first()
print("City " + city + " found")

else:
print(
"No zipcodes found corresponding to city " + city + ", " + state
)
raise Exception(
"No zipcodes found corresponding to city " + city + ", " + state
)
msg = "No zipcodes found corresponding to city " + city + ", " + state
raise Exception(msg)

self._check_geography_unique(community, geography_type, city)
elif geography_type == "COUNTY":
Expand All @@ -350,35 +321,21 @@ def _update_locations(self, geography_type, locations, community):
zips = zipcodes.filter_by(
county=county, state=state, zip_code_type="STANDARD"
)
print("Number of zipcodes = " + str(len(zips)))
if len(zips) > 0:
# get_or_create gives an error if multiple such locations exist (which can happen)
# loc, created = Location.objects.get_or_create(location_type='ZIP_CODE_ONLY', zipcode=location, city=city)
loc = Location.objects.filter(
location_type="COUNTY_ONLY", county=county, state=state
)
if not loc:
loc = Location.objects.create(
location_type="COUNTY_ONLY", county=county, state=state
)
print("County " + county + " created")
else:
loc = loc.first()
print("County " + county + " found")

else:
print(
"No zipcodes found corresponding to county "
+ county
+ ", "
+ state
)
raise Exception(
"No zipcodes found corresponding to county "
+ county
+ ", "
+ state
)
msg = "No zipcodes found corresponding to county " + county + ", " + state
raise Exception(msg)

self._check_geography_unique(community, geography_type, county)

Expand All @@ -397,23 +354,18 @@ def _update_locations(self, geography_type, locations, community):
loc = Location.objects.create(
location_type="STATE_ONLY", state=state
)
print("State " + state + " created")
else:
loc = loc.first()
print("State " + state + " found")
else:
print("No zipcodes found corresponding to state " + location)
raise Exception(
"No zipcodes found corresponding to state " + location
)
msg = "No zipcodes found corresponding to state " + location
raise Exception(msg)

self._check_geography_unique(community, geography_type, location)

elif geography_type == "COUNTRY":
# check that this state is found in the zipcodes list
country = location
zips = zipcodes.filter_by(country=country, zip_code_type="STANDARD")
print("Number of zipcodes = " + str(len(zips)))
if len(zips) > 0:
# get_or_create gives an error if multiple such locations exist (which can happen)
# loc, created = Location.objects.get_or_create(location_type='ZIP_CODE_ONLY', zipcode=location, city=city)
Expand All @@ -424,15 +376,11 @@ def _update_locations(self, geography_type, locations, community):
loc = Location.objects.create(
location_type="COUNTRY_ONLY", country=country
)
print("Country " + country + " created")
else:
loc = loc.first()
print("Country " + country + " found")
else:
print("No zipcodes found corresponding to country " + location)
raise Exception(
"No zipcodes found corresponding to country " + location
)
msg = "No zipcodes found corresponding to country " + location
raise Exception(msg)

self._check_geography_unique(community, geography_type, location)

Expand Down
1 change: 0 additions & 1 deletion src/api/store/deviceprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from database.models import UserProfile, DeviceProfile, Location, Community
from _main_.utils.massenergize_errors import MassEnergizeAPIError, InvalidResourceError, CustomMassenergizeError
from _main_.utils.context import Context
from _main_.settings import DEBUG
from _main_.utils.massenergize_logger import log
from typing import Tuple

Expand Down
Loading