def toggleFollow(kind): data = request.get_json() userEm = data.get("userEm") orgName = data.get("orgName") org = organizationService.getOrganizationByName(orgName) if type(org) == str: print(org) return org orgId = org.get("org_id") userId = userService.getUserIdByEmail(userEm)["user_id"] if type(userId) == str: print(userId) return userId if kind == "Follow": success = subscriptionService.addSubscription(userId, orgId) if success != 1: print(success) return success if orgName not in session["subscriptions"]: session["subscriptions"].append(orgName) return "sucessfully followed" elif kind == "Unfollow": success = subscriptionService.removeSubscription(userId, orgId) if success != 1: print(success) return success if orgName in session["subscriptions"]: session["subscriptions"].remove(orgName) return "sucessfully unfollowed" else: print("there was an error in the request") return "Error, could not understand request"
def search(): query = request.args.get("search").lower() print(query) charities = [ charity for charity in organizationService.getAllCharities() if query in charity['name'].replace("-", " ").lower() ] print(charities) if "Email" in session: userId = userService.getUserIdByEmail(session.get("Email"))["user_id"] subscriptions = subscriptionService.getSubscriptions(userId) if len(subscriptions) == 0: return render_template("search.html", charities=charities, query=query) subNames = [] for subEntry in subscriptions: org = organizationService.getOrganizationById(subEntry["org_id"]) subNames.append(org["name"]) session["subscriptions"] = subNames return render_template("search.html", charities=charities, email=session["Email"], query=query) else: error = request.args.get("error") success = request.args.get("success") return render_template( "search.html", charities=charities, success=success, error=error, query=query )
def charityHome(name): session["charityName"] = name orgInfo = organizationService.getOrganizationByName(name.replace("-", " ")) session["charityLogo"] = orgInfo["imageName"] followState = "Follow" # If user is logged in if session.get("Email"): userId = userService.getUserIdByEmail(session["Email"])["user_id"] orgId = organizationService.getOrganizationByName(name.replace("-", " ")).get( "org_id" ) # if no errors getting ids and the subscription entry exists... print(userId, orgId) newsfeedPosts = newsfeedService.getNewsfeedPosts(orgId) if ( type(userId) != str and type(orgId) != str and subscriptionService.isSubscribed(userId, orgId) ): followState = "Unfollow" else: # TODO get org_id of organization and query for newsfeed posts for that org_id newsfeedPosts = newsfeedService.getNewsfeedPosts( "c17a594a-d3f8-4a46-ae59-da368c67c05d" ) # The org_id above belongs to the Red Cross # If the user is not logged in, display posts from the Red Cross by default return render_template( "charityHomePage.html", name=name, location=orgInfo["location"], description=orgInfo["summary"], subOffset=0, followUnfollow=followState, newsfeedPosts=newsfeedPosts, )
def homepage(): # If user logged in, get charities that he is subscribed to and all charitites for search. charities = organizationService.getAllCharities() print(charities) if "Email" in session: userId = userService.getUserIdByEmail(session.get("Email"))["user_id"] subscriptions = subscriptionService.getSubscriptions(userId) if len(subscriptions) == 0: return render_template("home.html", charities=charities) subNames = [] for subEntry in subscriptions: org = organizationService.getOrganizationById(subEntry["org_id"]) subNames.append(org["name"]) session["subscriptions"] = subNames return render_template("home.html", charities=charities, email=session["Email"]) else: error = request.args.get("error") success = request.args.get("success") return render_template( "home.html", charities=charities, success=success, error=error )
def profilePage(): firstName = userService.getUserIdByEmail(session.get("Email"))["name"] years = [ "2019-01-04", "2019-02-04", "2019-03-04", "2019-04-04", "2019-05-04", "2019-06-04", "2019-07-04", "2019-08-04", "2019-09-04", "2019-10-04", "2019-11-04", "2019-12-04", "2020-01-04", "2020-02-04", "2020-03-04", "2020-04-04", "2020-05-04", "2020-06-04", "2020-07-04", "2020-08-04", "2020-09-04", "2020-10-04", "2020-11-04", "2020-12-04", "2020-12-04", ] donations = [ 25, 15, 30, 45, 10, 15, 30, 15, 25, 15, 45, 55, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 60, ] yearly_donations = format_data( pd.DatetimeIndex(years), donations, lambda df: group_by_time(df, type="year") ) monthly_donations = format_data( pd.DatetimeIndex(years), donations, lambda df: group_by_time(df, type="month") ) return render_template( "profile.html", firstName=firstName, yearly_donations=yearly_donations, monthly_donations=monthly_donations, )