Exemple #1
0
    def handle(self, *args, **options):
        try:
            in_data = json.load(open(options['filename_json'], "r"))
            user_portal = Portal.objects.get(owner=(User.objects.get(
                username=options['username']) if options['username'] else None
                                                    ))

        except IOError as e:
            raise CommandError(e.message)
        except ValueError:
            raise CommandError(_("Some lines of the file are not JSON"))
        except ObjectDoesNotExist:
            raise CommandError(_("User or portal not found"))

        root = Node(parent=user_portal.root)
        root.save()
        make_problemtree(in_data, root, self.stdout)
Exemple #2
0
    def handle(self, *args, **options):
        try:
            in_data = json.load(open(options['filename_json'], "r"))
            user_portal = \
                Portal.objects.get(
                    owner=(User.objects.get(
                        username=options['username']) if options['username'] else None))

        except IOError as e:
            raise CommandError(e.message)
        except ValueError:
            raise CommandError(_("Some lines of the file are not JSON"))
        except ObjectDoesNotExist:
            raise CommandError(_("User or portal not found"))

        root = Node(parent=user_portal.root)
        root.save()
        make_problemtree(in_data, root, self.stdout)
Exemple #3
0
    def handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError(_("Expected at least one argument"))
        if len(args) > 2:
            raise CommandError(_("Expected two arguments at most"))

        try:
            in_data = json.load(open(args[0], "r"))
            user_portal = \
                Portal.objects.get(
                    owner=(User.objects.get(
                        username=args[1]) if len(args) == 2 else None))

        except IOError as e:
            raise CommandError(e.message)
        except ValueError:
            raise CommandError(_("Some lines of the file are not JSON"))
        except ObjectDoesNotExist:
            raise CommandError(_("User or portal not found"))

        root = Node(parent=user_portal.root)
        root.save()
        make_problemtree(in_data, root, self.stdout)
Exemple #4
0
def make_problemtree(tree, root, stdout):
    for family in tree:
        family_node = Node(parent=root)
        family_node.short_name = family['name']
        family_node.full_name = family['long_name']
        family_node.panel_code = family['description']
        family_node.save()

        for edition in family['editions']:
            edition_node = Node(parent=family_node)
            edition_node.short_name = edition['name']
            edition_node.full_name = edition['long_name']

            try:
                edition_tag = Tag.objects.get(
                    name=edition['tag']).problems.all()
            except ObjectDoesNotExist:
                stdout.write(
                    'Ignoring edition with tag {}'.format(edition['tag']))
                edition_node.panel_code = ''
                edition_node.save()
                continue

            edition_node.panel_code = ''

            for header, tasks in edition['tasks']:
                l = []
                for task in tasks:
                    try:
                        taskname_tag = Tag.objects.get(
                            name=task).problems.all()

                        try:
                            task_obj = (edition_tag & taskname_tag)[0]
                        except IndexError:
                            stdout.write(
                                'Ignoring task: {} from {}, no such task in DB'
                                .format(task, edition['tag']))
                            continue

                        l.append(reverse(problem_site_view, kwargs={
                                'site_key': task_obj.problemsite.url_key}))
                    except ObjectDoesNotExist:
                        stdout.write('Ignoring task: {} from {}, task\'s \
                        tag does not exist'.format(task, edition['tag']))

                edition_node.panel_code += u'[[ProblemTable:{}|{}]]\n\n'\
                    .format(header, u';'.join(l))

            edition_node.save()

    root.short_name = u'problemset'
    root.full_name = u'Problem Tree'
    root.panel_code = u'All of the public tasks are (should be) here.'
    root.save()