Skip to content

Commit

Permalink
Merge pull request #113 from massenergize/April-Sprint2-Part2
Browse files Browse the repository at this point in the history
Removing prints, fixing messages to team admins
  • Loading branch information
Opoku-Agyemang authored Apr 22, 2020
2 parents 0a6ac41 + 675e1c1 commit 8565b13
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 53 deletions.
5 changes: 2 additions & 3 deletions src/_main_/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('EMAIL')
DEFAULT_FROM_EMAIL = os.environ.get('EMAIL')
EMAIL_HOST_USER = os.environ.get('EMAIL')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD')


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

Expand Down
2 changes: 1 addition & 1 deletion src/api/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def delete_message_view(request) -> None:
def team_admin_list(self) -> function:
def team_admin_list_view(request) -> None:
context: Context = request.context
messages, err = self.service.list_team_admin_messages_for_community_admin(context, args)
messages, err = self.service.list_team_admin_messages_for_community_admin(context)
if err:
return MassenergizeResponse(error=str(err), status=err.status)
return MassenergizeResponse(data=messages)
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def list_community_admin_messages_for_community_admin(self, context: Context, ar
return serialize_all(messages), None


def list_team_admin_messages_for_community_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
messages, err = self.store.list_team_admin_messages(context, args)
def list_team_admin_messages_for_community_admin(self, context: Context) -> (list, MassEnergizeAPIError):
messages, err = self.store.list_team_admin_messages(context)
if err:
return None, err
return serialize_all(messages), None
2 changes: 0 additions & 2 deletions src/api/store/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def remove_super_admin(self, context: Context, args) -> (UserProfile, MassEnergi

user.is_super_admin = False
user.save()
print(user)
return user, None

except Exception as e:
Expand Down Expand Up @@ -267,7 +266,6 @@ def list_admin_messages(self, context: Context, args) -> (list, MassEnergizeAPIE
subdomain = args.pop('subdomain', None)
community, err = get_community(community_id, subdomain)
if err:
print(err)
return None, err

if not community and context.user_id:
Expand Down
1 change: 0 additions & 1 deletion src/api/store/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def leave_community(self, context: Context, args) -> (dict, MassEnergizeAPIError

community_member: CommunityMember = CommunityMember.objects.filter(community=community, user=user).first()
if not community_member or (not community_member.is_admin):
print(community_member)
community_member.delete()

context.logger.log({
Expand Down
2 changes: 0 additions & 2 deletions src/api/store/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def delete_goal(self, goal_id) -> (Goal, MassEnergizeAPIError):
try:
#find the goal
goals_to_delete = Goal.objects.filter(id=goal_id)
print(goal_id, goals_to_delete)
# goals_to_delete.delete()
goals_to_delete.update(is_deleted=True)
if not goals_to_delete:
Expand Down Expand Up @@ -188,7 +187,6 @@ def list_goals_for_community_admin(self, context, community_id) -> (list, MassEn
def list_goals_for_super_admin(self):
try:
goals = Goal.objects.filter(is_deleted=False)
print(len(goals))
return goals, None
except Exception as e:
return None, CustomMassenergizeError(str(e))
Expand Down
1 change: 0 additions & 1 deletion src/api/store/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def update_graph(self, context:Context, args:dict) -> (dict, MassEnergizeAPIErro
if data_id.isnumeric() and v.isnumeric():
data = Data.objects.filter(pk=data_id).first()
if data:
print(data)
data.reported_value = v
data.save()

Expand Down
37 changes: 10 additions & 27 deletions src/api/store/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def reply_from_team_admin(self, context, args) -> (dict, MassEnergizeAPIError):

def message_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
try:
print(args)
community_id = args.pop("community_id", None)
subdomain = args.pop("subdomain", None)
user_name = args.pop("user_name", None)
Expand All @@ -73,10 +72,7 @@ def message_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
media = Media.objects.create(name=f"Messages: {new_message.title} - Uploaded File", file=uploaded_file)
media.save()
new_message.uploaded_file = media

# send message to slack


new_message.save()
return new_message, None

Expand All @@ -85,40 +81,27 @@ def message_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):

def message_team_admin(self, context: Context, args) -> (list, MassEnergizeAPIError):
try:

community_id = args.pop("community_id", None)
subdomain = args.pop("subdomain", None)
user_name = args.pop("user_name", None)
team_id = args.pop("team_id", None)
title = args.pop("title", None)
email = args.pop("email", None) or context.user_email
body = args.pop("body", None)
uploaded_file = args.pop("uploaded_file", None)
body = args.pop("message", None) or args.pop("body", None)

community, err = get_community(community_id, subdomain)
if err:
return None, err
if not team_id:
return None, InvalidResourceError()

team = Team.objects.filter(pk=team_id).first()
if not team:
return None, InvalidResourceError()

new_message = Message.objects.create(user_name=user_name, title=title, body=body, community=community, team=Team, is_team_admin_message=True)
new_message.save()
user, err = get_user(context.user_id, email)
user, err = get_user(context.user_id)
if err:
return None, err
if user:
new_message.user = user

if uploaded_file:
media = Media.objects.create(name=f"Messages: {new_message.title} - Uploaded File", file=uploaded_file)
media.save()
new_message.uploaded_file = media

community = team.community
new_message = Message.objects.create(user_name=user_name, user=user, title=title, body=body, community=team.community, team=team, is_team_admin_message=True)
new_message.save()

return new_message, None

except Exception as e:
Expand Down Expand Up @@ -170,13 +153,13 @@ def list_community_admin_messages(self, context: Context, args):
print(e)
return None, CustomMassenergizeError(str(e))

def list_team_admin_messages(self, context: Context, args):
def list_team_admin_messages(self, context: Context):
try:
admin_communities, err = get_admin_communities(context)
if context.user_is_community_admin:
messages = Message.objects.filter(is_deleted=False, is_team_admin_message=True, community__id__in=[c.id for c in admin_communities])
elif context.user_is_super_admin:
if context.user_is_super_admin:
messages = Message.objects.filter(is_deleted=False, is_team_admin_message=True)
elif context.user_is_community_admin:
admin_communities, err = get_admin_communities(context)
messages = Message.objects.filter(is_deleted=False, is_team_admin_message=True, community__id__in=[c.id for c in admin_communities])
else:
messages = []

Expand Down
3 changes: 0 additions & 3 deletions src/api/store/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def backfill_graph_default_data(self, context: Context, args):
if user_action.action and user_action.action.tags.filter(pk=tag.id).exists():
val += 1

print(val, d)
d.value = val
d.save()
return {'graph_default_data': 'done'}, None
Expand All @@ -101,7 +100,6 @@ def backfill_graph_default_data(self, context: Context, args):
def backfill_real_estate_units(self, context: Context, args):
try:
for user_action in UserActionRel.objects.all():
print(user_action.real_estate_unit, user_action.action.community)
if not user_action.real_estate_unit.community:
user_action.real_estate_unit.community = user_action.action.community
user_action.real_estate_unit.unit_type = (user_action.real_estate_unit.unit_type or 'residential').lower()
Expand All @@ -121,7 +119,6 @@ def backfill_tag_data(self, context: Context, args):
for data in Data.objects.all():
if data.tag and data.tag.name == "Lighting":
home_energy_data = Data.objects.filter(community=data.community, tag__name="Home Energy").first()
print(data, home_energy_data)
if home_energy_data:
home_energy_data.value += data.value
home_energy_data.reported_value += data.reported_value
Expand Down
1 change: 0 additions & 1 deletion src/api/store/tag_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def update_tag_collection(self, tag_collection_id, args) -> (dict, MassEnergizeA
def delete_tag_collection(self, tag_collection_id) -> (dict, MassEnergizeAPIError):
try:
tag_collections = TagCollection.objects.filter(id=tag_collection_id)
print(tag_collection_id, tag_collections)
if not tag_collections:
return None, InvalidResourceError()
tag_collections.delete()
Expand Down
9 changes: 1 addition & 8 deletions src/api/store/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def update_team(self, team_id, args) -> (dict, MassEnergizeAPIError):

def delete_team(self, team_id) -> (dict, MassEnergizeAPIError):
try:
print(team_id)
teams = Team.objects.filter(id=team_id)
if not teams:
return None, InvalidResourceError()
Expand All @@ -149,7 +148,6 @@ def delete_team(self, team_id) -> (dict, MassEnergizeAPIError):
team = teams.first()
members = TeamMembers.objects.filter(team=team)
msg = "delete_team: Team %s deleting %d members" % (team.name,members.count())
print(msg)
members.delete()
teams.delete() # or should that be team.delete()?

Expand All @@ -165,7 +163,6 @@ def join_team(self, team_id, user_id) -> (Team, MassEnergizeAPIError):
user = UserProfile.objects.get(id=user_id)
teamMember = TeamMember.create(team=team, user=user)
teamMember.save()
print("join_team")
#team.members.add(user_id)
#team.save()
return team, None
Expand All @@ -178,17 +175,13 @@ def leave_team(self, team_id, user_id) -> (Team, MassEnergizeAPIError):
user = UserProfile.objects.get(id=user_id)
teamMembers = TeamMember.objects.filter(team=team, user=user)
teamMembers.delete()
print("leave_team")
#team.members.remove(user_id)
#team.admins.remove(user_id)
#team.save()

return team, None
except Exception as e:
return None, CustomMassenergizeError(str(e))

def add_team_member(self, context: Context, args) -> (Team, MassEnergizeAPIError):
try:
print(args)
team_id = args.pop('team_id', None)
user = get_user_or_die(context, args)
status = args.pop('is_admin', None) == 'true'
Expand Down
1 change: 0 additions & 1 deletion src/api/store/testimonial.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def list_testimonials(self, context: Context, args) -> (list, MassEnergizeAPIErr

def create_testimonial(self, context: Context, args) -> (dict, MassEnergizeAPIError):
try:
print(args)
image = args.pop('image', None)
tags = args.pop('tags', [])
action = args.pop('action', None)
Expand Down
2 changes: 1 addition & 1 deletion src/api/store/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_community(community_id=None, subdomain=None):

return None, CustomMassenergizeError("Missing community_id or subdomain field")

def get_user(user_id, email):
def get_user(user_id, email=None):
try:
if email:
return UserProfile.objects.filter(email=email).first(), None
Expand Down

0 comments on commit 8565b13

Please sign in to comment.