def get(self, username): """ """ if username == 'profile': up_dict = self.current_userprofile.to_python() username = self.current_user.username else: # Load user's profile, if available. up_dict = load_userprofile(self.db_conn, owner_username=username) if up_dict and 'email' in up_dict and 'avatar_url' not in up_dict: # ad-hoc gravatar support! email = up_dict['email'] email_hash = md5(email).hexdigest() avatar_url = 'http://www.gravatar.com/avatar/%s?s=100' % email_hash up_dict['avatar_url'] = avatar_url user_links = load_listitems(self.db_conn, owner_username=username, archived=None) user_links = ListHandlerBase.prepare_items(user_links) context = { 'userprofile': up_dict, 'links': user_links, } return self.render_template('profiles/view.html', **context)
def post(self): """Renders a JSON list of link data """ ### Stream offset updated_offset = self.get_stream_offset() ### Load the owner_id's list of items, sorted by `updated_at`. items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, updated_after=updated_offset) items_qs.sort("updated_at", direction=pymongo.DESCENDING) num_items = items_qs.count() ### Page list (page, count, skip) = self.get_paging_arguments() items_qs.skip(skip) items_qs.limit(count) ### Generate safe list out of loaded items items = [ListItem.make_ownersafe(i) for i in items_qs] data = {"num_items": num_items, "items": items} self.add_to_payload("data", data) return self.render(status_code=200)
def get(self, username): """ """ if username == 'profile': up_dict = self.current_userprofile.to_python() username = self.current_user.username else: # Load user's profile, if available. up_dict = load_userprofile(self.db_conn, username=username) if up_dict and 'email' in up_dict and 'avatar_url' not in up_dict: # ad-hoc gravatar support! email = up_dict['email'] email_hash = md5(email).hexdigest() avatar_url = 'http://www.gravatar.com/avatar/%s?s=100' % email_hash up_dict['avatar_url'] = avatar_url user_links = load_listitems(self.db_conn, owner_username=username, archived=None) user_links = ListHandlerBase.prepare_items(user_links) context = { 'userprofile': up_dict, 'links': user_links, } return self.render_template('profiles/view.html', **context)
def post(self): """Renders a JSON list of link data """ ### Stream offset updated_offset = self.get_stream_offset() ### Load the owner_id's list of items, sorted by `updated_at`. items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, updated_after=updated_offset) items_qs.sort('updated_at', direction=pymongo.DESCENDING) num_items = items_qs.count() ### Page list (page, count, skip) = self.get_paging_arguments() items_qs.skip(skip) items_qs.limit(count) ### Generate safe list out of loaded items items = [ListItem.make_ownersafe(i) for i in items_qs] data = { 'num_items': num_items, 'items': items, } self.add_to_payload('data', data) return self.render(status_code=200)
def get(self): """Renders a template with our links listed """ items_qs = load_listitems(self.db_conn, self.current_user.username) items_qs.sort("updated_at", direction=pymongo.DESCENDING) items = [ListItem(i).to_primitive(role="owner") for i in items_qs] context = {"links": items} return self.render_template("linklists/link_list.html", **context)
def get(self): """Renders a template with our links listed """ items_qs = load_listitems(self.db_conn, self.current_user.username) items_qs.sort('updated_at', direction=pymongo.DESCENDING) items = [ListItem(i).to_primitive(role='owner') for i in items_qs] context = { 'links': items, } return self.render_template('linklists/link_list.html', **context)
def get(self): """Renders a template with our links listed """ items_qs = load_listitems(self.db_conn, self.current_user.id) items_qs.sort('updated_at', direction=pymongo.DESCENDING) items = [(i['updated_at'], i['url']) for i in items_qs] context = { 'links': items, } return self.render_template('linklists/link_list.html', **context)
def get(self): """A list display matching the parameters of a user's liked items list with respect to `load_listitems`. """ self.handle_updates() tags = self.get_tags() items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, liked=True, archived=None, tags=tags) items = ListHandlerBase.prepare_items(items_qs) context = {"links": items} return self.render_template("linklists/link_list.html", **context)
def get(self): """A list display matching the parameters of a user's dashboard. The parameters essentially map to the variation in how `load_listitems` is called. """ self.handle_updates() tags = self.get_tags() items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, tags=tags) items = ListHandlerBase.prepare_items(items_qs) context = {"links": items} return self.render_template("linklists/link_list.html", **context)
def get(self): """Renders a JSON response """ paging_arguments = self.get_paging_arguments() total = load_listitems(self.db_conn, self.current_user.username).count() items_qs = page_listitems(self.db_conn, self.current_user.username, **paging_arguments) items_qs.sort("updated_at", direction=pymongo.DESCENDING) num_items = items_qs.count() response = { "paging": {"page": paging_arguments["page"], "count": paging_arguments["count"], "total": total}, "items": [ListItem(i).to_primitive(role="owner") for i in items_qs], } self.set_body(json.dumps(response)) return self.render(status_code=200)
def get(self): """Renders a template with our links listed """ items_qs = load_listitems(self.db_conn, self.current_user.id) items_qs.sort('updated_at', direction=pymongo.DESCENDING) num_items = items_qs.count() items = [ListItem.make_ownersafe(i) for i in items_qs] data = { 'num_items': num_items, 'items': items, } self.set_body(json.dumps(data)) return self.render(status_code=200)
def get(self): """A list display matching the parameters of a user's archive with respect to `load_listitems`. """ self.handle_updates() tags = self.get_tags() items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, archived=True, tags=tags) items = ListHandlerBase.prepare_items(items_qs) context = { 'links': items, } return self.render_template('linklists/link_list.html', **context)
def get(self): """A list display matching the parameters of a user's dashboard. The parameters essentially map to the variation in how `load_listitems` is called. """ self.handle_updates() tags = self.get_tags() items_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, tags=tags) items = ListHandlerBase.prepare_items(items_qs) context = { 'links': items, } return self.render_template('linklists/link_list.html', **context)
def _load_item(self, owner_id, item_id): """Helper for loading a single item, if `item_id` is good. """ if item_id: try: item_id = ObjectIdField().for_python(item_id) except: return None item_qs = load_listitems(self.db_conn, owner_id=self.current_user.id, item_id=item_id) items = list(item_qs) if len(items) != 1: return None else: item = items[0] return item
def get(self): """Renders a JSON response """ paging_arguments = self.get_paging_arguments() total = load_listitems(self.db_conn, self.current_user.username).count() items_qs = page_listitems(self.db_conn, self.current_user.username, **paging_arguments) items_qs.sort('updated_at', direction=pymongo.DESCENDING) num_items = items_qs.count() response = { 'paging': { 'page': paging_arguments['page'], 'count': paging_arguments['count'], 'total': total }, 'items': [ListItem(i).to_primitive(role='owner') for i in items_qs] } self.set_body(json.dumps(response)) return self.render(status_code=200)
def get(self, username): """ """ if username == "profile": up_dict = self.current_userprofile.to_python() username = self.current_user.username else: # Load user's profile, if available. up_dict = load_userprofile(self.db_conn, owner_username=username) if up_dict and "email" in up_dict and "avatar_url" not in up_dict: # ad-hoc gravatar support! email = up_dict["email"] email_hash = md5(email).hexdigest() avatar_url = "http://www.gravatar.com/avatar/%s?s=100" % email_hash up_dict["avatar_url"] = avatar_url user_links = load_listitems(self.db_conn, owner_username=username, archived=None) user_links = ListHandlerBase.prepare_items(user_links) context = {"userprofile": up_dict, "links": user_links} return self.render_template("profiles/view.html", **context)