def show_member_info_form(self): logging.debug("show_admin_login_form") login_check = check_login(self) if login_check: try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/member_info_form.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error") else: self.redirect('/?' + urllib.urlencode({'member_login': True}))
def show_add_organization_info_form(self, name): logging.debug("show_organization_html") if check_login(self): # try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0 : path_length - 11] + "views/htmls/show_add_organization_info_form.html" filters = {"name": name} logged_in = check_login(self) results, results_exist = datastore_results( "Organization", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None ) order = "name" organization_results, results_exist = datastore_results( "Organization", filters=None, inequality_filters=None, order=order, fetch_total=1000, offset=0, mem_key=None ) data = { "logged_in": logged_in, "organization_results": organization_results, "single_organization_results": results, "title_kind": "Organizations", "name": name, } self.response.out.write(template.render(final_path, data)) # except: # logging.debug("exception") # show_error_html(self, "template error") else: self.redirect("/")
def show_home_page_html(self): logging.debug("show_home_page_html") # try: if check_login(self): path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0 : path_length - 11] + "views/htmls/member_home_html.html" logging.debug("path = " + path) logging.debug("final_path = " + final_path) session = get_current_session() email = session["email"] logged_in = check_login(self) filters = {"email": email} member_results, member_results_exist = datastore_results( "Member", filters=filters, inequality_filters=None, order=None, fetch_total=1000, offset=0, mem_key=None ) finished_organizations_list = [] unfinished_organizations_list = [] original_organizations_list = [] for result in member_results: original_organizations_list = result.orgs_list for name in original_organizations_list: filters = {"name": name} results, results_exist = datastore_results( "Organization", filters=filters, inequality_filters=None, order=None, fetch_total=1000, offset=0, mem_key=None, ) for result in results: city = result.city if city: finished_organizations_list.append(name) else: unfinished_organizations_list.append(name) error_message = "MEMBER HOME PAGE... CONTROL NOT FINISHED" data = { "error_message": error_message, "title_kind": "About Me:", "member_results": member_results, "logged_in": logged_in, "finished_organizations_list": finished_organizations_list, "unfinished_organizations_list": unfinished_organizations_list, } self.response.out.write(template.render(final_path, data)) # except: # logging.debug("exception") # show_error_html(self, "template error") else: self.redirect("/")
def show_index_html(self): logging.debug("show_index_html") session = get_current_session() staff_boolean = False try: staff_boolean = session['staff'] except: staff_boolean = False if staff_boolean: try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/index_staff.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error") else: #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/index.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) results, results_exist = datastore_results("Post", filters = None, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None) data = { "logged_in": logged_in, "post_results": results, "title_kind": "Timeline", } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error")
def show_add_post_form(self, post_id = None): logging.debug("show_index_html") if check_login(self): #try: session = get_current_session() email = session['email'] old_entry = None old_tags = None old_title = None old_hash = None if post_id: filters = { "email": email, "post_id": post_id, } results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if not results_exist: return False for result in results: old_entry = result.entry old_tags = result.tags old_title = result.title old_hash = result.post_id path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/add_post.html' #print final_path logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, "title_kind": "What makes a good post", "old_entry": old_entry, "old_title": old_title, "old_tags": old_tags, "old_hash": old_hash, } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error") else: self.redirect("/")
def show_search_volunteers_by_skill_form(self): logging.debug("show_index_html") session = get_current_session() staff_boolean = False try: staff_boolean = session['staff'] except: staff_boolean = False if staff_boolean: try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/search_volunteers_by_skill_form.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error") else: pass
def show_organizations_html(self): logging.debug("show_tags_html") #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/show_organizations_html.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) order = "name" results, results_exist = datastore_results("Organization", filters = None, inequality_filters = None, order = order, fetch_total = 1000, offset = 0, mem_key = None) data = { "logged_in": logged_in, "organization_results": results, "title_kind": "Organizations", } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error")
def put_organization(self, name): logging.debug("put_organization") if check_login(self): continue_boolean = False email = "" # try: session = get_current_session() email = session["email"] continue_boolean = True # except: # logging.debug("gaesessions exception, do not continue") # continue_boolean = False # show_error_html(self, "session error") if continue_boolean: ### check db, if not in db put tag filters = {"name": name} results, results_exist = datastore_results( "Organization", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None, ) if results_exist: logging.debug("tag already exists") else: o = model.Organization(name=name, added_by=email) o.put() else: self.redirect("/")
def show_contact_html(self, name): logging.debug("show_contact_html") #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/show_contact_html.html' filters = { "first_name": name, } logged_in = check_login(self) results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) order = "name" contact_results, results_exist = datastore_results("Member", filters = None, inequality_filters = None, order = order, fetch_total = 1000, offset = 0, mem_key = None) data = { "logged_in": logged_in, "contact_results": contact_results, "single_contact_results": results, "title_kind": "Contacts", } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error")
def put_organization_info(self): logging.debug("put_organization_info") if check_login(self): continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") if continue_boolean: name = self.request.get("name") organization = self.request.get("organization") email = self.request.get("email") street_address = self.request.get("street_address") city = self.request.get("city") state = self.request.get("state") country = self.request.get("country") notes = self.request.get("notes") address = street_address + " " + city + " " + state + " " + country print address if not state: address = street_address + " " + city + " " + country g = geocoders.OpenMapQuest() place, (lat, lng) = g.geocode(address) filters = { "name": name, } results, results_exist = datastore_results("Organization", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) key = None for result in results: key = result.key() if key is not None: o = model.Organization.get(key) o.email = email o.address = address o.city = city o.state = state o.country = country o.notes = notes lat_string = str(lat) lng_string = str(lng) o.lat = lat_string o.lng = lng_string o.put() else: self.redirect("/")
def plus_one_constraints(self, post_id): logging.debug("put_post_plus_one") if check_login(self): session = get_current_session() email = session["email"] filters = {"post_id": post_id} results, results_exist = datastore_results( "PlusMinusConstraints", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None, ) points = 0 if results_exist: for result in results: points = result.points # print points if points > 0: return False else: return True else: self.redirect("/")
def show_send_invite_form(self): logging.debug("show_send_invite_form") login_url = users.create_login_url("/?send_invite=True") user = users.get_current_user() if not user: self.response.out.write("<a href='%s'>Log in via google</a>" % login_url) return try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/show_send_invite_form.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, "title_kind": "Welcome to our crowdsourcing site!", } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error")
def show_maps_html(self): logging.debug("show_maps_html") #if login_check: #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/main_maps_html.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) results, results_exist = datastore_results("Organization", filters = None, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None) data = { "logged_in": logged_in, "title_kind": "Maps", "organization_results": results, } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error") #else: #self.redirect('/?' + urllib.urlencode({'member_login': True}))
def show_single_tag_html(self, tag): logging.debug("show_single_tag_html") path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/show_single_tag.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) filters = { "tags_list": tag, } results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) no_results = False if results_exist == False: no_results = True delete_tag(tag) data = { "logged_in": logged_in, "tag_results": results, "title_kind": "All results with: " + tag, "no_results": no_results, } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error")
def put_tag(self, tag): logging.debug("put_tag") if check_login(self): continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") tag = tag.lower() tag = tag.strip() if continue_boolean: ### check db, if not in db put tag filters = { "tag": tag, } results, results_exist = datastore_results("Tag", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if results_exist: logging.debug("tag already exists") else: t = model.Tag(tag = tag) t.put() else: self.redirect("/")
def put_post_flag(self): logging.debug("put_post_flag") if check_login(self): continue_boolean = False email = "" # try: session = get_current_session() email = session["email"] continue_boolean = True # except: # logging.debug("gaesessions exception, do not continue") # continue_boolean = False # show_error_html(self, "session error") if continue_boolean: post_id = self.request.get("post_id") filters = {"post_id": post_id} results, results_exist = datastore_results( "Post", filters=filters, inequality_filters=None, order=None, fetch_total=1, offset=0, mem_key=None ) key = None points = 0 for result in results: key = result.key() post_id = result.post_id email = result.email title = result.title tags = result.tags entry = result.entry tags_list = result.tags_list timestamp = result.timestamp points = result.points user_email = session["email"] p = model.FlagPost( post_id=post_id, email=email, title=title, tags=tags, entry=entry, tags_list=tags_list, timestamp=timestamp, points=points, added_by=user_email, ) p.put() db.delete(key) return post_id else: self.redirect("/")
def show_comment_form(self, post_id): logging.debug("show_comment_form") if check_login(self): #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/comment_form.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) filters = { "post_id": post_id, } results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) data = { "logged_in": logged_in, "post_id": post_id, "show_comment_form": True, "post_results": results, } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error") else: self.redirect("/")
def post(self): form = PostForm(self.request.POST) if not form.validate(): path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path + '/views/htmls/add_post.html' logged_in = check_login(self) data = { "logged_in": logged_in, 'form': form, } self.response.out.write(template.render(final_path, data)) else: post_id = put_post(self) self.redirect('/?' + urllib.urlencode({'post': post_id}))
def show_error_html(self, error_message): logging.debug("show_index_html") try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0 : path_length - 11] + "views/htmls/errors.html" logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = {"error_message": error_message, "logged_in": logged_in} self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error")
def put_comment(self): logging.debug("put_post") if check_login(self): continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") comment = self.request.get("comment") post_id = self.request.get("post_id") if not comment: logging.debug("No comment entered") return False, post_id if continue_boolean: ### check db, if not in db put tag new_hash = get_hash() timestamp = get_date_time() c = model.Comment(comment = comment, email = email, comment_id = new_hash, post_id = post_id, timestamp = timestamp) c.put() filters = { "email": email, } results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if results_exist: for result in results: key = result.key() points = result.rep_points member = model.Member.get(key) member.rep_points = points + 5 member.put() return True, post_id else: self.redirect("/")
def post(self): form = InviteForm(self.request.POST) if not form.validate(): logged_in = check_login(self) path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path + '/views/htmls/show_send_invite_form.html' data = { 'form': form, "logged_in": logged_in, } self.response.out.write(template.render(final_path, data)) return else: if send_invite(self): self.redirect('/') return else: show_error_html(self, "Send invite didn't work, please contact us, or try again")
def show_member_login_form(self): logging.debug("show_admin_login_form") try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/member_login_form.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, "title_kind": "Welcome to our crowdsourcing site!", } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error")
def show_about_us_html(self): logging.debug("show_about_us_html") try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/about_us_html.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, "title_kind": "Basic Info", } self.response.out.write(template.render(final_path, data)) except: logging.debug("exception") show_error_html(self, "template error")
def post(self): form = FeedbackForm(self.request.POST) if not form.validate(): logged_in = check_login(self) path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path + '/views/htmls/contact_us_html.html' data = { "logged_in": logged_in, 'form': form, } self.response.out.write(template.render(final_path, data)) return else: if put_feedback(self): self.redirect("/") logging.debug("feedback") return else: show_error_html(self, "Feedback didn't work, please email us and let us know what went wrong. Thanks!") logging.debug("feedback didn't work") return
def comment_minus_one_constraints(self, comment_id): logging.debug("comment_minus_one_constraints") if check_login(self): session = get_current_session() email = session['email'] filters = { "comment_id": comment_id, "email": email, } results, results_exist = datastore_results("CommentPlusMinusConstraints", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) points = 0 if results_exist: for result in results: points = result.points #print points if points < 0: return False else: return True else: return False
def show_post_html(self, post_id): logging.debug("show_post_html") #try: path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/show_post.html' logging.debug("path = " + path) logging.debug("final_path = " + final_path) filters = { "post_id": post_id, } results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) filters = { "post_id": post_id, } comment_results, comment_results_exist = datastore_results("Comment", filters = filters, inequality_filters = None, order = None, fetch_total = 1000, offset = 0, mem_key = None) login_check = check_login(self) data = { "post_results": results, "logged_in": login_check, "comment_results": comment_results, "title_kind": "About Post", } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error")
def put_post_minus_one(self): logging.debug("put_post_minus_one") if check_login(self): continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") if continue_boolean: post_id = self.request.get("post_id") post_email = "" if minus_one_constraints(self, post_id): filters = { "post_id": post_id, } results, results_exist = datastore_results("Post", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) key = None points = 0 for result in results: key = result.key() post_email = result.email points = result.points if key is not None: p = model.Post.get(key) if points is None: points = 0 p.points = points - 1 p.put() filters = { "post_id": post_id, "email": email, } results, results_exist = datastore_results("PlusMinusConstraints", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) points = 0 if results_exist: for result in results: points = result.points key = result.key() pm = model.PlusMinusConstraints.get(key) pm.points = points - 1 pm.put() else: pm = model.PlusMinusConstraints(email = email, post_id = post_id, points = points - 1) pm.put() filters = { "email": post_email, } results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if results_exist: for result in results: key = result.key() points = result.rep_points member = model.Member.get(key) member.rep_points = points - 4 member.put() return post_id else: self.redirect("/")
def put_post(self): logging.debug("put_post") if check_login(self): continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") if continue_boolean: title = self.request.get("title") tags = self.request.get("tags") entry = self.request.get("entry") old_hash = self.request.get("old_hash") tags_list = [] final_list = [] tags = tags.lower() tags_list = tags.split(",") for item in tags_list: final_item = item.strip() put_tag(self, final_item) final_list.append(final_item) new_hash = get_hash() timestamp = get_date_time() key = check_post_duplicates(old_hash) if key: p = model.Post.get(key) p.title = title p.tags = tags p.entry = entry p.tags_list = final_list p.timestamp = timestamp p.put() return old_hash p = model.Post(post_id = new_hash, email = email, title = title, tags = tags, entry = entry, tags_list = final_list, timestamp = timestamp, points=0) p.put() filters = { "email": email, } results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if results_exist: for result in results: key = result.key() points = result.rep_points member = model.Member.get(key) member.rep_points = points + 10 member.put() return new_hash else: self.redirect("/")
def show_edit_member(self): logging.debug("show_index_html") if check_login(self): #try: session = get_current_session() email = session['email'] old_email = None old_first_name = None old_last_name = None old_twitter = None old_orgs = None old_orgs_list = None old_anything_else = None old_location = None old_rep_points = None old_city = None old_state = None old_country = None filters = { "email": email, } results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) if not results_exist: return False for result in results: old_email = result.email old_first_name = result.first_name old_last_name = result.last_name old_twitter = result.twitter old_orgs = result.orgs old_orgs_list = result.orgs_list old_anything_else = result.anything_else old_location = result.location old_rep_points = result.rep_points try: old_city = result.city old_state = result.state old_country = result.country except: pass path = os.path.join(os.path.dirname(__file__)) path_length = path.__len__() final_path = path[0:path_length-11] + 'views/htmls/member_info_form.html' #print final_path logging.debug("path = " + path) logging.debug("final_path = " + final_path) logged_in = check_login(self) data = { "logged_in": logged_in, "title_kind": "Edit Member Info", "old_email": old_email, "old_first_name": old_first_name, "old_last_name": old_last_name, "old_twitter": old_twitter, "old_orgs": old_orgs, "old_orgs_list": old_orgs_list, "old_anything_else": old_anything_else, "old_location": old_location, "old_rep_points": old_rep_points, "old_city": old_city, "old_state": old_state, "old_country": old_country, } self.response.out.write(template.render(final_path, data)) #except: #logging.debug("exception") #show_error_html(self, "template error") else: self.redirect("/")
def put_member_info(self): if check_login(self): logging.debug("sign_in_user") continue_boolean = False email = "" #try: session = get_current_session() email = session['email'] continue_boolean = True #except: #logging.debug("gaesessions exception, do not continue") #continue_boolean = False #show_error_html(self, "session error") if continue_boolean: first_name = self.request.get("first_name") last_name = self.request.get("last_name") twitter = self.request.get("twitter") organizations = self.request.get("organizations") anything_else = self.request.get("anything_else") city = self.request.get("city") state = self.request.get("state") country = self.request.get("country") if state: location = city + " " + state + " " + country else: location = city + " " + country filters = { "email": email, } results, results_exist = datastore_results("Member", filters = filters, inequality_filters = None, order = None, fetch_total = 1, offset = 0, mem_key = None) organizations_list = [] final_list = [] organizations = organizations.lower() organizations_list = organizations.split(",") for item in organizations_list: final_item = item.strip() final_list.append(final_item) put_organization(self, final_item) if results_exist: key = None for result in results: key = result.key() if key is not None: try: m = model.Member.get(key) m.first_name = first_name m.last_name = last_name m.twitter = twitter m.orgs = organizations m.orgs_list = final_list m.anything_else = anything_else m.location = location m.city = city m.state = state m.country = country m.put() return True except: return False else: return False else: return False else: self.redirect("/")