def shorten(self, url_to_shorten, custom_short_url, user): short_url = Trimmer(url_to_shorten).shorten(custom_short_url, user) self.template_parameters["short_url"] = short_url if short_url != custom_short_url: self.template_parameters["custom_short_url_error_message"] = 'The selected custom short URL already exists, and hece we\'ve generated a new short URL' self.logger.log(url_to_shorten, custom_short_url, short_url, RequestResult.NEW_SHORT_URL_CREATED) taskqueue.add(url='/task/linkinfo', params={'short_url': short_url}) # Update Link Info self.response.out.write(render_template("index.html", self.template_parameters))
def resolve(self, request_path, user): if is_empty(request_path): self.response.out.write(render_template("index.html", self.template_parameters)) return resolver = self.resolver_for(request_path) if resolver.is_resolvable(): if resolver.is_aggregate(): resolved_url = '/stats/' + request_path # Display aggregate stats? else: # No logging for aggregate url requests since they resolve to their stats.. Logging them would pollute stats.. resolved_url = resolver.resolved_url() self.logger.log(resolved_url, None, request_path, RequestResult.SHORT_URL_RESOLVED) taskqueue.add(url='/task/stats', params={'request_data_key': self.logger.data().key()}) # Update Stats self.redirect(resolved_url) else: self.logger.log(None, None, None, RequestResult.ERROR, '404: /%(PATH)s not found' % {"PATH" : request_path}) show_error_page(self, 404, "The requested page was not found") return