def install(self, django_user): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name, )) try: # Don't overwrite model = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) msg = _('Sample design %(name)s already exists.') % { 'name': self.name } LOG.error(msg) raise InstallException(msg) except SavedQuery.DoesNotExist: model = SavedQuery(owner=django_user, name=self.name) model.type = self.type # The data field needs to be a string. The sample file writes it # as json (without encoding into a string) for readability. model.data = simplejson.dumps(self.data) model.desc = self.desc model.save() LOG.info('Successfully installed sample design: %s' % (self.name, ))
def install(self, django_user): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name, )) try: # Don't overwrite query = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) except SavedQuery.DoesNotExist: query = SavedQuery(owner=django_user, name=self.name, type=self.type, desc=self.desc) # The data field needs to be a string. The sample file writes it # as json (without encoding into a string) for readability. query.data = json.dumps(self.data) query.save() LOG.info('Successfully installed sample design: %s' % (self.name, )) if beeswax.conf.USE_NEW_EDITOR.get(): try: # Don't overwrite doc2 = Document2.objects.get(owner=django_user, name=self.name, type=self._document_type( self.type)) except Document2.DoesNotExist: # Create document from saved query notebook = import_saved_beeswax_query(query) data = notebook.get_json() # Get or create sample user directories home_dir = Directory.objects.get_home_directory(django_user) examples_dir, created = Directory.objects.get_or_create( parent_directory=home_dir, owner=django_user, name=Document2.EXAMPLES_DIR) doc2 = Document2.objects.create(owner=django_user, parent_directory=examples_dir, name=self.name, type=self._document_type( self.type), description=self.desc, data=data) # Share with default group examples_dir.share(django_user, Document2Permission.READ_PERM, groups=[get_default_user_group()]) doc2.save() LOG.info('Successfully installed sample query: %s' % (self.name, ))
def create_saved_query(app_name, owner): query_type = SavedQuery.TYPES_MAPPING[app_name] design = SavedQuery(owner=owner, type=query_type) design.name = SavedQuery.DEFAULT_NEW_DESIGN_NAME design.desc = '' design.data = '' design.is_auto = False design.save() return design
def create_saved_query(app_name, owner): query_type = SavedQuery.TYPES_MAPPING[app_name] design = SavedQuery(owner=owner, type=query_type) design.name = SavedQuery.DEFAULT_NEW_DESIGN_NAME design.desc = '' design.data = hql_query('show $tables', database='db1').dumps() design.is_auto = False design.save() return design
def install(self, django_user, interpreter=None): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name,)) try: # Don't overwrite query = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) except SavedQuery.DoesNotExist: query = SavedQuery(owner=django_user, name=self.name, type=self.type, desc=self.desc) # The data field needs to be a string. The sample file writes it as json (without encoding into a string) for readability. query.data = json.dumps(self.data) query.save() LOG.info('Successfully installed sample design: %s' % (self.name,)) if USE_NEW_EDITOR.get(): examples_dir = _get_example_directory(django_user) document_type = self._document_type(self.type, interpreter) notebook = import_saved_beeswax_query(query, interpreter=interpreter) try: # Could move PK from a uuid in queries.json at some point to handle name changes without duplicating. # And move to a simpler json format at some point. doc2 = Document2.objects.get(owner=django_user, name=self.name, type=document_type, is_history=False) if doc2.parent_directory != examples_dir: # Recover from Trash or if moved doc2.parent_directory = examples_dir data = json.loads(doc2.data) data['uuid'] = doc2.uuid doc2.data = json.dumps(data) # Refresh content doc2.save() except Document2.DoesNotExist: # Create new example data = notebook.get_data() data['isSaved'] = True uuid = data.get('uuid') data = json.dumps(data) doc2 = Document2.objects.create( uuid=uuid, # Must the same as in the notebook data owner=django_user, parent_directory=examples_dir, name=self.name, type=document_type, description=self.desc, data=data ) # TODO: FK to connector object # Share with default group examples_dir.share(django_user, Document2Permission.READ_PERM, groups=[get_default_user_group()]) LOG.info('Successfully installed sample query: %s' % doc2)
def install(self, django_user, interpreter=None): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name,)) try: # Don't overwrite query = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) except SavedQuery.DoesNotExist: query = SavedQuery(owner=django_user, name=self.name, type=self.type, desc=self.desc) # The data field needs to be a string. The sample file writes it # as json (without encoding into a string) for readability. query.data = json.dumps(self.data) query.save() LOG.info('Successfully installed sample design: %s' % (self.name,)) if USE_NEW_EDITOR.get(): # Get or create sample user directories home_dir = Directory.objects.get_home_directory(django_user) examples_dir, created = Directory.objects.get_or_create( parent_directory=home_dir, owner=django_user, name=Document2.EXAMPLES_DIR ) document_type = self._document_type(self.type, interpreter) try: # Don't overwrite doc2 = Document2.objects.get(owner=django_user, name=self.name, type=document_type, is_history=False) # If document exists but has been trashed, recover from Trash if doc2.parent_directory != examples_dir: doc2.parent_directory = examples_dir doc2.save() except Document2.DoesNotExist: # Create document from saved query notebook = import_saved_beeswax_query(query, interpreter=interpreter) data = notebook.get_data() data['isSaved'] = True uuid = data.get('uuid') data = json.dumps(data) doc2 = Document2.objects.create( uuid=uuid, owner=django_user, parent_directory=examples_dir, name=self.name, type=document_type, description=self.desc, data=data ) # Share with default group examples_dir.share(django_user, Document2Permission.READ_PERM, groups=[get_default_user_group()]) LOG.info('Successfully installed sample query: %s' % (self.name,))
def install(self, django_user): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name,)) try: # Don't overwrite query = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) except SavedQuery.DoesNotExist: query = SavedQuery(owner=django_user, name=self.name, type=self.type, desc=self.desc) # The data field needs to be a string. The sample file writes it # as json (without encoding into a string) for readability. query.data = json.dumps(self.data) query.save() LOG.info('Successfully installed sample design: %s' % (self.name,)) if USE_NEW_EDITOR.get(): # Get or create sample user directories home_dir = Directory.objects.get_home_directory(django_user) examples_dir, created = Directory.objects.get_or_create( parent_directory=home_dir, owner=django_user, name=Document2.EXAMPLES_DIR ) try: # Don't overwrite doc2 = Document2.objects.get(owner=django_user, name=self.name, type=self._document_type(self.type)) # If document exists but has been trashed, recover from Trash if doc2.parent_directory != examples_dir: doc2.parent_directory = examples_dir doc2.save() except Document2.DoesNotExist: # Create document from saved query notebook = import_saved_beeswax_query(query) data = notebook.get_data() data['isSaved'] = True uuid = data.get('uuid') data = json.dumps(data) doc2 = Document2.objects.create( uuid=uuid, owner=django_user, parent_directory=examples_dir, name=self.name, type=self._document_type(self.type), description=self.desc, data=data ) # Share with default group examples_dir.share(django_user, Document2Permission.READ_PERM, groups=[get_default_user_group()]) LOG.info('Successfully installed sample query: %s' % (self.name,))
def create_saved_query(app_name, owner): query_type = SavedQuery.TYPES_MAPPING[app_name] design = SavedQuery(owner=owner, type=query_type) design.name = 'create_saved_query' design.desc = '' design.data = hql_query('show $tables', database='db1').dumps() design.is_auto = False design.save() Document.objects.link(design, owner=design.owner, extra=design.type, name=design.name, description=design.desc) return design
def install(self, django_user): """ Install queries. Raise InstallException on failure. """ LOG.info('Installing sample query: %s' % (self.name,)) try: # Don't overwrite model = SavedQuery.objects.get(owner=django_user, name=self.name, type=self.type) except SavedQuery.DoesNotExist: model = SavedQuery(owner=django_user, name=self.name) model.type = self.type # The data field needs to be a string. The sample file writes it # as json (without encoding into a string) for readability. model.data = json.dumps(self.data) model.desc = self.desc model.save() LOG.info('Successfully installed sample design: %s' % (self.name,))