def get_publish(self, document, group): document = Document.get_by_id(document) if not document: raise HttpErrorException.bad_request('invalid document id') if not document.has_permission_read(self.user): raise HttpErrorException.forbidden() group = Group.get_by_id(group) if not group: raise HttpErrorException.bad_request('invalid group id') self.project = document.project.get() version = self.request.get('v', 'latest') pub = PublishDocument.get(document, group, version) if not pub: raise HttpErrorException.not_found() if pub.group not in self.user.groups and pub.group != Group.get_worldshare_key( ): raise HttpErrorException.forbidden() self._create_analytic_session() self.project.record_analytic('pro_opn', self.analytic_session) template_index = JINJA_ENVIRONMENT.get_template('document_public.html') return template_index.render({ 'title': self.project.title, 'version': pub.version, 'created_at': pub.created_ts, 'published_to': pub.group.get().name, 'an_token': self.analytic_session.key.id(), 'project_id': self.project.id, 'html': pub.html, })
def post(self): if not self.user.is_super_admin: raise HttpErrorException.not_found() if self.json_request.get('clear_indexes'): orgs = Organization.query().fetch() for org in orgs: indexes = org.get_indexes() for index in indexes: ttindex.clear_index(index) users = User.query(User.organization == None).fetch() for user in users: indexes = user.get_indexes() for index in indexes: ttindex.clear_index(index) project_ids = self.json_request.get('project_ids') if project_ids: if project_ids == 'all': self.project_keys = Project.query().fetch(keys_only=True) else: if type(project_ids) is not list: raise HttpErrorException.bad_request( 'project ids must be list') for pro_id in project_ids: pro = Project.get_by_id(pro_id) if not pro: raise HttpErrorException.bad_request( 'invalid project id given: ' + str(pro_id)) self.project_keys.append(pro.key) t = background_thread.BackgroundThread(target=self.index_project) t.start()
def get(self, script=None): log.info('Background request received %s' % script) if not self.user.is_super_admin: raise HttpErrorException.not_found() if script == 'migration': log.info('Starting migration thread') t = background_thread.BackgroundThread(target=_do_migration) t.start() log.info('Started migration thread') log.info('Background request ended') # if parent.children.index(concept.key) == 0: # return_status = False # if parent.node_type == 'Concept': # attributes = ndb.get_multi(parent.attributes) # for attr in attributes: # if 'ul' in attr.attributes or 'ol' in attr.attributes: # if 'ul' in attr.attributes: # attr.attributes.remove('ul') # if len(concept.attributes) > 0: # concept.attributes[0].attributes.append('ul') # else: # concept.attributes.append(Attributes( # key=Attributes.create_key(), project=project.key, # document=project.distilled_document.key, attributes=['ul']).put() # ) # if 'ol' in attr.attributes: # attr.attributes.remove('ol') # if len(concept.attributes) > 0: # concept.attributes[0].attributes.append('ol') # else: # concept.attributes.append(Attributes( # key=Attributes.create_key(), project=project.key, # document=project.distilled_document.key, attributes=['ol']).put() # ) # attr.put() # if len(attr.attributes) == 0: # attr.key.delete() # parent.attributes.remove(attr.key) # attributes.remove(attr) # children = parent.children[1:] # parent.children = [parent.children[0]] # parent.put() # if not concept.children or len(concept.children) == 0: # concept.children = children # else: # concept.children += children # for child in children: # child.parent = concept.key # child.put() # break # ndb.put_multi(attributes)
def get(self, publish): if not publish: raise HttpErrorException.bad_request('invalid publish id given') pub = memcache.get(publish, namespace='document_publish') if not pub: raise HttpErrorException.not_found() if pub == '500': self.write_json_response({'error': 500}) else: document = pub.document.get() if not document.has_permission_read(self.user): raise HttpErrorException.forbidden() self.write_json_response(pub.to_dict(html=False))