コード例 #1
0
def group_settings(request,
                   group,
                   template='livesettings/group_settings.html'):
    # Determine what set of settings this editor is used for

    use_db, overrides = get_overrides()

    mgr = ConfigurationSettings()

    settings = mgr[group]
    if settings is None:
        raise Http404()
    title = settings.name
    log.debug('title: %s', title)

    if use_db:
        # Create an editor customized for the current user
        # editor = forms.customized_editor(settings)

        if request.method == 'POST':
            # Populate the form with user-submitted data
            data = request.POST.copy()
            form = forms.SettingsEditor(data, request.FILES, settings=settings)
            if form.is_valid():
                for name, value in form.cleaned_data.items():
                    group, key, lang = name.split('__')
                    cfg = mgr.get_config(group, key)

                    if isinstance(cfg, ImageValue):
                        if request.FILES and name in request.FILES:
                            value = request.FILES[name]
                        else:
                            continue

                    try:
                        cfg.update(value, lang)
                        # message='Updated %s on %s' % (cfg.key, cfg.group.key)
                        # messages.success(request, message)
                        # the else if for the settings that are not updated.
                    except Exception as e:
                        request.user.message_set.create(message=e.message)

                return HttpResponseRedirect(request.path)
        else:
            # Leave the form populated with current setting values
            # form = editor()
            form = forms.SettingsEditor(settings=settings)
    else:
        form = None

    return render(
        request, template, {
            'all_super_groups': mgr.get_super_groups(),
            'page_class': 'settings',
            'title': title,
            'settings_group': settings,
            'form': form,
            'use_db': use_db
        })
コード例 #2
0
ファイル: views.py プロジェクト: ASKBOT/askbot-devel
def group_settings(request, group, template='livesettings/group_settings.html'):
    # Determine what set of settings this editor is used for

    use_db, overrides = get_overrides()

    mgr = ConfigurationSettings()

    settings = mgr[group]
    if settings is None:
        raise Http404()
    title = settings.name
    log.debug('title: %s', title)

    if use_db:
        # Create an editor customized for the current user
        # editor = forms.customized_editor(settings)

        if request.method == 'POST':
            # Populate the form with user-submitted data
            data = request.POST.copy()
            form = forms.SettingsEditor(data, request.FILES, settings=settings)
            if form.is_valid():
                for name, value in form.cleaned_data.items():
                    group, key, lang = name.split('__')
                    cfg = mgr.get_config(group, key)

                    if isinstance(cfg, ImageValue):
                        if request.FILES and name in request.FILES:
                            value = request.FILES[name]
                        else:
                            continue

                    try:
                        cfg.update(value, lang)
                        # message='Updated %s on %s' % (cfg.key, cfg.group.key)
                        # messages.success(request, message)
                        # the else if for the settings that are not updated.
                    except Exception as e:
                        request.user.message_set.create(message=e.message)

                return HttpResponseRedirect(request.path)
        else:
            # Leave the form populated with current setting values
            # form = editor()
            form = forms.SettingsEditor(settings=settings)
    else:
        form = None

    return render(request, template, {
        'all_super_groups': mgr.get_super_groups(),
        'page_class': 'settings',
        'title': title,
        'settings_group': settings,
        'form': form,
        'use_db': use_db
    })
コード例 #3
0
ファイル: views.py プロジェクト: pruthvikar/askbot-devel
def spaces_settings(request, template='livesettings/space_settings.html'):
    use_db, overrides = get_overrides();
    print request.GET, request.POST
    mgr = ConfigurationSettings()
    settings = mgr['SPACE']

    if use_db:
        if request.method=='GET' and request.GET.get('Create_or_Edit_Space'):
            
            try :
                instance=Space.objects.get(pk=request.GET['Create_or_Edit_Space'])
                selectform=SelectForm(initial = {'Create_or_Edit_Space': instance.pk })
                thisform=SpaceForm(instance=instance)

            except KeyError:
                selectform=SelectForm(initial = {'Create_or_Edit_Space': 0 })
                thisform=SpaceForm()
        
        elif request.method=='POST':
            try:
#                request.GET['Create_or_Edit_Space']

                instance=Space.objects.get(pk=request.GET['Create_or_Edit_Space'])
                selectform=SelectForm(initial={'Create_or_Edit_Space': instance.pk })
                if request.POST['Delete']:
                    instance.delete()
                    instance=None
                    selectform=SelectForm(initial={'Create_or_Edit_Space': 0 })
                    thisform=SpaceForm(instance=instance)
                else:
                    selectform=SelectForm(initial={'Create_or_Edit_Space': instance.pk })
                    thisform=SpaceForm(request.POST,request.FILES,instance=instance)
            except :
                instance=None
                selectform=SelectForm(initial = {'Create_or_Edit_Space': 0 })
                thisform=SpaceForm(request.POST,request.FILES,instance=instance)
            
            

                
            if thisform.is_valid():
                thisform.save()
        else:
            thisform=SpaceForm()
            selectform=SelectForm()
                            
    else:
        form = None

    return render_to_response(template, {
                              'all_super_groups': mgr.get_super_groups(),
                              'group' : settings,
                              'select':selectform,
                              'form': thisform,
                              'use_db' : use_db
                              }, context_instance=RequestContext(request))
コード例 #4
0
def group_settings(request,
                   group,
                   template='livesettings/group_settings.html'):
    # Determine what set of settings this editor is used for

    use_db, overrides = get_overrides()

    mgr = ConfigurationSettings()

    settings = mgr[group]
    title = settings.name
    log.debug('title: %s', title)

    if use_db:
        # Create an editor customized for the current user
        #editor = forms.customized_editor(settings)

        if request.method == 'POST':

            # Populate the form with user-submitted data
            data = request.POST.copy()
            form = forms.SettingsEditor(data, request.FILES, settings=settings)
            if form.is_valid():
                for name, value in form.cleaned_data.items():
                    group, key = name.split('__')
                    cfg = mgr.get_config(group, key)

                    if isinstance(cfg, ImageValue):
                        if request.FILES and name in request.FILES:
                            value = request.FILES[name]
                        else:
                            continue

                    if cfg.update(value):
                        # Give user feedback as to which settings were changed
                        message = 'Updated %s on %s' % (cfg.key, cfg.group.key)
                        request.user.message_set.create(message=message)

                return HttpResponseRedirect(request.path)
        else:
            # Leave the form populated with current setting values
            #form = editor()
            form = forms.SettingsEditor(settings=settings)
    else:
        form = None

    return render_to_response(template, {
        'all_super_groups': mgr.get_super_groups(),
        'title': title,
        'group': settings,
        'form': form,
        'use_db': use_db
    },
                              context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: B-Rich/askbot-devel
def group_settings(request, group, template='livesettings/group_settings.html'):
    # Determine what set of settings this editor is used for

    use_db, overrides = get_overrides();
    
    mgr = ConfigurationSettings()

    settings = mgr[group]
    title = settings.name
    log.debug('title: %s', title)

    if use_db:
        # Create an editor customized for the current user
        #editor = forms.customized_editor(settings)

        if request.method == 'POST':

            # Populate the form with user-submitted data
            data = request.POST.copy()
            form = forms.SettingsEditor(data, request.FILES, settings=settings)
            if form.is_valid():
                for name, value in form.cleaned_data.items():
                    group, key = name.split('__')
                    cfg = mgr.get_config(group, key)

                    if isinstance(cfg, ImageValue):
                        if request.FILES and name in request.FILES:
                            value = request.FILES[name]
                        else:
                            continue

                    if cfg.update(value):
                        # Give user feedback as to which settings were changed
                        message='Updated %s on %s' % (cfg.key, cfg.group.key)
                        request.user.message_set.create(message = message)

                return HttpResponseRedirect(request.path)
        else:
            # Leave the form populated with current setting values
            #form = editor()
            form = forms.SettingsEditor(settings=settings)
    else:
        form = None

    return render_to_response(template, {
        'all_super_groups': mgr.get_super_groups(),
        'title': title,
        'group' : settings,
        'form': form,
        'use_db' : use_db
    }, context_instance=RequestContext(request))