def post (self): logged_in, db_user = ADayThere.logged_in_user () if not logged_in: self.response.status = 401 return name = self.request.get ('name', None) matched = re.match ("^[a-z0-9_]+$", name, re.IGNORECASE) if name is None or matched is None: self.response,status = 400 self.response.write ("Valid name required") return response = db_user.update_username (name) if response == False: self.response.status = 409 self.response.write (' name is in use ') return self.response.status = 200 self.response.write (name)
def put (self): logged_in, db_user = ADayThere.logged_in_user () if not logged_in: self.response.status = 401 return operation = self.request.get ("operation") if operation == 'add_tool_access': if db_user is not None and db_user.has_tool_access: return print "TOOL ACCESS FOR:", db_user db_user.has_tool_access = True db_user.date_agreed_to_tool_access = datetime.datetime.utcnow () name = self.request.get ('name', None) if name is not None: db_user.name = name db_user.put () res = { "name": name, "menu": LoggedInNavView.tool_user_menus () } self.response.status = 200 self.response.write (json.dumps (res))
def get (self): """ Responds to a get request. """ logged_in, db_user = ADayThere.logged_in_user () if not logged_in: self.response.status = 401 return res = self.__build_response (db_user) self.response.write (json.dumps (res))
def post (self): logged_in, user = ADayThere.logged_in_user () if not logged_in: self.response.status = 401 return location = json.loads (self.request.body) logging.info (location) db_location = Location () db_location.latitude = str (location["location"]["latitude"]) db_location.longitude = str (location["location"]["longitude"]) db_location.locality = location["location"]["locality"] db_location.vicinity = location["location"]["vicinity"] db_user.location = db_location db_user.put () res = self.__build_response (db_user) self.response.write (json.dumps (res))
def get (self): logged_in, db_user = ADayThere.logged_in_user () if not logged_in: self.response.status = 401 return name = self.request.get ('name', None) if name is None: self.response,status = 400 self.response.write ("Name required") return user = User.query_name (name) self.response.status = 200 if user is not None: self.response.write ('not available') else: self.response.write ('available')
def __init__ (self): super (BecomeAContributorModal, self).__init__ ("becomeAContributorModalContent.html") logged_in, db_user = ADayThere.logged_in_user () body_html = "" if logged_in: suggest_change = "" if db_user.name == db_user.email: suggest_change = """*Please, change your user name to something other then your email address to avoid spam. Only alphanumeric characters and the underscore (_) are accepted.""" if not logged_in: body_html += "You must be logged in through Google before becoming a contributor" else: body_html += """ <div>Thanks for choosing to become a contributor to the community. We ask that you don't use language that would make anyone's Grandmother blush. Be repectful of others who use "A Day There". By clicking the OK button you agree to allow "A Day There" to use the material you contribute and to abide by the rules.<br/><br/> Thank You!<br/> </div> <div id="contributor_name_choice" style="color:red;">{0}</div> <label for="contribute_google_nickname">Name:</label> <input data-warning-id="contributor_name_choice" id="contribute_google_nickname" class="form-control" type='text' contributor-user-name value="{1}"></input> <input id="contribute_gotto_tools" type="checkbox">Go to create tools</input> """.format (suggest_change, db_user.name) modalHeader = Elements () modalHeader.append_to_element (""" <h3>Become A Contributor</h3> """) self.add_header_content (modalHeader) modalBody = Elements () modalBody.append_to_element (body_html) self.add_body_content (modalBody) modalFooter = Elements () modalFooter.append_to_element (""" <button class="btn btn-primary" ng-click="contribute_modal_ok ()">OK</button> <button class="btn btn-warning" ng-click="contribute_modal_cancel ()">Cancel</button>""") self.add_footer_content (modalFooter)