def get(self, profile_slug, data_source_slug, data_view_ext): try: user = User.get_by_slug(profile_slug) if not user: raise ValueError("No user exists called %s" % profile_slug) data_source = DataSource.get_by_slug(user, data_source_slug) if not data_source: raise ValueError("No data source exists with the slug %s" % data_source_slug) data_view = DataView.get_by_extension(data_source, data_view_ext) if not data_view: raise ValueError("No data view exists with the extension %s" % data_view_ext) self.response.headers.add('Access-Control-Allow-Origin','*') self.response.content_type = str(data_view.mimetype) self.response.write(data_view.render()) # TODO Consider context specific error messages (xml, json &c.) issue#31 except ValueError as e: error_404(self.request, self.response, e) except Exception as e: error_500(self.request, self.response, e)
def get(self, profile_slug): try: user = User.get_by_slug(profile_slug) if not user: raise ValueError("No user exists called %s" % profile_slug) current_user = self.current_user().to_dict() if self.current_user() else {} data = {'user': user.to_dict(), 'current_user': current_user} body = render('user_profile.html', data) self.response.write(body) except ValueError as e: error_404(self.request, self.response, e) except Exception as e: error_500(self.request, self.response, e)
def get(self, profile_slug, data_source_slug): try: user = User.get_by_slug(profile_slug) if not user: raise ValueError("No user exists called %s" % profile_slug) data_source = DataSource.get_by_slug(user, data_source_slug) if not data_source: raise ValueError("No data source exists with the slug %s" % data_source_slug) if 'copy' in self.request.GET.keys(): # TODO handler to duplicate data source in current_user profile issue#17 self.response.write('copy data source') else: current_user = self.current_user().to_dict() if self.current_user() else {} data = {'user': user.to_dict(), 'data_source': data_source.to_dict(), 'current_user': current_user} body = render('data_source.html', data) self.response.write(body) except ValueError as e: error_404(self.request, self.response, e) except Exception as e: error_500(self.request, self.response, e)
def test_user_method_get_by_slug(self): user = self.make_user() self.assertEqual(user.key(), User.get_by_slug(dummy.user['profile_slug']).key())