def get(self, page): r""" If page doesn't exist, send to edit page If no id sent, show last version, If id sent, and id matches page, show version with the id if id doesn't match page, show last version """ last_10_wikis = self.get_last_10_wikis() id = self.request.get( 'id' ) wiki = None #verify id exists and is a valid number, therwise show last version if id and id.isdigit(): #if id is a valid number, verify that it exists and that id version belongs to page #If it does, show the id version, otherwise show last version wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == page:#id exists and belongs to page content = wiki.content # Mofify login part on top depending on whether user is logged in if session.is_user_logged_in(self): username_session = session.get_username(self) self.render('page.html',last_10_wikis=last_10_wikis, page=page, username_session=username_session, link_edit_view="/_edit" ,edit_view="edit", content=content) else: self.render('page.html',last_10_wikis=last_10_wikis, content=content) else: self.show_last_version(page) else: self.show_last_version(page)
def get(self): r"""Load main page and change login header depending if user is logged-in or not """ #check if main page exists, if it doesn't create a welcome message. query = "SELECT * FROM Wiki WHERE page = '/' ORDER BY created DESC LIMIT 1" wiki = db.GqlQuery(query) if not wiki.count():#if main page does not exist content = "Welcome to my new wiki" new_wiki = Wiki(parent=Wiki.wiki_key(), page = '/', content = content) new_wiki.put() time.sleep(.5) #make sure put goes before geeting list of wikis last_10_wikis = self.get_last_10_wikis() id = self.request.get( 'id' ) username_session = session.get_username(self) wiki = None if id:#if user is requesting an specific version wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == "/": #Check version belong to this page content = wiki.content self.render("page.html", from_main = True, last_10_wikis=last_10_wikis, page = "/",username_session=username_session, link_edit_view="/_edit/?id="+ id, edit_view="edit", content=content) else:#Not a version, load last version query = "SELECT * FROM Wiki WHERE page = '/' ORDER BY created DESC LIMIT 1" wiki = db.GqlQuery(query) content = "" if wiki.count():#if wiki exist content = wiki.get().content self.render("page.html", from_main = True, last_10_wikis=last_10_wikis, page = "/",username_session=username_session, link_edit_view="/_edit", edit_view="edit", content=content)
def get(self, page): r""" If an id is sent, and id is from given page, edit that version of a page, if no id is sent, and id is not from given page, edit the last version, if page doesn't exist, sow blank textarea If user not logged in, send user to loggin page """ last_10_wikis = self.get_last_10_wikis() if session.is_user_logged_in(self): id = self.request.get('id') wiki = None username_session = session.get_username(self) if id and id.isdigit(): wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == page: content = wiki.content self.render('edit.html', last_10_wikis=last_10_wikis, username_session=username_session, page=page, edit_view="view", content=content) else: self.edit_last_version(page, username_session) else: self.edit_last_version(page, username_session) else: self.redirect('/login')
def get(self): r""" Shows sign-up page """ last_10_wikis = self.get_last_10_wikis() username_session = session.get_username(self) self.render('signup.html', last_10_wikis=last_10_wikis, username_session=username_session)
def get(self, page): r""" get all versions of pages and show them to user in a table, if page does not exist, table will be empty """ last_10_wikis = self.get_last_10_wikis() query = "SELECT * FROM Wiki WHERE page = '%s' ORDER BY created DESC" %(page) wikis = db.GqlQuery(query) self.set_escaping(True) username_session = session.get_username(self) self.render('history.html', last_10_wikis=last_10_wikis, username_session=username_session, wikis=wikis, page=page) self.set_escaping(False)
def show_last_version(self,page): last_10_wikis = self.get_last_10_wikis() query = "SELECT * FROM Wiki WHERE page = '%s' ORDER BY created DESC LIMIT 1" %(page) wiki = db.GqlQuery(query) if wiki.count():#if wiki exist content = wiki.get().content if session.is_user_logged_in(self): username_session = session.get_username(self) self.render('page.html',last_10_wikis=last_10_wikis, page=page, username_session=username_session, link_edit_view="/_edit" ,edit_view="edit", content=content) else: self.render('page.html',last_10_wikis=last_10_wikis, page=page, content=content) else: url = "/_edit%s"%(page) self.redirect(url)
def get(self, page): r""" get all versions of pages and show them to user in a table, if page does not exist, table will be empty """ last_10_wikis = self.get_last_10_wikis() query = "SELECT * FROM Wiki WHERE page = '%s' ORDER BY created DESC" % ( page) wikis = db.GqlQuery(query) self.set_escaping(True) username_session = session.get_username(self) self.render('history.html', last_10_wikis=last_10_wikis, username_session=username_session, wikis=wikis, page=page) self.set_escaping(False)
def get(self): r"""Load main page and change login header depending if user is logged-in or not """ #check if main page exists, if it doesn't create a welcome message. query = "SELECT * FROM Wiki WHERE page = '/' ORDER BY created DESC LIMIT 1" wiki = db.GqlQuery(query) if not wiki.count(): #if main page does not exist content = "Welcome to my new wiki" new_wiki = Wiki(parent=Wiki.wiki_key(), page='/', content=content) new_wiki.put() time.sleep(.5) #make sure put goes before geeting list of wikis last_10_wikis = self.get_last_10_wikis() id = self.request.get('id') username_session = session.get_username(self) wiki = None if id: #if user is requesting an specific version wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == "/": #Check version belong to this page content = wiki.content self.render("page.html", from_main=True, last_10_wikis=last_10_wikis, page="/", username_session=username_session, link_edit_view="/_edit/?id=" + id, edit_view="edit", content=content) else: #Not a version, load last version query = "SELECT * FROM Wiki WHERE page = '/' ORDER BY created DESC LIMIT 1" wiki = db.GqlQuery(query) content = "" if wiki.count(): #if wiki exist content = wiki.get().content self.render("page.html", from_main=True, last_10_wikis=last_10_wikis, page="/", username_session=username_session, link_edit_view="/_edit", edit_view="edit", content=content)
def get(self, page): r""" If an id is sent, and id is from given page, edit that version of a page, if no id is sent, and id is not from given page, edit the last version, if page doesn't exist, sow blank textarea If user not logged in, send user to loggin page """ last_10_wikis = self.get_last_10_wikis() if session.is_user_logged_in(self): id = self.request.get( 'id' ) wiki = None username_session = session.get_username(self) if id and id.isdigit() : wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == page: content = wiki.content self.render('edit.html', last_10_wikis=last_10_wikis, username_session=username_session, page=page, edit_view="view", content = content) else: self.edit_last_version(page, username_session) else: self.edit_last_version(page, username_session) else: self.redirect('/login' )
def handle_submission(): if session.is_logged_in(): json_request = request.get_json() if json_request is None: return jsonify(standard_responses.REQUEST_ISNT_JSON) try: sess = db.make_session() chart = db.get_chart_by_hash(sess, json_request['chart_sha256']) client = db.get_client_by_name_and_key(sess, json_request["client"], json_request["key_name"]) if not chart: chart = db.add_chart_from_score(sess, json_request) if client: if score_is_valid(json_request): user = db.get_user_by_username(sess, session.get_username()) db.add_score(sess, user, chart, client, json_request) sess.commit() else: return jsonify(standard_responses.SCORE_REJECTED) else: return jsonify(standard_responses.INVALID_CLIENT_KEY) except Exception as e: sess.rollback() db.app.logger.error("Error adding score: {}".format(e)) traceback.print_tb(e.__traceback__) return jsonify(standard_responses.MALFORMED_REQUEST) else: return jsonify(standard_responses.UNAUTHORIZED) return jsonify(standard_responses.OK)
def get(self, page): r""" If page doesn't exist, send to edit page If no id sent, show last version, If id sent, and id matches page, show version with the id if id doesn't match page, show last version """ last_10_wikis = self.get_last_10_wikis() id = self.request.get('id') wiki = None #verify id exists and is a valid number, therwise show last version if id and id.isdigit(): #if id is a valid number, verify that it exists and that id version belongs to page #If it does, show the id version, otherwise show last version wiki = Wiki.get_by_id(int(id), parent=Wiki.wiki_key()) if wiki and wiki.page == page: #id exists and belongs to page content = wiki.content # Mofify login part on top depending on whether user is logged in if session.is_user_logged_in(self): username_session = session.get_username(self) self.render('page.html', last_10_wikis=last_10_wikis, page=page, username_session=username_session, link_edit_view="/_edit", edit_view="edit", content=content) else: self.render('page.html', last_10_wikis=last_10_wikis, content=content) else: self.show_last_version(page) else: self.show_last_version(page)
def show_last_version(self, page): last_10_wikis = self.get_last_10_wikis() query = "SELECT * FROM Wiki WHERE page = '%s' ORDER BY created DESC LIMIT 1" % ( page) wiki = db.GqlQuery(query) if wiki.count(): #if wiki exist content = wiki.get().content if session.is_user_logged_in(self): username_session = session.get_username(self) self.render('page.html', last_10_wikis=last_10_wikis, page=page, username_session=username_session, link_edit_view="/_edit", edit_view="edit", content=content) else: self.render('page.html', last_10_wikis=last_10_wikis, page=page, content=content) else: url = "/_edit%s" % (page) self.redirect(url)