def get(self): """Handler for HTTP GET requests. Loads an app from the datastore and displays information for editing purposes. """ user = users.get_current_user() app = db_models.GetApplicationById(self.request.get('app_id')) is_admin = users.is_current_user_admin() if not user: self.loginUser() return if app and (user == app.author_ref.user or is_admin): template_values = { 'title': 'Edit', 'app': app, 'is_admin': is_admin, } for api in app.apis: template_values[str(api)] = True for language in app.languages: template_values[str(language)] = True self.generate('edit.html', template_values) else: self.redirect(app.GetLink())
def get(self): """Generates the image from a blog in the datastore. request.get('img_type') is used to determine whether we are displaying a screenshot (300x200) or a thumbnail (120x60). These are stored in different entity properties so we pull the right one based on a cgi parameter passed in. """ key = self.request.get('img_id') if not key: self.error(400) return app = db_models.GetApplicationById(key) if app is None: self.error(400) return img_type = self.request.get('img_type') if img_type != 'screenshot' and img_type != 'thumbnail': self.error(400) self.response.out.write('Bad img_type') return query = db_models.ApplicationImage.all() query.filter('application =', app) query.filter('img_type =', img_type) image = query.get() if image is None: self.error(404) self.response.out.write('Image not found') return self.response.headers['Content-Type'] = 'image/png' self.response.out.write(image.content)
def post(self): """Handler for HTTP POST requests. Processes a new comment and rating.""" user = users.get_current_user() if user: app = db_models.GetApplicationById(self.request.get('app_id')) if not app: self.error('404') return title = self.request.get('title') body = self.request.get('body') nickname = self.request.get('nickname') rating = int(self.request.get('star_rating')) # Create a comment, update the avg_rating in a transaction. comment = db_models.Comment() comment.application = app comment.title = title comment.body = body comment.nickname = nickname comment.author = user comment.rating = rating comment.Add() if rating >= 1 and rating <= 5: old_rating = db.run_in_transaction(self.RateApp, app, rating, user) db.run_in_transaction(self.UpdateAppAvg, app, rating, old_rating) self.redirect(app.GetLink()) else: self.loginUser()
def post(self): """Handler for HTTP POST requests. Loads an app from the datastore and modifies supplied info. """ user = users.get_current_user() is_admin = users.is_current_user_admin() app = db_models.GetApplicationById(self.request.get('app_id')) if app and (user == app.author_ref.user or is_admin): app.title = self.request.get('title') app.author_name = self.request.get('author_name') app.author_url = self.request.get('author_url') app.type = self.request.get('type') if self.request.get('author_googler') == 'on': app.author_googler = True if self.request.get('best_practice') == 'on': app.best_practice = True if self.request.get('api_v2') == 'yes': app.api_v2 = True else: app.api_v2 = False app.description = self.request.get('content') app.code_snippet = self.request.get('code_snippet').lstrip() app.tech_details = self.request.get('tech_details') app.api_usage = self.request.get('api_usage') app.url = self.request.get('url') #if app.url and not app.url.startswith('http://'): # app.url = "http://" + app.url app.source_url = self.request.get('source_url') if app.source_url and not app.source_url.startswith('http://'): app.source_url = "http://" + app.source_url tags_str = self.request.get('tags').replace(" ", "") app.tags = tags_str.strip().split(',') app.robot_email = self.request.get('robot_email') app.gadget_xml = self.request.get('gadget_xml') app.installer_xml = self.request.get('installer_xml') app.video_url = self.request.get('video_url') app.apis = self.request.get_all('apis') app.languages = self.request.get_all('languages') if self.request.get('updatedthumbnail'): thumb = self.request.get('thumbnail') if len(thumb) <= 1000000: app.UpdateThumbnail(thumb) if self.request.get('updatedscreenshot'): ss = self.request.get('screenshot') if len(ss) <= 1000000: app.UpdateScreenshot(ss) if is_admin: admin_tags = self.request.get('admin_tags').replace(' ', '') app.admin_tags = admin_tags.split(',') app.put() if not is_admin: self.sendAdminEmail(app, 'edit') self.redirect(app.GetLink()) else: self.redirect(app.GetLink() + '&err=1')
def post(self): if users.is_current_user_admin(): app = db_models.GetApplicationById(self.request.get('app_id')) action = self.request.get('moderate_action') if app and action: if action == "approve": app.moderation_status = db_models.Application.APPROVED self.sendUserApprovalEmail(app) elif action == "reject": app.moderation_status = db_models.Application.REJECTED self.sendUserRejectionEmail(app, self.request.get('reason')) app.put() self.redirect('/moderate')
def post(self): """Handler for HTTP POST requests to delete an app from the datastore.""" user = users.get_current_user() key = self.request.get('app_id') if key is None: self.redirect('/') return app = db_models.GetApplicationById(key) if app and (user == app.author_ref.user or users.is_current_user_admin()): for comment in app.comments: comment.delete() for image in app.images: image.delete() app.delete() self.redirect('/')
def get(self): self.response.out.write("Upgrading authors <br>") app = db_models.GetApplicationById(self.request.get('id')) if app is None: query = self.queryApp() apps = query.fetch(170) for app in apps: app.author_ref.name = app.author_name app.author_ref.url = app.author_url app.author_ref.put() if app.author_ref is None: self.response.out.write("upgrading " + app.title + "<br>") self.response.out.write(app.AddAuthor(app.author)) app.put() elif app.author_ref is None: self.response.out.write("upgrading " + app.title + "<br>") self.response.out.write(app.AddAuthor(app.author)) app.put()
def get(self): """Handler for GET requests. Displays app info for the specified app.""" key = self.request.get('app_id') if not key: self.error(500) return error = self.request.get('err') is_admin = users.is_current_user_admin() app = db_models.GetApplicationById(key) if app: # If the app was found if is_admin or users.get_current_user() == app.author_ref.user: can_edit = True else: can_edit = False if app.moderation_status != db_models.Application.APPROVED and not can_edit: if not users.get_current_user(): self.loginUser() return else: self.redirect('/') return num_comments = app.comment_count # check if we're paging through comments start = self.request.get('start') prev = None next = None if start: try: start = int(start) except ValueError: start = None query = db_models.Comment.all() query.filter('application =', app) query.order('-index') if start: prev_query = db_models.Comment.all() prev_query.filter('application =', app) prev_query.order('index') prev_query.filter('index >', start) prev_results = prev_query.fetch(5) if prev_results: prev = prev_results[-1].index query.filter('index <=', start) # see if we have another page of results to look at comments = query.fetch(6) if len(comments) == 6: next = comments[-1].index comments = comments[:-1] values = { 'title': GALLERY_APP_NAME + ': ' + app.title, 'app': app, 'comments': comments, 'num_comments': num_comments, 'can_edit': can_edit, 'is_admin': is_admin, 'next': next, 'prev': prev, } for api in app.apis: values[str(api)] = True if error: # If the user was redirected here with an error. values[ 'error'] = 'You do not have permission to edit this entry' self.generate('about_app.html', values) else: self.redirect('/')