Example #1
0
    def test_none_indexed(self):
        self.book2 = Book.create(self.user, 'book 2', slug='book2')
        self.make_gallery(self.book1, {
            '0001_1l' : 'aa',
            '0001_2r' : 'bb',
            '0002_1l' : 'cc',
            '0002_2r' : 'dd',
            })

        self.make_gallery(self.book2, {
            '0001_1l' : 'ee',
            '0001_2r' : 'ff',
            '0002_1l' : 'gg',
            '0002_2r' : 'hh',
            })

        self.book1.append(self.book2)

        files = listdir(join(self.scandir, self.book1.gallery))
        files.sort()
        print files
        self.assertEqual(files, [
            '0-0001_1l',
            '0-0001_2r',
            '0-0002_1l',
            '0-0002_2r',
            '1-0001_1l',
            '1-0001_2r',
            '1-0002_1l',
            '1-0002_2r',
            ])        
Example #2
0
def create_missing(request, slug=None):
    if slug is None:
        slug = ''
    slug = slug.replace(' ', '-')

    if request.method == "POST":
        form = forms.DocumentCreateForm(request.POST, request.FILES)
        if form.is_valid():
            
            if request.user.is_authenticated():
                creator = request.user
            else:
                creator = None
            book = Book.create(
                text=form.cleaned_data['text'],
                creator=creator,
                slug=form.cleaned_data['slug'],
                title=form.cleaned_data['title'],
                gallery=form.cleaned_data['gallery'],
            )

            return http.HttpResponseRedirect(reverse("catalogue_book", args=[book.slug]))
    else:
        form = forms.DocumentCreateForm(initial={
                "slug": slug,
                "title": slug.replace('-', ' ').title(),
                "gallery": slug,
        })

    return render(request, "catalogue/document_create_missing.html", {
        "slug": slug,
        "form": form,

        "logout_to": '/',
    })
Example #3
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.book1 = Book.create(self.user, 'book 1', slug='book1')
     self.book1.chunk_set.create(number=2, title='Second chunk',
             slug='book1-2')
     c=self.book1[1]
     c.gallery_start=3
     
     self.scandir = join(settings.MEDIA_ROOT, settings.IMAGE_DIR)
     if not exists(self.scandir):
         makedirs(self.scandir)
Example #4
0
    def test_both_indexed(self):
        self.book2 = Book.create(self.user, 'book 2', slug='book2')
        self.book2.chunk_set.create(number=2, title='Second chunk of second book',
                slug='book2-2')

        c = self.book2[1]
        c.gallery_start = 3
        c.save()
        
        print "gallery starts:",self.book2[0].gallery_start, self.book2[1].gallery_start

        self.make_gallery(self.book1, {
            '1-0001_1l' : 'aa',
            '1-0001_2r' : 'bb',
            '1-0002_1l' : 'cc',
            '1-0002_2r' : 'dd',
            })

        self.make_gallery(self.book2, {
            '1-0001_1l' : 'dd', # the same, should not be moved
            '1-0001_2r' : 'ff',
            '2-0002_1l' : 'gg',
            '2-0002_2r' : 'hh',
            })

        self.book1.append(self.book2)

        files = listdir(join(self.scandir, self.book1.gallery))
        files.sort()
        print files
        self.assertEqual(files, [
            '1-0001_1l',
            '1-0001_2r',
            '1-0002_1l',
            '1-0002_2r',
            #            '2-0001_1l',
            '2-0001_2r',
            '3-0002_1l',
            '3-0002_2r',
            ])        

        self.assertEqual((4, 6), (self.book1[2].gallery_start, self.book1[3].gallery_start))
Example #5
0
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.text1 = get_fixture('chunk1.xml')
     self.book = Book.create(self.user, self.text1, slug='test-book')
Example #6
0
 def setUp(self):
     self.user = User.objects.create(username="******")
     text = get_fixture("chunk1.xml")
     Book.create(self.user, text, slug="test-book")
     self.title = "Do M***"
Example #7
0
def upload(request):
    if request.method == "POST":
        form = forms.DocumentsUploadForm(request.POST, request.FILES)
        if form.is_valid():
            from slugify import slugify

            if request.user.is_authenticated():
                creator = request.user
            else:
                creator = None

            zip = form.cleaned_data['zip']
            skipped_list = []
            ok_list = []
            error_list = []
            slugs = {}
            existing = [book.slug for book in Book.objects.all()]
            for filename in zip.namelist():
                if filename[-1] == '/':
                    continue
                title = os.path.basename(filename)[:-4]
                slug = slugify(title)
                if not (slug and filename.endswith('.xml')):
                    skipped_list.append(filename)
                elif slug in slugs:
                    error_list.append((filename, slug, _('Slug already used for %s' % slugs[slug])))
                elif slug in existing:
                    error_list.append((filename, slug, _('Slug already used in repository.')))
                else:
                    try:
                        zip.read(filename).decode('utf-8') # test read
                        ok_list.append((filename, slug, title))
                    except UnicodeDecodeError:
                        error_list.append((filename, title, _('File should be UTF-8 encoded.')))
                    slugs[slug] = filename

            if not error_list:
                for filename, slug, title in ok_list:
                    book = Book.create(
                        text=zip.read(filename).decode('utf-8'),
                        creator=creator,
                        slug=slug,
                        title=title,
                    )

            return render(request, "catalogue/document_upload.html", {
                "form": form,
                "ok_list": ok_list,
                "skipped_list": skipped_list,
                "error_list": error_list,

                "logout_to": '/',
            })
    else:
        form = forms.DocumentsUploadForm()

    return render(request, "catalogue/document_upload.html", {
        "form": form,

        "logout_to": '/',
    })
Example #8
0
File: book.py Project: fnp/redakcja
 def setUp(self):
     self.user = User.objects.create(username='******')
     self.book1 = Book.create(self.user, 'book 1', slug='book1')
     self.book2 = Book.create(self.user, 'book 2', slug='book2')