Beispiel #1
0
    def generate_server(self, a_user=None, remote=False):  # generate the report server.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = "\n  "

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
            # opens server.R template file
        filein = open(self.path_server_r_template)
        src = Template(filein.read())
        # document data
        generated = "Generated on %s for user %s (%s)" % (self.created, self.author.get_full_name(), self.author)
        updated = "Last updated on %s for user %s (%s)" % (aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by("order"):
                if each.enabled:
                    # add it to the source list
                    alist.append(
                        '### Tag %s by %s (%s) %s%ssource("%s",local = TRUE)'
                        % (
                            each.name,
                            each.author.get_full_name(),
                            each.author,
                            each.created,
                            SEP,
                            each.path_dashboard_server(remote),
                        )
                    )
                else:
                    alist.append(
                        "### DISABLED Tag %s by %s (%s) %s"
                        % (each.name, each.author.get_full_name(), each.author, each.created)
                    )
        loaders = self.get_parsed_loader()  # TODO redo
        alist.append("")  # avoid join errors if list is empty
        d = {
            "title": self.title,
            "generated": generated,
            "updated": updated,
            "loaders": loaders,
            "sources": SEP.join(alist),
        }
        assert isinstance(src, Template)
        result = src.safe_substitute(d)
        f = open(self.server_path(remote), "w")
        f.write(result)
        f.close()
        return
Beispiel #2
0
    def generate_server(
        self,
        a_user=None,
        remote=False
    ):  # generate the report server.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = '\n  '

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
        # opens server.R template file
        filein = open(self.path_server_r_template)
        src = Template(filein.read())
        # document data
        generated = 'Generated on %s for user %s (%s)' % (
            self.created, self.author.get_full_name(), self.author)
        updated = 'Last updated on %s for user %s (%s)' % (
            aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by('order'):
                if each.enabled:
                    # add it to the source list
                    alist.append(
                        '### Tag %s by %s (%s) %s%ssource("%s",local = TRUE)' %
                        (each.name, each.author.get_full_name(),
                         each.author, each.created, SEP,
                         each.path_dashboard_server(remote)))
                else:
                    alist.append('### DISABLED Tag %s by %s (%s) %s' %
                                 (each.name, each.author.get_full_name(),
                                  each.author, each.created))
        loaders = self.get_parsed_loader()  # TODO redo
        alist.append('')  # avoid join errors if list is empty
        d = {
            'title': self.title,
            'generated': generated,
            'updated': updated,
            'loaders': loaders,
            'sources': SEP.join(alist)
        }
        assert (isinstance(src, Template))
        result = src.safe_substitute(d)
        f = open(self.server_path(remote), 'w')
        f.write(result)
        f.close()
        return
Beispiel #3
0
    def generate_global(
            self,
            a_user=None,
            remote=False
    ):  # generate the report ui.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = '\n'

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
        # opens ui.R template file
        filein = open(self.path_global_r_template)
        src = Template(filein.read())
        # document data
        generated = 'Generated on %s for user %s (%s)' % (
            self.created, self.author.get_full_name(), self.author)
        updated = 'Last updated on %s for user %s (%s)' % (
            aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by('order'):
                # base, ui_path, _ = self.get_tag_path(each)
                file_glob = open(each.folder_name + self.FILE_GLOBAL)
                alist.append('### from tag %s by %s (%s) %s\n%s' %
                             (each.name, each.author.get_full_name(),
                              each.author, each.created, file_glob.read()))
                file_glob.close()
        alist.append('')
        d = {
            'generated': generated,
            'updated': updated,
            'tag_global': SEP.join(alist)
        }
        # do the substitution
        result = src.substitute(d)
        f = open(self.global_path(remote), 'w')
        f.write(result)
        f.close()
        return
Beispiel #4
0
    def generate_global(self, a_user=None, remote=False):  # generate the report ui.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = "\n"

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
            # opens ui.R template file
        filein = open(self.path_global_r_template)
        src = Template(filein.read())
        # document data
        generated = "Generated on %s for user %s (%s)" % (self.created, self.author.get_full_name(), self.author)
        updated = "Last updated on %s for user %s (%s)" % (aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by("order"):
                # base, ui_path, _ = self.get_tag_path(each)
                file_glob = open(each.folder_name + self.FILE_GLOBAL)
                alist.append(
                    "### from tag %s by %s (%s) %s\n%s"
                    % (each.name, each.author.get_full_name(), each.author, each.created, file_glob.read())
                )
                file_glob.close()
        alist.append("")
        d = {"generated": generated, "updated": updated, "tag_global": SEP.join(alist)}
        # do the substitution
        result = src.substitute(d)
        f = open(self.global_path(remote), "w")
        f.write(result)
        f.close()
        return
Beispiel #5
0
    def generate_ui(self, a_user=None, remote=False):  # generate the report ui.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = "\n"
        SEP2 = ",\n  "

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
            # opens ui.R template file
        filein = open(self.path_ui_r_template)
        src = Template(filein.read())
        filein.close()
        # document data
        generated = "Generated on %s for user %s (%s)" % (self.created, self.author.get_full_name(), self.author)
        updated = "Last updated on %s for user %s (%s)" % (aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        tag_vars = list()
        menu_list = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by("order"):
                if each.enabled:
                    self.import_tag_res(each)
                    alist.append(
                        '### Tag %s by %s (%s) %s%ssource("%s",local = TRUE)'
                        % (
                            each.name,
                            each.author.get_full_name(),
                            each.author,
                            each.created,
                            SEP,
                            each.path_dashboard_body(remote),
                        )
                    )
                    tag_vars.append(each.get_name.upper())
                    menu_list.append(each.menu_entry)
                else:
                    alist.append(
                        "### DISABLED Tag %s by %s (%s) %s"
                        % (each.name, each.author.get_full_name(), each.author, each.created)
                    )
        alist.append("")
        menu_list.append("")
        d = {
            "title": self.title,
            "header": self.custom_header,
            "generated": generated,
            "updated": updated,
            "menu_items": SEP2.join(menu_list),
            "sources": SEP.join(alist),
            "tag_vars": SEP2.join(tag_vars),
        }
        # do the substitution
        result = src.substitute(d)
        f = open(self.ui_path(remote), "w")
        f.write(result)
        f.close()
        return
Beispiel #6
0
    def generate_ui(self,
                    a_user=None,
                    remote=False
                    ):  # generate the report ui.R file to include all the tags
        """
		Handle either LOCAL or REMOTE at once
		:param a_user:
		:type a_user:
		:param remote:
		:type remote:
		:return:
		:rtype:
		"""
        from string import Template
        import auxiliary as aux

        SEP = '\n'
        SEP2 = ',\n  '

        if a_user is None or not isinstance(a_user, (User, OrderedUser)):
            a_user = self.author
        # opens ui.R template file
        filein = open(self.path_ui_r_template)
        src = Template(filein.read())
        filein.close()
        # document data
        generated = 'Generated on %s for user %s (%s)' % (
            self.created, self.author.get_full_name(), self.author)
        updated = 'Last updated on %s for user %s (%s)' % (
            aux.date_t(), a_user.get_full_name(), a_user)
        alist = list()
        tag_vars = list()
        menu_list = list()
        if ShinyTag.objects.filter(attached_report=self).count() > 0:
            for each in self.shinytag_set.all().order_by('order'):
                if each.enabled:
                    self.import_tag_res(each)
                    alist.append(
                        '### Tag %s by %s (%s) %s%ssource("%s",local = TRUE)' %
                        (each.name, each.author.get_full_name(), each.author,
                         each.created, SEP, each.path_dashboard_body(remote)))
                    tag_vars.append(each.get_name.upper())
                    menu_list.append(each.menu_entry)
                else:
                    alist.append('### DISABLED Tag %s by %s (%s) %s' %
                                 (each.name, each.author.get_full_name(),
                                  each.author, each.created))
        alist.append('')
        menu_list.append('')
        d = {
            'title': self.title,
            'header': self.custom_header,
            'generated': generated,
            'updated': updated,
            'menu_items': SEP2.join(menu_list),
            'sources': SEP.join(alist),
            'tag_vars': SEP2.join(tag_vars),
        }
        # do the substitution
        result = src.substitute(d)
        f = open(self.ui_path(remote), 'w')
        f.write(result)
        f.close()
        return