コード例 #1
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_import(request):
    if request.method == 'POST':
        try:
            # Calls the theme importing function to save theme, templates and static files in the right places
            theme = import_theme(request.FILES['file'])

            # Calls the signal after static files changed
            theme_static_files_changed.send(sender=request.site, theme=theme, request=request,
                    items=list(theme['static_files'].exclude(file=None)))

            # Final message and redirecting
            request.info(_('File imported with success!'))
            url_redirect = reverse('themes_theme', kwargs={'name': theme['name']})
        except ValueError as e:
            request.info(e)
            url_redirect = reverse('themes_home')
    return HttpResponseRedirect(url_redirect)
コード例 #2
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_preview(request, name=None):
    if name:
        resp = HttpResponseRedirect('/')
        resp.set_cookie(app_settings.CURRENT_THEME_COOKIE, name)
        request.info(_('Theme "%s" set to preview.')%name)
    else:
        resp = HttpResponseRedirect(reverse('themes_home'))
        resp.delete_cookie(app_settings.CURRENT_THEME_COOKIE)
        request.info(_('Disabled the theme preview.'))
    return resp
コード例 #3
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_save_as(request, theme):
    if request.method == 'POST':
        # Theme
        new_theme = Theme()
        new_theme['verbose_name'] = request.POST['name']
        new_name = slugify(new_theme['verbose_name'])
        counter = 0
        while Theme.query().filter(name=new_name).exclude(pk=theme['pk']).count():
            counter += 1
            new_name = '%s-%s'%(slugify(theme['verbose_name']), counter)
        new_theme['name'] = new_name
        new_theme.save()

        # Templates
        for tpl in theme['templates']:
            new_tpl, new = new_theme['templates'].get_or_create(name=tpl['name'])
            new_tpl['notes'] = tpl['notes']
            new_tpl['content'] = tpl['content']
            new_tpl['engine'] = tpl['engine']
            new_tpl.save()

        """
        # FIXME
        # Static files
        for sf in theme['static_files']:
            try:
                new_sf, new = new_theme['static_files'].get_or_create(name=sf['name'])
                new_sf.url = sf.url
                new_sf.mimetype = sf.mimetype
                new_sf.save()

                if sf.file:
                    # Finds a name for the new file
                    root = sf.file.path.replace(sf.file.name, '')
                    name, ext = os.path.splitext(sf.file.name)
                    while os.path.exists(root + name + ext):
                        name += '_'

                    # Reads the old file to make a ContentFile instance
                    fp = file(sf.file.path)
                    content = ContentFile(fp.read())
                    fp.close()
                    
                    # Saves the new file for the new static file object
                    new_sf.file.save(name+ext, content)
            except BaseException as e:
                print(sf, e.__class__, e)
                raise
        """
        ret = {'new_url': reverse('themes_theme', kwargs={'name': new_theme['name']})}
    else:
        ret = {'result': 'error'}
    
    return JsonResponse(ret)
コード例 #4
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_delete(request, theme):
    # Templates first
    theme['templates'].delete()

    # Delete static files and their phisical files
    for sf in theme['static_files']:
        sf['file'].delete()
        sf.delete()

    name = theme['name']

    # Finally, deletes the theme
    theme.delete()

    request.info(_('Theme "%s" deleted.')%unicode(name))
    return HttpResponseRedirect(reverse('themes_home'))
コード例 #5
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_rename(request, theme):
    if request.method == 'POST':
        # Sets a new verbose name and its slugified name
        theme['verbose_name'] = request.POST['name']
        new_name = slugify(theme['verbose_name'])
        counter = 0
        while Theme.query().filter(name=new_name).exclude(pk=theme['pk']).count():
            counter += 1
            new_name = '%s-%s'%(slugify(theme['verbose_name']), counter)
        theme['name'] = new_name
        theme.save()

        ret = {'new_url': reverse('themes_theme', kwargs={'name': theme['name']})}
    else:
        ret = {'result': 'error'}
    
    # Returns a JSON with new URL to redirect it
    return JsonResponse(ret)
コード例 #6
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def home(request):
    themes = Theme.query().order_by('verbose_name')
    previewing = request.COOKIES.get(app_settings.CURRENT_THEME_COOKIE, None)

    if request.POST.get('name', None):
        verbose_name = request.POST['name']
        name = slugify(request.POST['name'])
        counter = 0
        while Theme.query().filter(name=name).count():
            counter += 1
            name = '%s-%s'%(slugify(request.POST['name']), counter)
        theme = Theme.query().create(name=name, verbose_name=verbose_name)

        request.warning(_('New theme "%s" created.'))
        return HttpResponseRedirect(reverse('themes_theme', kwargs={'name': theme['name']}))
    return render_to_response(request,
            'themes/home.html',
            {'themes':themes, 'previewing':previewing},
            )
コード例 #7
0
ファイル: views.py プロジェクト: avelino/votacao_paredao_bbb
def theme_set_default(request, theme):
    theme['is_default'] = True
    theme.save()
    request.info(_('Theme "%s" set as default.')%theme['name'])
    return HttpResponseRedirect(reverse('themes_theme', kwargs={'name':theme['name']}))