当前位置: 首页>>代码示例>>Python>>正文


Python Book.create方法代码示例

本文整理汇总了Python中catalogue.models.Book.create方法的典型用法代码示例。如果您正苦于以下问题:Python Book.create方法的具体用法?Python Book.create怎么用?Python Book.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在catalogue.models.Book的用法示例。


在下文中一共展示了Book.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_none_indexed

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
    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',
            ])        
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: create_missing

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
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": '/',
    })
开发者ID:,项目名称:,代码行数:37,代码来源:

示例3: setUp

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
 def setUp(self):
     self.user = User.objects.create(username='tester')
     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)
开发者ID:,项目名称:,代码行数:13,代码来源:

示例4: test_both_indexed

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
    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))
开发者ID:,项目名称:,代码行数:44,代码来源:

示例5: setUp

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
 def setUp(self):
     self.user = User.objects.create(username='tester')
     self.text1 = get_fixture('chunk1.xml')
     self.book = Book.create(self.user, self.text1, slug='test-book')
开发者ID:fnp,项目名称:redakcja,代码行数:6,代码来源:test_publish.py

示例6: upload

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
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": '/',
    })
开发者ID:,项目名称:,代码行数:63,代码来源:

示例7: setUp

# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import create [as 别名]
 def setUp(self):
     self.user = User.objects.create(username='tester')
     self.book1 = Book.create(self.user, 'book 1', slug='book1')
     self.book2 = Book.create(self.user, 'book 2', slug='book2')
开发者ID:fnp,项目名称:redakcja,代码行数:6,代码来源:book.py


注:本文中的catalogue.models.Book.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。