Example #1
0
def selector(request, keep_files=None):
    if settings.LOCAL_THEME:
        raise ESPError(THEME_ERROR_STRING, log=False)

    context = {}
    tc = ThemeController()

    if request.method == 'POST' and 'action' in request.POST:
        if request.POST['action'] == 'select':
            theme_name = request.POST['theme'].replace(' (current)', '')

            #   Check for differences between the theme's files and those in the working copy.
            #   If there are differences, require a confirmation from the user for each file.
            differences = tc.check_local_modifications(theme_name)
            if len(differences) > 0 and keep_files is None:
                return confirm_overwrite(request, current_theme=theme_name, differences=differences, orig_view='selector')

            #   Display configuration form if one is provided for the selected theme
            if tc.get_config_form_class(theme_name) is not None:
                return configure(request, current_theme=theme_name, force_display=True, keep_files=keep_files)

            tc.save_customizations('%s-last' % tc.get_current_theme())
            backup_info = tc.clear_theme(keep_files=keep_files)
            tc.load_theme(theme_name, backup_info=backup_info)
        elif request.POST['action'] == 'clear':
            tc.save_customizations('%s-last' % tc.get_current_theme())
            tc.clear_theme()

    context['theme_name'] = tc.get_current_theme()
    context['themes'] = tc.get_theme_names()
    return render_to_response('themes/selector.html', request, context)
Example #2
0
def configure(request, current_theme=None, force_display=False):
    context = {}
    tc = ThemeController()
    if current_theme is None:
        current_theme = request.POST.get('theme',
                                         None) or tc.get_current_theme()
    context['theme_name'] = current_theme

    form_class = tc.get_config_form_class(current_theme)
    if form_class is None:
        form = None
        return render_to_response('themes/configure_form.html', request,
                                  context)

    if request.method == 'POST' and not force_display:
        form = form_class(request.POST.copy())

        if form.is_valid():
            #   Done; save results and go back to landing page.
            if form.cleaned_data['theme'] != tc.get_current_theme():
                tc.save_customizations('%s-last' % tc.get_current_theme())
            if form.cleaned_data['just_selected']:
                tc.clear_theme()
                tc.load_theme(form.cleaned_data['theme'])
            form.save_to_tag()
            return HttpResponseRedirect('/themes/')
    else:
        form = form_class.load_from_tag(theme_name=current_theme,
                                        just_selected=force_display)

    context['form'] = form

    return render_to_response('themes/configure_form.html', request, context)
Example #3
0
def configure(request, current_theme=None, force_display=False, keep_files=None):
    if settings.LOCAL_THEME:
        raise ESPError(THEME_ERROR_STRING, log=False)

    context = {}
    tc = ThemeController()
    if current_theme is None:
        current_theme = request.POST.get('theme', None) or tc.get_current_theme()
    context['theme_name'] = current_theme

    form_class = tc.get_config_form_class(current_theme)
    if form_class is None:
        form = None
        return render_to_response('themes/configure_form.html', request, context)

    if request.method == 'POST' and not force_display:
        form = form_class(request.POST.copy())

        if form.is_valid():
            #   Done; save results and go back to landing page.
            if form.cleaned_data['theme'] != tc.get_current_theme():
                tc.save_customizations('%s-last' % tc.get_current_theme())

            if form.cleaned_data['just_selected']:
                #   Detect which files (in the active media directories) are being preserved,
                #   and use this information when reloading the theme.
                keep_files = request.POST.getlist('keep_files', [])
                backup_info = tc.clear_theme(keep_files=keep_files)
                tc.load_theme(form.cleaned_data['theme'], backup_info=backup_info)

            form.save_to_tag()
            return HttpResponseRedirect('/themes/')
    else:
        form = form_class.load_from_tag(theme_name=current_theme, just_selected=force_display)

    context['form'] = form
    context['keep_files'] = keep_files
    context['confirm_overwrite'] = request.POST.get('confirm_overwrite', '0')

    return render_to_response('themes/configure_form.html', request, context)
Example #4
0
def selector(request):
    context = {}
    tc = ThemeController()

    if request.method == 'POST' and 'action' in request.POST:
        if request.POST['action'] == 'select':
            theme_name = request.POST['theme'].replace(' (current)', '')

            #   Display configuration form if one is provided for the selected theme
            if tc.get_config_form_class(theme_name) is not None:
                return configure(request,
                                 current_theme=theme_name,
                                 force_display=True)

            tc.save_customizations('%s-last' % tc.get_current_theme())
            tc.clear_theme()
            tc.load_theme(theme_name)
        elif request.POST['action'] == 'clear':
            tc.save_customizations('%s-last' % tc.get_current_theme())
            tc.clear_theme()

    context['theme_name'] = tc.get_current_theme()
    context['themes'] = tc.get_theme_names()
    return render_to_response('themes/selector.html', request, context)