def get_apps(cls):
     apps = []
     for appconfig in me.iter_djangoappconfigs():
         apps.append((appconfig.get_app_label(),
                      appconfig.make_crapp_class()))
         for modelconfig in appconfig.iter_modelconfigs():
             apps.append((modelconfig.get_unique_identifier(),
                          modelconfig.make_crapp_class()))
     return apps
示例#2
0
文件: django.py 项目: mbeacom/zimagi
    def get_installed_apps(self):
        apps = []
        for module_dir in self.get_module_dirs():
            data_dir = os.path.join(module_dir, 'data')

            if os.path.isdir(data_dir):
                for name in os.listdir(data_dir):
                    if name[0] != '_' and os.path.isdir(
                            os.path.join(
                                data_dir,
                                name)) and name not in ('base', 'mixins'):
                        apps.append("data.{}".format(name))

        logger.debug("Installed Django applications: {}".format(apps))
        return apps
示例#3
0
    def fetch(self, program):
        """ Get apps for a particular program from the Formstack API. """

        # get submissions from the API
        settings = program.formstackappsettings
        submissions = settings.form().submissions(use_cache=False)

        # parse submitted data and make model instances
        with transaction.atomic():
            apps = []
            for submission in submissions:
                try:
                    app = self.create_from_submission(submission, settings)
                    apps.append(app)
                except Exception as e:
                    logger.exception("Failed to get submissions: %s", e)

        return apps
示例#4
0
    def fetch(self, program):
        """ Get apps for a particular program from the Formstack API. """

        # get submissions from the API
        settings = program.formstackappsettings
        submissions = settings.form().submissions(use_cache=False)

        # parse submitted data and make model instances
        with transaction.atomic():
            apps = []
            for submission in submissions:
                try:
                    app = self.create_from_submission(submission, settings)
                    apps.append(app)
                except Exception as e:
                    logger.exception("Failed to get submissions: %s", e)

        return apps
示例#5
0
    def handle(self, *args, **options):
        # To preserve users' agents add -sa True when running command
        sa = False
        if options['saveagents']:
            sa = True

        apps = []
        apps.append(get_app('lrs'))
        apps.append(get_app('oauth_provider'))
        apps.append(get_app('adl_lrs'))

        # Clear app(db) data
        for app in apps:
            for model in app.get_models():
                if app.name.split(
                        '.')[0] == 'lrs' and model.__name__ == "Agent" and sa:
                    user_emails = [
                        "mailto:" + s
                        for s in User.objects.all().values_list('email',
                                                                flat=True)
                    ]
                    model.objects.exclude(mbox__in=user_emails).delete()
                    self.stdout.write(
                        "Deleted all %s objects from - %s except for the Agents associated with LRS users\n"
                        % (model.__name__, app.name.split('.')[0]))
                else:

                    # Chunking configuration
                    step = 20000
                    total = model.objects.count()
                    steps = total // step

                    # Clear in chunks
                    for i in xrange(steps):
                        chunk = model.objects.filter(**{
                            filter:
                            "%s__id__lte=%s" % (model.__name__, i * steps)
                        })
                        chunk.delete()

                    # Clear residuals
                    model.objects.all().delete()
                    self.stdout.write("Deleted all %s objects from - %s\n" %
                                      (model.__name__, app.name.split('.')[0]))

        # Clear cache data
        cache.clear()

        # Clear media folders
        for subdir, dirs, files in os.walk(settings.MEDIA_ROOT):
            for dr in dirs:
                for sd, ds, fs in os.walk(os.path.join(settings.MEDIA_ROOT,
                                                       dr)):
                    for f in fs:
                        os.remove(os.path.join(sd, f))

        self.stdout.write("Successfully cleared all data from the apps\n")
示例#6
0
    def handle(self, *args, **options):
        apps = []
        if options['all_applications']:
            apps = list(get_apps())

        for app_label in options['appnames']:
            app = get_app(app_label)
            if app not in apps:
                apps.append(app)

        self.verbose_names = options['verbose_names']
        self.exclude_modules = parse_file_or_list(options['exclude_modules'])
        self.exclude_models = parse_file_or_list(options['exclude_models'])
        self.exclude_fields = parse_file_or_list(options['exclude_columns'])
        self.inheritance = options['inheritance']
        self.sort_fields = options['sort_fields']
        self.bezier = options['bezier']

        ET.register_namespace('dia', 'http://www.lysator.liu.se/~alla/dia/')
        ns = {'dia': 'http://www.lysator.liu.se/~alla/dia/'}
        dom = ET.fromstring(get_empty_xml())
        self.layer = dom.find('dia:layer', namespaces=ns)

        app_colors = {}

        obj_num = 0
        obj_ref = []

        model_list = self.get_full_model_list(apps)
        for model in model_list:
            mdata = {
                'id': obj_num,
                'pos': (random.random() * 80, random.random() * 80),
                'name': self.get_model_name(model),
                'fields': self.get_model_fields(model),
                'color': get_model_color(app_colors, model),
                'port_idx': 0,
            }
            self.xml_make_table(mdata)
            obj_ref.append((obj_num, model, mdata))
            obj_num += 1

        for model in model_list:
            for rel in self.get_model_relations(model):
                try:
                    self.prepare_relation_stage2(obj_ref, rel, obj_num)
                    self.xml_make_relation(rel)
                    obj_num += 1
                except ModelNotFoundException:
                    pass
            if self.inheritance:
                for rel in self.get_model_inheritance(model):
                    try:
                        self.prepare_relation_stage2(obj_ref, rel, obj_num)
                        self.xml_make_relation(rel)
                    except ModelNotFoundException:
                        pass

        xml = six.b('<?xml version="1.0" encoding="UTF-8"?>') + \
            ET.tostring(dom, encoding='utf-8')

        outfile = options['outputfile']
        if outfile:
            if outfile[-4:] != '.dia':
                outfile += '.dia'
            with gzip.open(outfile, 'wb') as f:
                f.write(xml)
        else:
            self.stdout.write(xml.decode('utf-8'))
示例#7
0
    def handle(self, *args, **options):
        apps = []
        if options['all_applications']:
            apps = list(get_apps())

        for app_label in options['appnames']:
            app = get_app(app_label)
            if app not in apps:
                apps.append(app)

        self.verbose_names = options['verbose_names']
        self.exclude_modules = parse_file_or_list(options['exclude_modules'])
        self.exclude_models = parse_file_or_list(options['exclude_models'])
        self.exclude_fields = parse_file_or_list(options['exclude_columns'])
        self.inheritance = options['inheritance']
        self.sort_fields = options['sort_fields']
        self.bezier = options['bezier']

        ET.register_namespace('dia', 'http://www.lysator.liu.se/~alla/dia/')
        ns = {'dia': 'http://www.lysator.liu.se/~alla/dia/'}
        dom = ET.fromstring(get_empty_xml())
        self.layer = dom.find('dia:layer', namespaces=ns)

        app_colors = {}

        obj_num = 0
        obj_ref = []

        model_list = self.get_full_model_list(apps)
        for model in model_list:
            mdata = {
                'id': obj_num,
                'pos': (random.random() * 80, random.random() * 80),
                'name': self.get_model_name(model),
                'fields': self.get_model_fields(model),
                'color': get_model_color(app_colors, model),
                'port_idx': 0,
            }
            self.xml_make_table(mdata)
            obj_ref.append((obj_num, model, mdata))
            obj_num += 1

        for model in model_list:
            for rel in self.get_model_relations(model):
                try:
                    self.prepare_relation_stage2(obj_ref, rel, obj_num)
                    self.xml_make_relation(rel)
                    obj_num += 1
                except ModelNotFoundException:
                    pass
            if self.inheritance:
                for rel in self.get_model_inheritance(model):
                    try:
                        self.prepare_relation_stage2(obj_ref, rel, obj_num)
                        self.xml_make_relation(rel)
                    except ModelNotFoundException:
                        pass

        xml = six.b('<?xml version="1.0" encoding="UTF-8"?>') + \
            ET.tostring(dom, encoding='utf-8')

        outfile = options['outputfile']
        if outfile:
            if outfile[-4:] != '.dia':
                outfile += '.dia'
            with gzip.open(outfile, 'wb') as f:
                f.write(xml)
        else:
            self.stdout.write(xml.decode('utf-8'))