Exemple #1
0
def new_theme(request):
    """Create a new theme, using the client.html template as the default. """
    context = {}
    theme_form = None
    if request.method == "POST":
        # Validate and save the theme
        theme_form = ThemeForm(request.POST)
        if theme_form.is_valid():
            name = theme_form.cleaned_data["name"]
            content = theme_form.cleaned_data["content"]
            owner = request.user
            theme = Theme(name=name, content=content, owner=owner)
            theme.save()
            # Return edit theme template on successful
            # theme creation
            context["message"] = "Successfully Created Theme."
            context["form"] = theme_form

            return_response = render_response(request, "edittheme.html", context)
        else:
            context["form"] = theme_form
            return_response = render_response(request, "newtheme.html", context)

    else:
        # set initial context as client.html
        rendered = render_to_string("client.html", {})
        theme_form = ThemeForm(initial={"content": rendered})
        context["form"] = theme_form
        return_response = render_response(request, "newtheme.html", context)
    return return_response
Exemple #2
0
def new_theme(request):
    """Create a new theme, using the client.html template as the default. """
    context = {}
    theme_form = None
    if request.method == "POST":
        #Validate and save the theme
        theme_form = ThemeForm(request.POST)
        if theme_form.is_valid():
            name = theme_form.cleaned_data['name']
            content = theme_form.cleaned_data['content']
            owner = request.user
            theme = Theme(name=name, content=content, owner=owner)
            theme.save()
            #Return edit theme template on successful
            #theme creation
            context['message'] = "Successfully Created Theme."
            context['form'] = theme_form

            return_response = render_response(request, 'edittheme.html',
                                              context)
        else:
            context['form'] = theme_form
            return_response = render_response(request, 'newtheme.html',
                                              context)

    else:
        #set initial context as client.html
        rendered = render_to_string('client.html', {})
        theme_form = ThemeForm(initial={'content': rendered})
        context['form'] = theme_form
        return_response = render_response(request, 'newtheme.html', context)
    return return_response
Exemple #3
0
def edit_theme(request, theme_id=None):

    context = {}
    theme = get_object_or_404(Theme, id=theme_id)
    if request.method == "POST":
        # Validate and save the theme
        theme_form = ThemeForm(request.POST)
        if theme_form.is_valid():
            theme.name = theme_form.cleaned_data["name"]
            theme.content = theme_form.cleaned_data["content"]
            theme.owner = request.user
            theme.save()

        context["form"] = theme_form
    else:
        theme_form = ThemeForm({"name": theme.name, "content": theme.content})
        context["form"] = theme_form

    return render_response(request, "edittheme.html", context)
Exemple #4
0
def edit_theme(request, theme_id=None):

    context = {}
    theme = get_object_or_404(Theme, id=theme_id)
    if request.method == "POST":
        #Validate and save the theme
        theme_form = ThemeForm(request.POST)
        if theme_form.is_valid():
            theme.name = theme_form.cleaned_data['name']
            theme.content = theme_form.cleaned_data['content']
            theme.owner = request.user
            theme.save()

        context['form'] = theme_form
    else:
        theme_form = ThemeForm({'name': theme.name, 'content': theme.content})
        context['form'] = theme_form

    return render_response(request, 'edittheme.html', context)
def edit_theme(request,theme_id=None):
	
	context = {}
	theme = get_object_or_404(Theme,id=theme_id)
	if request.method == "POST":
		#Validate and save the theme
		theme_form = ThemeForm(request.POST)
		if theme_form.is_valid():			
			theme.name=theme_form.cleaned_data['name']
			theme.content=theme_form.cleaned_data['content']
			theme.owner=request.user
			theme.save()

		context['form'] = theme_form
	else:
		theme_form = ThemeForm({'name':theme.name,
				       'content':theme.content})
		context['form'] = theme_form
		
	return render_response(request,
			       'edittheme.html',
			       context)
Exemple #6
0
 def testTheme(self):
     form = ThemeForm({'name':"test",
                       'content':"<html></html>"})
     self.assert_(form.is_valid())