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


Python models.Submission类代码示例

本文整理汇总了Python中demos.models.Submission的典型用法代码示例。如果您正苦于以下问题:Python Submission类的具体用法?Python Submission怎么用?Python Submission使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: build_submission

def build_submission(creator):
    now = str(datetime.datetime.now())

    s = Submission(title='Hello world' + now, slug='hello-world' + now,
        description='This is a hello world demo', hidden=False,
        creator=creator)
    s.save()

    return s
开发者ID:gerv,项目名称:kuma,代码行数:9,代码来源:__init__.py

示例2: _build_hidden_submission

    def _build_hidden_submission(self, slug):
        now = str(datetime.datetime.now())

        s = Submission(title='Hidden submission 1' + now, slug=slug + now,
            description='This is a hidden demo', hidden=True,
            creator=self.other_user)
        s.save()

        return s
开发者ID:aregee,项目名称:kuma,代码行数:9,代码来源:test_models.py

示例3: build_hidden_submission

def build_hidden_submission(creator, slug='hidden-world'):
    now = str(datetime.datetime.now())

    s = Submission(title='Hidden submission 1' + now, slug=slug + now,
        description='This is a hidden demo', hidden=True,
        creator=creator)
    s.save()

    return s
开发者ID:gerv,项目名称:kuma,代码行数:9,代码来源:__init__.py

示例4: test_censored_demo_files_are_deleted

    def test_censored_demo_files_are_deleted(self):
        """Demo files should be deleted when the demo is censored."""
        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile(s.demo_package.path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        s.censor(url="http://example.com/censored-explanation")

        ok_(not isfile(s.demo_package.path))
        ok_(not isfile('%s/index.html' % path))
        ok_(not isfile('%s/css/main.css' % path))
        ok_(not isfile('%s/js/main.js' % path))
        ok_(not isdir(path))
开发者ID:AprilMorone,项目名称:kuma,代码行数:35,代码来源:test_models.py

示例5: test_demo_deletion

    def test_demo_deletion(self):
        """Ensure that demo files are deleted along with submission record"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        s.delete()

        ok_(not isfile('%s/index.html' % path))
        ok_(not isfile('%s/css/main.css' % path))
        ok_(not isfile('%s/js/main.js' % path))
        ok_(not isdir(path))
开发者ID:AprilMorone,项目名称:kuma,代码行数:34,代码来源:test_models.py

示例6: save_valid_submission

def save_valid_submission(title="hello world", desc="This is a hello world demo"):
    testuser = User.objects.get(username="testuser")
    s = Submission(title=title, slug=slugify(title), description=desc, summary=desc, creator=testuser)
    fout = StringIO()
    zf = zipfile.ZipFile(fout, "w")
    zf.writestr("index.html", """<html> </html>""")
    zf.close()
    s.demo_package.save("play_demo.zip", ContentFile(fout.getvalue()))
    s.screenshot_1.save(
        "screenshot_1.jpg", ContentFile(open("%s/fixtures/screenshot_1.png" % (dirname(dirname(__file__)),)).read())
    )
    s.save()
    return s
开发者ID:nogsantos,项目名称:kuma,代码行数:13,代码来源:test_models.py

示例7: build_hidden_submission

def build_hidden_submission(creator, slug="hidden-world"):
    now = str(datetime.datetime.now())

    s = Submission(
        title="Hidden submission 1" + now,
        slug=slug + now,
        description="This is a hidden demo",
        hidden=True,
        creator=creator,
    )
    s.save()

    return s
开发者ID:Boldewyn,项目名称:kuma,代码行数:13,代码来源:__init__.py

示例8: build_submission

def build_submission(creator):
    now = str(datetime.datetime.now())

    s = Submission(
        title="Hello world" + now,
        slug="hello-world" + now,
        description="This is a hello world demo",
        hidden=False,
        creator=creator,
    )
    s.save()

    return s
开发者ID:Boldewyn,项目名称:kuma,代码行数:13,代码来源:__init__.py

示例9: save_valid_submission

def save_valid_submission(title='hello world'):
    testuser = User.objects.get(username='testuser')
    s = Submission(title=title, slug=slugify(title),
        description='This is a hello world demo',
        creator=testuser)
    fout = StringIO()
    zf = zipfile.ZipFile(fout, 'w')
    zf.writestr('index.html', """<html> </html>""")
    zf.close()
    s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
    s.screenshot_1.save('screenshot_1.jpg', ContentFile(open(
        '%s/fixtures/screenshot_1.png' % ( dirname(dirname(__file__)), ) ).read()))
    s.save()
    return s
开发者ID:LucianU,项目名称:kuma,代码行数:14,代码来源:test_models.py

示例10: get_queryset

 def get_queryset(self):
     submissions = Submission.objects.all_sorted(
         self.request.GET.get('sort', 'created')
         )
     if not Submission.allows_listing_hidden_by(self.request.user):
         submissions = submissions.exclude(hidden=True)
     return submissions
开发者ID:kyoshino,项目名称:kuma,代码行数:7,代码来源:views.py

示例11: test_demo_html_normalized

    def test_demo_html_normalized(self):
        """Ensure a demo.html in zip file is normalized to index.html when unpacked"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        rmtree(path)
开发者ID:LucianU,项目名称:kuma,代码行数:29,代码来源:test_models.py

示例12: test_demo_html_normalized

    def test_demo_html_normalized(self):
        """Ensure a demo.html in zip file is normalized to index.html when unpacked"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, "w")
        zf.writestr("demo.html", """<html></html""")
        zf.writestr("css/main.css", "h1 { color: red }")
        zf.writestr("js/main.js", 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(
            title="Hello world",
            slug="hello-world",
            description="This is a hello world demo",
            tags="hello,world,demo,play",
            creator=self.user,
        )

        s.demo_package.save("play_demo.zip", ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace(".zip", "")

        ok_(isdir(path))
        ok_(isfile("%s/index.html" % path))
        ok_(isfile("%s/css/main.css" % path))
        ok_(isfile("%s/js/main.js" % path))

        rmtree(path)
开发者ID:fwenzel,项目名称:mdn,代码行数:33,代码来源:tests.py

示例13: test_demo_unicode_filenames

    def test_demo_unicode_filenames(self):
        """Bug 741660: Demo package containing filenames with non-ASCII
        characters works"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/예제.css', 'h1 { color: red }')
        zf.writestr('js/示例.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile((u'%s/index.html' % path).encode('utf-8')))
        ok_(isfile((u'%s/css/예제.css' % path).encode('utf-8')))
        ok_(isfile((u'%s/js/示例.js' % path).encode('utf-8')))

        rmtree(path)
开发者ID:AprilMorone,项目名称:kuma,代码行数:30,代码来源:test_models.py

示例14: test_demo_package_no_files

    def test_demo_package_no_files(self):
        """Demo package with no files is invalid"""

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            video_url='http://www.youtube.com/watch?v=dQw4w9WgXcQ',
            creator=self.user)

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.close()
        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))

        try:
            s.clean()
            ok_(False, "There should be a validation exception")
        except ValidationError, e:
            ok_('ZIP file contains no acceptable files' in e.messages)
开发者ID:LucianU,项目名称:kuma,代码行数:18,代码来源:test_models.py

示例15: home

def home(request):
    """Home page."""

    featured_submissions = Submission.objects.order_by('-modified').filter(featured=True)
    if not Submission.allows_listing_hidden_by(request.user):
        featured_submissions = featured_submissions.exclude(hidden=True)

    submissions = Submission.objects.all_sorted(request.GET.get('sort', 'created'))
    if not Submission.allows_listing_hidden_by(request.user):
        submissions = submissions.exclude(hidden=True)

    return object_list(request, submissions,
        extra_context={
            'featured_submission_list': featured_submissions,
        },
        paginate_by=DEMOS_PAGE_SIZE, allow_empty=True,
        template_loader=template_loader,
        template_object_name='submission',
        template_name='demos/home.html') 
开发者ID:lmorchard,项目名称:mdn,代码行数:19,代码来源:views.py


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