def post(self, user, page): """ Updates a bookmark's collaborators """ current_user = users.get_current_user() logging.debug('Request to modify collaborators for user %s, page %s' % (user, page)) collaborators_str = self.request.get('collaborators') collaborators = collaborators_str.split() # Go thru existing collaborators and remove any from the POST that # we already have, otherwise get rid of them. bookmark_collaborators = model.fetch({ "user ="******"url =": page }, model.BookmarkCollaborator) for bookmark_collaborator in bookmark_collaborators: if bookmark_collaborator not in collaborators: bookmark_collaborator.delete() else: collaborators.remove(bookmark_collaborator) collaborator_keys = [] # Go thru remaining collaborators and add them for collaborator in collaborators: bookmark_collaborator = model.BookmarkCollaborator() bookmark_collaborator.collaborator = users.User(collaborator) bookmark_collaborator.url = page bookmark_collaborator.put() collaborator_keys.append("'%s'" % str(bookmark_collaborator.key())) keys_str = ','.join(collaborator_keys) json = '{ "collaborators": [%s] }' % keys_str logging.info(json) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json)
def update_bookmark(self, page, tags, access): current_user = users.get_current_user() bookmark = model.get({ "user ="******"url =": page }, model.Bookmark) if bookmark == None: bookmark = model.Bookmark() bookmark.url = page bookmark.access = access bookmark.put() # Now update tags bookmark_tags = model.fetch({ "user ="******"url =": page }, model.BookmarkTag) for bookmark_tag in bookmark_tags: # if existing tag isn't in list of tags submitted by user remove it, # otherwise remove tag from list of user-submitted tags if bookmark_tag not in tags: bookmark_tag.delete() else: tags.remove(bookmark_tag) # Go thru remaining user-submitted tags and add them for tag in tags: bookmark_tag = model.BookmarkTag() bookmark_tag.url = page bookmark_tag.tag = tag bookmark_tag.put()
def get(self, user, page, note_id = None): current_user = users.get_current_user() user = urllib.unquote_plus(user) bookmark_notes = model.fetch({"owner =": users.User(user), "url =": page}, model.BookmarkNote) tmpl_vars = { "notes": bookmark_notes } self.response.headers['Content-Type'] = 'application/json' self.response.out.write(template.render('tmpl/notes_json.tmpl', tmpl_vars))
def get(self, request_user, page): request_user = urllib.unquote_plus(request_user) page = urllib.unquote_plus(page) current_user = users.get_current_user() logging.debug('getting overhead user: %s, page: %s for %s' % (request_user, page, current_user)) bookmark = model.get({"user ="******"url =": page}, model.Bookmark) bookmark_tags = model.fetch({"user ="******"url =": page}, model.BookmarkTag) bookmark_collaborators = model.fetch({"user ="******"url =": page}, model.BookmarkCollaborator) bookmark_notes = self.get_bookmark_notes(request_user, page) logging.info('found %s notes' % bookmark_notes.count()) access = "" tags_str = "" collaborators_str = "" if bookmark: access = bookmark.access if bookmark_tags: bookmark_tags = map(lambda x: x.tag, bookmark_tags) tags_str = ' '.join(bookmark_tags) if bookmark_collaborators: bookmark_collaborators = map(lambda x: str(x.collaborator), bookmark_collaborators) collaborators_str = '\\n'.join(bookmark_collaborators) tmpl_vars = { "logged_in_user": current_user.email(), "user": request_user, "page": page, "access": access, "tags": tags_str, "collaborators": collaborators_str, "notes": bookmark_notes, "logout_url" : users.create_logout_url('/') } self.response.headers['Content-Type'] = 'text/html' self.response.out.write(template.render('tmpl/overhead.tmpl', tmpl_vars))
def get_bookmark_notes(self, request_user, page): # TODO Get notes for the user associated with the request and all other collaborators bookmark_notes = model.fetch({"owner =": users.User(request_user), "url =": page}, model.BookmarkNote) logging.debug('fetched %d bookmark notes', bookmark_notes.count()) return bookmark_notes