Skip to content

Commit

Permalink
Merge pull request #814 from massenergize/BHN-bugfixes
Browse files Browse the repository at this point in the history
Carbon Calculator bug fixes, and bugs uncovered by unit tests
  • Loading branch information
BradHN1 authored Oct 17, 2023
2 parents 9e3fc77 + 8bfd23e commit 2e2386e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/api/store/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
if community_id and not args.get('is_global', False):
community = Community.objects.get(id=community_id)
new_action.community = community


user_media_upload = None
if images: #now, images will always come as an array of ids
if user_submitted:
name = f'ImageFor {new_action.title} Action'
Expand Down
1 change: 1 addition & 0 deletions src/api/store/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
if community:
new_event.community = community

user_media_upload = None
if image: #now, images will always come as an array of ids
if user_submitted:
name= f'ImageFor {new_event.name} Event'
Expand Down
7 changes: 4 additions & 3 deletions src/api/store/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
if communities:
new_vendor.communities.set(communities)

user_media_upload = None
if images:
if user_submitted:
name=f"ImageFor {new_vendor.name} Vendor"
Expand Down Expand Up @@ -196,11 +197,11 @@ def update_vendor(self, context: Context, args, user_submitted) -> Tuple[dict, M
media = Media.objects.filter(id = image[0]).first()
vendor.logo = media

if vendor.image:
if vendor.logo:
old_image_info, can_save_info = get_media_info(vendor.logo)
if can_save_info:
vendor.image.user_upload.info.update({**old_image_info,**image_info})
vendor.image.user_upload.save()
vendor.logo.user_upload.info.update({**old_image_info,**image_info})
vendor.logo.user_upload.save()


if onboarding_contact_email:
Expand Down
6 changes: 3 additions & 3 deletions src/api/tests/test_mou_reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ def test_send_admin_mou_notification(
# Create an admin who should receive a notification (last notified more than a month ago)
admin1 = UserProfile.objects.create(
full_name="Akwesi",
email="akwesi@me.org",
email="akwesi@massenergize.org",
is_deleted=False,
is_community_admin=True,
)

# Create an admin who should not receive a notification (last notified less than a month ago)
admin2 = UserProfile.objects.create(
full_name="Brad",
email="brad@me.org",
email="brad@massenergize.org",
is_deleted=False,
is_community_admin=True,
)

# Create an admin who should receive a notification (never signed MOU)
admin3 = UserProfile.objects.create(
full_name="Tahiru",
email="tahiru@me.org",
email="tahiru@massenergize.org",
is_deleted=False,
is_community_admin=True,
)
Expand Down
1 change: 0 additions & 1 deletion src/api/tests/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def test_stats(self):
UserActionRel.objects.create(user=self.USER2, action=action2, status="DONE", real_estate_unit=reu, date_completed="2021-09-01")

stats_response = self.client.post('/api/teams.stats', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict()
print(stats_response)
self.assertTrue(stats_response["success"])

self.assertIs(1, len(stats_response['data']))
Expand Down
14 changes: 13 additions & 1 deletion src/carbon_calculator/carbonCalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .foodWaste import EvalLowCarbonDiet, EvalReduceWaste, EvalCompost
from .landscaping import EvalReduceLawnSize, EvalReduceLawnCare, EvalRakeOrElecBlower, EvalElectricMower

CALCULATOR_VERSION = "4.0.2"
CALCULATOR_VERSION = "4.0.3"
QUESTIONS_DATA = BASE_DIR + "/carbon_calculator/content/Questions.csv"
ACTIONS_DATA = BASE_DIR + "/carbon_calculator/content/Actions.csv"
DEFAULTS_DATA = BASE_DIR + "/carbon_calculator/content/defaults.csv"
Expand Down Expand Up @@ -417,6 +417,18 @@ def __init__(self,name):
self.text = "" # "Explanation for the calculated results."
self.picture = ""

status, actionInfo = QuerySingleAction(self.name)
if status == VALID_QUERY:
self.id = actionInfo["id"]
self.title = actionInfo["title"]
self.description = actionInfo["description"]
self.helptext = actionInfo["helptext"]
self.questions = actionInfo["questionInfo"] # question with list of valid responses.
self.average_points = actionInfo["average_points"]
self.picture = actionInfo["picture"]
self.initialized = True


def Query(self):
status, actionInfo = QuerySingleAction(self.name)
if not self.id and status == VALID_QUERY:
Expand Down
9 changes: 5 additions & 4 deletions src/carbon_calculator/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def QuerySingleAction(name,event_tag=""):

questionInfo = []
for question in q.questions:
qq = CalculatorQuestion(question, event_tag)
# a question with no text is not to be included; this is how depending on the event_tag some questions would not be asked.
if len(qq.questionText)>0:
questionInfo.append(jsons.dump(qq))
if question != '':
qq = CalculatorQuestion(question, event_tag)
# a question with no text is not to be included; this is how depending on the event_tag some questions would not be asked.
if len(qq.questionText)>0:
questionInfo.append(jsons.dump(qq))

picture = ""
if q.picture:
Expand Down

0 comments on commit 2e2386e

Please sign in to comment.