コード例 #1
0
ファイル: views.py プロジェクト: shway1/ESP-Website
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)
コード例 #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)
コード例 #3
0
def landing(request):
    context = {}
    tc = ThemeController()
    context['theme_name'] = tc.get_current_theme()
    context['last_customization_name'] = Tag.getTag('prev_theme_customization',
                                                    default='None')
    return render_to_response('themes/landing.html', request, context)
コード例 #4
0
ファイル: views.py プロジェクト: shway1/ESP-Website
def landing(request):
    if settings.LOCAL_THEME:
        raise ESPError(THEME_ERROR_STRING, log=False)
    context = {}
    tc = ThemeController()
    context['theme_name'] = tc.get_current_theme()
    context['last_customization_name'] = tc.get_current_customization()
    return render_to_response('themes/landing.html', request, context)
コード例 #5
0
 def load_from_tag(cls, theme_name=None, just_selected=False):
     data = json.loads(Tag.getTag('theme_template_control', default='{}'))
     if theme_name is None:
         tc = ThemeController()
         theme_name = tc.get_current_theme()
     data['theme'] = theme_name
     form_temp = cls(initial=data)
     data = form_temp.recover_from_serialization(data)
     data['just_selected'] = just_selected
     form = cls(initial=data)
     return form
コード例 #6
0
 def load_from_tag(cls, theme_name=None, just_selected=False):
     data = json.loads(Tag.getTag('theme_template_control', default='{}'))
     if theme_name is None:
         tc = ThemeController()
         theme_name = tc.get_current_theme()
     data['theme'] = theme_name
     form_temp = cls(initial=data)
     data = form_temp.recover_from_serialization(data)
     data['just_selected'] = just_selected
     form = cls(initial=data)
     return form
コード例 #7
0
ファイル: views.py プロジェクト: shway1/ESP-Website
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)
コード例 #8
0
ファイル: views.py プロジェクト: shway1/ESP-Website
def recompile(request, keep_files=None):
    if settings.LOCAL_THEME:
        raise ESPError(THEME_ERROR_STRING, log=False)

    tc = ThemeController()

    #   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.
    theme_name = tc.get_current_theme()
    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='recompile')

    tc.recompile_theme(keep_files=keep_files)
    return HttpResponseRedirect('/themes/')
コード例 #9
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)
コード例 #10
0
ファイル: views.py プロジェクト: shway1/ESP-Website
def editor(request):
    if settings.LOCAL_THEME:
        raise ESPError(THEME_ERROR_STRING, log=False)

    tc = ThemeController()

    if request.method == 'POST':
        #   Handle form submission
        vars = None
        palette = None

        if 'save' in request.POST:
            if request.POST['saveThemeName'] == '':
                theme_name = tc.get_current_customization()
                if theme_name == 'None':
                    #   Generate a temporary theme name
                    random_slug  = ''.join(random.choice(string.lowercase) for i in range(4))
                    theme_name = 'theme-%s-%s' % (datetime.now().strftime('%Y%m%d'), random_slug)
            else:
                theme_name = request.POST['saveThemeName']
            vars = request.POST.dict()
            palette = request.POST.getlist('palette')
            tc.save_customizations(theme_name, vars=vars, palette=palette)
            tc.set_current_customization(theme_name)
        elif 'load' in request.POST:
            (vars, palette) = tc.load_customizations(request.POST['loadThemeName'])
        elif 'delete' in request.POST:
            tc.delete_customizations(request.POST['loadThemeName'])
        elif 'apply' in request.POST:
            vars = request.POST.dict()
            palette = request.POST.getlist('palette')

        #   Re-generate the CSS for the current theme given the supplied settings
        if vars:
            tc.customize_theme(vars)
        if palette:
            tc.set_palette(palette)

    #   Get current theme and customization settings
    current_theme = tc.get_current_theme()
    context = tc.find_less_variables(flat=True)
    context.update(tc.get_current_params())
    context['palette'] = tc.get_palette()

    #   Get list of available customizations
    context['available_themes'] = tc.get_customization_names()
    context['last_used_setting'] = tc.get_current_customization()

    #   Load a bunch of preset fonts
    context['sans_fonts'] = sorted(themes_settings.sans_serif_fonts.iteritems())

    #   Load the theme-specific options
    adv_vars = tc.find_less_variables(current_theme, theme_only=True)
    context['adv_vars'] = {}
    for filename in adv_vars:
        category_name = os.path.basename(filename)[:-5]
        category_vars = []
        keys = adv_vars[filename].keys()
        keys.sort()
        for key in keys:
            #   Detect type of variable based on default value
            initial_val = adv_vars[filename][key]
            if key in context:
                initial_val = context[key]
            if initial_val.startswith('#'):
                category_vars.append((key, 'color', initial_val))
            elif 'color' in key:
                #   This is a nontrivial color value.  However, we only allow overriding
                #   these variables with specific colors.
                category_vars.append((key, 'color', ''))
            elif initial_val.endswith('px') or initial_val.endswith('em'):
                category_vars.append((key, 'length', initial_val))
            else:
                category_vars.append((key, 'text', initial_val))
        context['adv_vars'][category_name] = category_vars

    return render_to_response('themes/editor.html', request, context)
コード例 #11
0
ファイル: views.py プロジェクト: pteromys/ESP-Website
def landing(request):
    context = {}
    tc = ThemeController()
    context['theme_name'] = tc.get_current_theme()
    context['last_customization_name'] = tc.get_current_customization()
    return render_to_response('themes/landing.html', request, context)