示例#1
0
def original_templates(request, template_name="theme_editor/original_templates.html"):

    selected_theme = request.GET.get("theme_edit", get_theme())
    if not is_valid_theme(selected_theme):
        raise Http404(_('Specified theme does not exist'))
    if is_theme_read_only(selected_theme):
        raise Http403

    app = request.GET.get("app", None)

    current_dir = request.GET.get("dir", '')
    if current_dir:
        current_dir = current_dir.replace('\\', '/')
        current_dir = current_dir.strip('/')
        current_dir = current_dir.replace('////', '/')
        current_dir = current_dir.replace('///', '/')
        current_dir = current_dir.replace('//', '/')

    # if current_dir is a directory then append the
    # trailing slash so we can get the dirname below

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'original templates'
    current_dir_split = current_dir.split('/')
    if len(current_dir_split) > 1:
        prev_dir_name = current_dir_split[-2]
        current_dir_split.pop()
        prev_dir = '/'.join(current_dir_split)
    elif not current_dir_split[0]:
        prev_dir = ''

    if app in app_templates:
        root = app_templates[app]
    elif is_valid_theme(app):
        root = os.path.join(get_theme_root(app), 'templates')
    else:
        if '/' in app and app.split('/')[0] == 'builtin':
            builtin_base_name = app.split('/')[1]
            root = os.path.join(settings.TENDENCI_ROOT, "themes/{}/templates".format(builtin_base_name))
        else:
            raise Http404(_('Specified theme or app does not exist'))

    if not is_valid_path(root, current_dir):
        raise Http403

    dirs = get_dir_list(root, current_dir)
    files, non_editable_files = get_file_list(root, current_dir)
    return render_to_resp(request=request, template_name=template_name, context={
        'current_theme': selected_theme,
        'app': app,
        'current_dir': current_dir,
        'prev_dir_name': prev_dir_name,
        'prev_dir': prev_dir,
        'dirs': dirs,
        'files': files,
        'non_editable_files': non_editable_files,
    })
示例#2
0
def original_templates(request,
                       app=None,
                       template_name="theme_editor/original_templates.html"):

    current_dir = request.GET.get("dir", '')
    if current_dir:
        current_dir = current_dir.replace('\\', '/')
        current_dir = current_dir.strip('/')
        current_dir = current_dir.replace('////', '/')
        current_dir = current_dir.replace('///', '/')
        current_dir = current_dir.replace('//', '/')

    # if current_dir is a directory then append the
    # trailing slash so we can get the dirname below

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'original templates'
    current_dir_split = current_dir.split('/')
    if len(current_dir_split) > 1:
        prev_dir_name = current_dir_split[-2]
        current_dir_split.pop()
        prev_dir = '/'.join(current_dir_split)
    elif not current_dir_split[0]:
        prev_dir = ''

    root = os.path.join(settings.TENDENCI_ROOT, "templates")
    if app:
        root = app_templates[app]

    dirs = get_dir_list(current_dir, ROOT_DIR=root)
    files, non_editable_files = get_file_list(current_dir, ROOT_DIR=root)
    return render_to_resp(request=request,
                          template_name=template_name,
                          context={
                              'app': app,
                              'current_dir': current_dir,
                              'prev_dir_name': prev_dir_name,
                              'prev_dir': prev_dir,
                              'dirs': dirs,
                              'files': files,
                              'non_editable_files': non_editable_files
                          })
示例#3
0
def original_templates(request, app=None, template_name="theme_editor/original_templates.html"):

    current_dir = request.GET.get("dir", "")
    if current_dir:
        current_dir = current_dir.replace("\\", "/")
        current_dir = current_dir.strip("/")
        current_dir = current_dir.replace("////", "/")
        current_dir = current_dir.replace("///", "/")
        current_dir = current_dir.replace("//", "/")

    # if current_dir is a directory then append the
    # trailing slash so we can get the dirname below

    # get the previous directory name and path
    prev_dir = "/"
    prev_dir_name = "original templates"
    current_dir_split = current_dir.split("/")
    if len(current_dir_split) > 1:
        prev_dir_name = current_dir_split[-2]
        current_dir_split.pop()
        prev_dir = "/".join(current_dir_split)
    elif not current_dir_split[0]:
        prev_dir = ""

    root = os.path.join(settings.TENDENCI_ROOT, "templates")
    if app:
        root = app_templates[app]

    dirs = get_dir_list(current_dir, ROOT_DIR=root)
    files, non_editable_files = get_file_list(current_dir, ROOT_DIR=root)
    return render_to_response(
        template_name,
        {
            "app": app,
            "current_dir": current_dir,
            "prev_dir_name": prev_dir_name,
            "prev_dir": prev_dir,
            "dirs": dirs,
            "files": files,
            "non_editable_files": non_editable_files,
        },
        context_instance=RequestContext(request),
    )
示例#4
0
def original_templates(request, app=None, template_name="theme_editor/original_templates.html"):

    current_dir = request.GET.get("dir", '')
    if current_dir:
        current_dir = current_dir.replace('\\', '/')
        current_dir = current_dir.strip('/')
        current_dir = current_dir.replace('////', '/')
        current_dir = current_dir.replace('///', '/')
        current_dir = current_dir.replace('//', '/')

    # if current_dir is a directory then append the
    # trailing slash so we can get the dirname below

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'original templates'
    current_dir_split = current_dir.split('/')
    if len(current_dir_split) > 1:
        prev_dir_name = current_dir_split[-2]
        current_dir_split.pop()
        prev_dir = '/'.join(current_dir_split)
    elif not current_dir_split[0]:
        prev_dir = ''

    root = os.path.join(settings.TENDENCI_ROOT, "templates")
    if app:
        root = app_templates[app]

    dirs = get_dir_list(current_dir, ROOT_DIR=root)
    files, non_editable_files = get_file_list(current_dir, ROOT_DIR=root)
    return render_to_response(template_name, {
        'app': app,
        'current_dir': current_dir,
        'prev_dir_name': prev_dir_name,
        'prev_dir': prev_dir,
        'dirs': dirs,
        'files': files,
        'non_editable_files': non_editable_files
    }, context_instance=RequestContext(request))
示例#5
0
def edit_file(request,
              form_class=FileForm,
              template_name="theme_editor/index.html"):

    selected_theme = request.GET.get("theme_edit", get_theme())
    if not is_valid_theme(selected_theme):
        raise Http404(_('Specified theme does not exist'))

    # get the default file and clean up any input
    default_file = request.GET.get("file", DEFAULT_FILE)
    if default_file:
        default_file = default_file.replace('\\', '/')
        default_file = default_file.strip('/')
        default_file = default_file.replace('////', '/')
        default_file = default_file.replace('///', '/')
        default_file = default_file.replace('//', '/')

    theme_root = get_theme_root(selected_theme)
    if not is_valid_path(theme_root, default_file):
        raise Http403

    theme_read_only = is_theme_read_only(selected_theme)

    if request.is_ajax() and request.method == "POST":
        if theme_read_only:
            raise Http403
        file_form = form_class(request.POST)
        response_status = 'FAIL'
        response_message = _('Cannot update file.')
        if file_form.is_valid():
            if file_form.save(theme_root, selected_theme, default_file,
                              request):
                response_status = 'SUCCESS'
                response_message = str(_('Your changes have been saved.'))
                EventLog.objects.log()
        response = json.dumps({
            'status': response_status,
            'message': response_message
        })
        return HttpResponse(response, content_type='application/json')

    is_file = os.path.isfile(os.path.join(theme_root, default_file))
    is_dir = os.path.isdir(os.path.join(theme_root, default_file))
    if is_file:
        pass
    elif is_dir:
        # if default_file is a directory then append the
        # trailing slash so we can get the dirname below
        default_file = '%s/' % default_file
    else:
        # if the default_file is not a directory or file within
        # the themes folder then return a 404
        raise Http404(
            _("Custom template not found. Make sure you've copied over the themes to the THEME_DIR."
              ))

    # get the current file name
    current_file = os.path.basename(default_file)

    # get file ext
    name = current_file.split('/')[-1]
    ext = name.split('.')[-1]
    stylesheets = ['css', 'less']

    # get the present working directory
    # and make sure they cannot list root
    pwd = os.path.dirname(default_file)
    if pwd == '/':
        pwd = ''
    # make sure the path is still valid after stripping off the file name
    if not is_valid_path(theme_root, pwd):
        raise Http403

    current_file_path = os.path.join(pwd, current_file)

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'theme base'
    pwd_split = pwd.split('/')
    if len(pwd_split) > 1:
        prev_dir_name = pwd_split[-2]
        pwd_split.pop()
        prev_dir = '/'.join(pwd_split)
    elif not pwd_split[0]:
        prev_dir = ''

    # get the directory list
    dirs = get_dir_list(theme_root, pwd)

    # get the file list
    files, non_editable_files = get_file_list(theme_root, pwd)

    all_files_folders = get_all_files_list(theme_root, selected_theme)

    # non-deletable files
    non_deletable_files = [
        'homepage.html', 'default.html', 'footer.html', 'header.html',
        'sidebar.html', 'nav.html', 'styles.less', 'styles.css'
    ]

    # get the number of themes in the themes directory on the site
    theme_count = len([i for i in theme_choices()])

    # get a list of revisions
    archives = ThemeFileVersion.objects.filter(
        relative_file_path=current_file_path).order_by("-create_dt")

    # New templates created by clicking the New Template" button are blank.
    # Add a space for the blank template to make it editable.
    content = get_file_content(theme_root, selected_theme,
                               current_file_path) or ' '
    file_form = form_class({'content': content})
    theme_form = ThemeSelectForm(initial={'theme_edit': selected_theme})

    return render_to_resp(request=request,
                          template_name=template_name,
                          context={
                              'file_form': file_form,
                              'theme_form': theme_form,
                              'current_theme': selected_theme,
                              'current_file_path': current_file_path,
                              'current_file': current_file,
                              'prev_dir_name': prev_dir_name,
                              'prev_dir': prev_dir,
                              'pwd': pwd,
                              'dirs': dirs,
                              'files': files,
                              'non_editable_files': non_editable_files,
                              'non_deletable_files': non_deletable_files,
                              'theme_count': theme_count,
                              'archives': archives,
                              'is_file': is_file,
                              'is_dir': is_dir,
                              'theme_read_only': theme_read_only,
                              'can_copy_theme':
                              (not is_base_theme(selected_theme)),
                              'all_files_folders': all_files_folders,
                              'ext': ext,
                              'stylesheets': stylesheets,
                          })
示例#6
0
def edit_file(request,
              form_class=FileForm,
              template_name="theme_editor/index.html"):

    if not has_perm(request.user, 'theme_editor.view_themefileversion'):
        raise Http403

    selected_theme = request.GET.get("theme_edit", get_theme())
    original_theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR,
                                       selected_theme)
    if settings.USE_S3_THEME:
        theme_root = os.path.join(settings.THEME_S3_PATH, selected_theme)
    else:
        theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)

    # get the default file and clean up any input
    default_file = request.GET.get("file", DEFAULT_FILE)

    if default_file:
        default_file = default_file.replace('\\', '/')
        default_file = default_file.strip('/')
        default_file = default_file.replace('////', '/')
        default_file = default_file.replace('///', '/')
        default_file = default_file.replace('//', '/')

    is_file = qstr_is_file(default_file, ROOT_DIR=theme_root)
    is_dir = qstr_is_dir(default_file, ROOT_DIR=theme_root)

    if is_file:
        pass
    elif is_dir:
        # if default_file is a directory then append the
        # trailing slash so we can get the dirname below
        default_file = '%s/' % default_file
    else:
        # if the default_file is not a directory or file within
        # the themes folder then return a 404
        raise Http404(
            "Custom template not found. Make sure you've copied over the themes to the THEME_DIR."
        )

    # get the current file name
    current_file = os.path.basename(default_file)

    # get file ext
    name = current_file.split('/')[-1]
    ext = name.split('.')[-1]
    stylesheets = ['css', 'less']

    # get the present working directory
    # and make sure they cannot list root
    pwd = os.path.dirname(default_file)
    if pwd == '/':
        pwd = ''

    current_file_path = os.path.join(pwd, current_file)

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'theme base'
    pwd_split = pwd.split('/')
    if len(pwd_split) > 1:
        prev_dir_name = pwd_split[-2]
        pwd_split.pop()
        prev_dir = '/'.join(pwd_split)
    elif not pwd_split[0]:
        prev_dir = ''

    # get the direcory list
    dirs = get_dir_list(pwd, ROOT_DIR=theme_root)

    # get the file list
    files, non_editable_files = get_file_list(pwd, ROOT_DIR=theme_root)

    all_files_folders = get_all_files_list(ROOT_DIR=theme_root)

    # non-deletable files
    non_deletable_files = [
        'homepage.html', 'default.html', 'footer.html', 'header.html',
        'sidebar.html', 'nav.html', 'styles.less', 'styles.css'
    ]

    # get the number of themes in the themes directory on the site
    theme_choices = [i for i in theme_choice_list()]
    theme_count = len(theme_choices)

    # get a list of revisions
    archives = ThemeFileVersion.objects.filter(
        relative_file_path=default_file).order_by("-create_dt")

    if request.is_ajax() and request.method == "POST":
        file_form = form_class(request.POST)
        response_status = 'FAIL'
        response_message = 'Cannot update file.'
        if file_form.is_valid():
            if file_form.save(request,
                              default_file,
                              ROOT_DIR=theme_root,
                              ORIG_ROOT_DIR=original_theme_root):
                response_status = 'SUCCESS'
                response_message = 'Your changes have been saved.'
                EventLog.objects.log()

        response = json.dumps({
            'status': response_status,
            'message': response_message
        })
        return HttpResponse(response, mimetype="application/json")

    content = get_file_content(default_file, ROOT_DIR=theme_root)
    file_form = form_class({"content": content, "rf_path": default_file})

    theme_form = ThemeSelectForm(initial={'theme_edit': selected_theme})

    return render_to_response(template_name, {
        'file_form': file_form,
        'theme_form': theme_form,
        'current_theme': selected_theme,
        'current_file_path': current_file_path,
        'current_file': current_file,
        'prev_dir_name': prev_dir_name,
        'prev_dir': prev_dir,
        'pwd': pwd,
        'dirs': dirs,
        'files': files,
        'non_editable_files': non_editable_files,
        'non_deletable_files': non_deletable_files,
        'theme_count': theme_count,
        'archives': archives,
        'is_file': is_file,
        'is_dir': is_dir,
        'all_files_folders': all_files_folders,
        'ext': ext,
        'stylesheets': stylesheets
    },
                              context_instance=RequestContext(request))
示例#7
0
def edit_file(request, form_class=FileForm, template_name="theme_editor/index.html"):

    if not has_perm(request.user, 'theme_editor.view_themefileversion'):
        raise Http403

    selected_theme = request.GET.get("theme_edit", get_theme())
    original_theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)
    if settings.USE_S3_THEME:
        theme_root = os.path.join(settings.THEME_S3_PATH, selected_theme)
    else:
        theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)

    # get the default file and clean up any input
    default_file = request.GET.get("file", DEFAULT_FILE)

    if default_file:
        default_file = default_file.replace('\\', '/')
        default_file = default_file.strip('/')
        default_file = default_file.replace('////', '/')
        default_file = default_file.replace('///', '/')
        default_file = default_file.replace('//', '/')

    is_file = qstr_is_file(default_file, ROOT_DIR=theme_root)
    is_dir = qstr_is_dir(default_file, ROOT_DIR=theme_root)
    if is_file:
        pass
    elif is_dir:
        # if default_file is a directory then append the
        # trailing slash so we can get the dirname below
        default_file = '%s/' % default_file
    else:
        # if the default_file is not a directory or file within
        # the themes folder then return a 404
        raise Http404("Custom template not found. Make sure you've copied over the themes to the THEME_DIR.")

    # get the current file name
    current_file = os.path.basename(default_file)

    # get the present working directory
    # and make sure they cannot list root
    pwd = os.path.dirname(default_file)
    if pwd == '/':
        pwd = ''

    current_file_path = os.path.join(pwd, current_file)

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'theme base'
    pwd_split = pwd.split('/')
    if len(pwd_split) > 1:
        prev_dir_name = pwd_split[-2]
        pwd_split.pop()
        prev_dir = '/'.join(pwd_split)
    elif not pwd_split[0]:
        prev_dir = ''

    # get the direcory list
    dirs = get_dir_list(pwd, ROOT_DIR=theme_root)

    # get the file list
    files, non_editable_files = get_file_list(pwd, ROOT_DIR=theme_root)

    all_files_folders = get_all_files_list(ROOT_DIR=theme_root)

    # non-deletable files
    non_deletable_files = ['homepage.html', 'default.html', 'footer.html', 'header.html', 'sidebar.html', 'nav.html', 'styles.less', 'styles.css']
    
    # get the number of themes in the themes directory on the site
    theme_choices = [ i for i in theme_choice_list()]
    theme_count = len(theme_choices)
    
    # get a list of revisions
    archives = ThemeFileVersion.objects.filter(relative_file_path=default_file).order_by("-create_dt")

    if request.method == "POST":
        file_form = form_class(request.POST)
        if file_form.is_valid():
            if file_form.save(request, default_file, ROOT_DIR=theme_root, ORIG_ROOT_DIR=original_theme_root):
                message = "Successfully updated %s" % current_file
                message_status = messages.SUCCESS

                EventLog.objects.log()
            else:
                message = "Cannot update"
                message_status = messages.WARNING
            messages.add_message(request, message_status, message)

    else:
        content = get_file_content(default_file,  ROOT_DIR=theme_root)
        file_form = form_class({"content": content, "rf_path": default_file})

    theme_form = ThemeSelectForm(initial={'theme_edit': selected_theme})

    return render_to_response(template_name, {
        'file_form': file_form,
        'theme_form': theme_form,
        'current_theme': selected_theme,
        'current_file_path': current_file_path,
        'current_file': current_file,
        'prev_dir_name': prev_dir_name,
        'prev_dir': prev_dir,
        'pwd': pwd,
        'dirs': dirs,
        'files': files,
        'non_editable_files': non_editable_files,
        'non_deletable_files': non_deletable_files,
        'theme_count': theme_count,
        'archives': archives,
        'is_file': is_file,
        'is_dir': is_dir,
        'all_files_folders': all_files_folders,
    }, context_instance=RequestContext(request))
示例#8
0
文件: views.py 项目: eloyz/tendenci
def edit_file(request,
              form_class=FileForm,
              template_name="theme_editor/index.html"):

    if not has_perm(request.user, 'theme_editor.view_themefileversion'):
        raise Http403

    selected_theme = request.GET.get("theme_edit", get_theme())
    if settings.USE_S3_STORAGE:
        theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)
    else:
        theme_root = os.path.join(settings.THEMES_DIR, selected_theme)

    # get the default file and clean up any input
    default_file = request.GET.get("file", DEFAULT_FILE)

    if default_file:
        default_file = default_file.replace('\\', '/')
        default_file = default_file.strip('/')
        default_file = default_file.replace('////', '/')
        default_file = default_file.replace('///', '/')
        default_file = default_file.replace('//', '/')

    is_file = qstr_is_file(default_file, ROOT_DIR=theme_root)
    is_dir = qstr_is_dir(default_file, ROOT_DIR=theme_root)
    if is_file:
        pass
    elif is_dir:
        # if default_file is a directory then append the
        # trailing slash so we can get the dirname below
        default_file = '%s/' % default_file
    else:
        # if the default_file is not a directory or file within
        # the themes folder then return a 404
        raise Http404(
            "Custom template not found. Make sure you've copied over the themes to the THEME_DIR."
        )

    # get the current file name
    current_file = os.path.basename(default_file)

    # get the present working directory
    # and make sure they cannot list root
    pwd = os.path.dirname(default_file)
    if pwd == '/':
        pwd = ''

    current_file_path = os.path.join(pwd, current_file)

    # get the previous directory name and path
    prev_dir = '/'
    prev_dir_name = 'theme base'
    pwd_split = pwd.split('/')
    if len(pwd_split) > 1:
        prev_dir_name = pwd_split[-2]
        pwd_split.pop()
        prev_dir = '/'.join(pwd_split)
    elif not pwd_split[0]:
        prev_dir = ''

    # get the direcory list
    dirs = get_dir_list(pwd, ROOT_DIR=theme_root)

    # get the file list
    files, non_editable_files = get_file_list(pwd, ROOT_DIR=theme_root)

    all_files_folders = get_all_files_list(ROOT_DIR=theme_root)

    # non-deletable files
    non_deletable_files = [
        'homepage.html', 'default.html', 'footer.html', 'header.html',
        'sidebar.html', 'nav.html', 'styles.less', 'styles.css'
    ]

    # get the number of themes in the themes directory on the site
    theme_choices = [i for i in theme_choice_list()]
    theme_count = len(theme_choices)

    # get a list of revisions
    archives = ThemeFileVersion.objects.filter(
        relative_file_path=default_file).order_by("-create_dt")

    if request.method == "POST":
        file_form = form_class(request.POST)
        if file_form.is_valid():
            if file_form.save(request, default_file, ROOT_DIR=theme_root):
                message = "Successfully updated %s" % current_file
                message_status = messages.SUCCESS

                log_defaults = {
                    'event_id': 1110000,
                    'event_data':
                    '%s updated by %s' % (current_file, request.user),
                    'description': 'theme file edited',
                    'user': request.user,
                    'request': request,
                    'source': 'theme_editor',
                }
                EventLog.objects.log(**log_defaults)
            else:
                message = "Cannot update"
                message_status = messages.WARNING
            messages.add_message(request, message_status, message)

    else:
        content = get_file_content(default_file, ROOT_DIR=theme_root)
        file_form = form_class({"content": content, "rf_path": default_file})

    theme_form = ThemeSelectForm(initial={'theme_edit': selected_theme})

    return render_to_response(template_name, {
        'file_form': file_form,
        'theme_form': theme_form,
        'current_theme': selected_theme,
        'current_file_path': current_file_path,
        'current_file': current_file,
        'prev_dir_name': prev_dir_name,
        'prev_dir': prev_dir,
        'pwd': pwd,
        'dirs': dirs,
        'files': files,
        'non_editable_files': non_editable_files,
        'non_deletable_files': non_deletable_files,
        'theme_count': theme_count,
        'archives': archives,
        'is_file': is_file,
        'is_dir': is_dir,
        'all_files_folders': all_files_folders,
    },
                              context_instance=RequestContext(request))
示例#9
0
def edit_file(request, form_class=FileForm, template_name="theme_editor/index.html"):

    if not has_perm(request.user, "theme_editor.view_themefileversion"):
        raise Http403

    selected_theme = request.GET.get("theme_edit", get_theme())
    original_theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)
    if settings.USE_S3_THEME:
        theme_root = os.path.join(settings.THEME_S3_PATH, selected_theme)
    else:
        theme_root = os.path.join(settings.ORIGINAL_THEMES_DIR, selected_theme)

    # get the default file and clean up any input
    default_file = request.GET.get("file", DEFAULT_FILE)

    if default_file:
        default_file = default_file.replace("\\", "/")
        default_file = default_file.strip("/")
        default_file = default_file.replace("////", "/")
        default_file = default_file.replace("///", "/")
        default_file = default_file.replace("//", "/")

    is_file = qstr_is_file(default_file, ROOT_DIR=theme_root)
    is_dir = qstr_is_dir(default_file, ROOT_DIR=theme_root)

    if is_file:
        pass
    elif is_dir:
        # if default_file is a directory then append the
        # trailing slash so we can get the dirname below
        default_file = "%s/" % default_file
    else:
        # if the default_file is not a directory or file within
        # the themes folder then return a 404
        raise Http404(_("Custom template not found. Make sure you've copied over the themes to the THEME_DIR."))

    # get the current file name
    current_file = os.path.basename(default_file)

    # get file ext
    name = current_file.split("/")[-1]
    ext = name.split(".")[-1]
    stylesheets = ["css", "less"]

    # get the present working directory
    # and make sure they cannot list root
    pwd = os.path.dirname(default_file)
    if pwd == "/":
        pwd = ""

    current_file_path = os.path.join(pwd, current_file)

    # get the previous directory name and path
    prev_dir = "/"
    prev_dir_name = "theme base"
    pwd_split = pwd.split("/")
    if len(pwd_split) > 1:
        prev_dir_name = pwd_split[-2]
        pwd_split.pop()
        prev_dir = "/".join(pwd_split)
    elif not pwd_split[0]:
        prev_dir = ""

    # get the direcory list
    dirs = get_dir_list(pwd, ROOT_DIR=theme_root)

    # get the file list
    files, non_editable_files = get_file_list(pwd, ROOT_DIR=theme_root)

    all_files_folders = get_all_files_list(ROOT_DIR=theme_root)

    # non-deletable files
    non_deletable_files = [
        "homepage.html",
        "default.html",
        "footer.html",
        "header.html",
        "sidebar.html",
        "nav.html",
        "styles.less",
        "styles.css",
    ]

    # get the number of themes in the themes directory on the site
    theme_choices = [i for i in theme_choice_list()]
    theme_count = len(theme_choices)

    # get a list of revisions
    archives = ThemeFileVersion.objects.filter(relative_file_path=default_file).order_by("-create_dt")

    if request.is_ajax() and request.method == "POST":
        file_form = form_class(request.POST)
        response_status = "FAIL"
        response_message = _("Cannot update file.")
        if file_form.is_valid():
            if file_form.save(request, default_file, ROOT_DIR=theme_root, ORIG_ROOT_DIR=original_theme_root):
                response_status = "SUCCESS"
                response_message = _("Your changes have been saved.")
                EventLog.objects.log()

        response = json.dumps({"status": response_status, "message": response_message})
        return HttpResponse(response, mimetype="application/json")

    content = get_file_content(default_file, ROOT_DIR=theme_root)
    file_form = form_class({"content": content, "rf_path": default_file})

    theme_form = ThemeSelectForm(initial={"theme_edit": selected_theme})

    return render_to_response(
        template_name,
        {
            "file_form": file_form,
            "theme_form": theme_form,
            "current_theme": selected_theme,
            "current_file_path": current_file_path,
            "current_file": current_file,
            "prev_dir_name": prev_dir_name,
            "prev_dir": prev_dir,
            "pwd": pwd,
            "dirs": dirs,
            "files": files,
            "non_editable_files": non_editable_files,
            "non_deletable_files": non_deletable_files,
            "theme_count": theme_count,
            "archives": archives,
            "is_file": is_file,
            "is_dir": is_dir,
            "all_files_folders": all_files_folders,
            "ext": ext,
            "stylesheets": stylesheets,
        },
        context_instance=RequestContext(request),
    )