Beispiel #1
0
    def test_search(self):
        series, created = Series.from_dict({"name": "Secret Files"})
        self.assertTrue(created)
        self.assertIsNotNone(series.id)

        series, created = Series.from_dict({"name": "Ran"})
        self.assertTrue(created)
        self.assertIsNotNone(series.id)

        series, created = Series.from_dict({"name": "Random Files"})
        self.assertTrue(created)
        self.assertIsNotNone(series.id)

        self.assertEquals(3, Series.objects.all().count())
        self.assertEquals(2, Series.search("files").count())
        self.assertEquals(2, Series.search("ran").count())
Beispiel #2
0
def _series(args: Namespace, file: TextIO = sys.stdout):
    series: Optional[Series] = None
    if args.subparser == "add":
        series, created = Series.from_dict({
            "name":
            args.name,
            "links":
            [Link.get_or_create(link).to_dict() for link in args.link],
        })
        if created:
            stdout.write(
                _('Successfully added series "%(name)s" with id "%(pk)d".') % {
                    "name": series.name,
                    "pk": series.pk
                },
                "=",
                file=file,
            )
            series.print(file)
        else:
            stdout.write(
                _('The series "%(name)s" already exists with id "%(pk)d", aborting...'
                  ) % {
                      "name": series.name,
                      "pk": series.pk
                  },
                "",
                file=file,
            )
    elif args.subparser == "delete":
        series = Series.get(args.series)
        if series:
            series.delete()
            stdout.write(
                _('Successfully deleted series with id "%(pk)d".') %
                {"pk": series.pk},
                "",
                file=file,
            )
        else:
            stdout.write(_("No series found."), "", file=file)
    elif args.subparser == "edit":
        series = Series.get(args.series)
        if series:
            series.edit(args.field, args.value)
            stdout.write(
                _('Successfully edited series "%(name)s" with id "%(pk)d".') %
                {
                    "name": series.name,
                    "pk": series.pk
                },
                "",
                file=file,
            )
            series.print(file)
        else:
            stdout.write(_("No series found."), "", file=file)
    elif args.subparser == "info":
        series = Series.get(args.series)
        if series:
            series.print(file)
        else:
            stdout.write(_("No series found."), "", file=file)
    elif args.subparser == "list":
        if args.search:
            series = Series.search(args.search)
        else:
            series = Series.objects.all()
        stdout.write(
            [_("Id"), _("Name"), _("Number of books")],
            "=", [0.05, 0.8],
            file=file)
        for i, has_next in lookahead(series):
            stdout.write(
                [i.id, i.name, i.books.count()],
                "_" if has_next else "=",
                [0.05, 0.8],
                file=file,
            )