def theme_edit_modify(request, channel): theme = get_object_or_404(Theme, id=request.POST['id']) form_theme = FrontThemeForm(instance=theme) return render(request, "channel/form_theme.html", { 'form_theme': form_theme, 'channel': channel })
def theme_edit_save(request, channel): form_theme = None if (request.POST.get("theme_id") and request.POST.get("theme_id") != "None"): theme = get_object_or_404(Theme, id=request.POST['theme_id']) form_theme = FrontThemeForm(request.POST, instance=theme) else: form_theme = FrontThemeForm(request.POST) if form_theme.is_valid(): form_theme.save() rendered = render_to_string("channel/list_theme.html", { 'list_theme': channel.themes.all(), 'channel': channel }, request) list_element = {'list_element': rendered} data = json.dumps(list_element) return HttpResponse(data, content_type='application/json') else: rendered = render_to_string("channel/form_theme.html", { 'form_theme': form_theme, 'channel': channel }, request) some_data_to_dump = { 'errors': "%s" % _('Please correct errors'), 'form': rendered } data = json.dumps(some_data_to_dump) return HttpResponse(data, content_type='application/json')
def theme_edit(request, slug): channel = get_object_or_404(Channel, slug=slug) if (request.user not in channel.owners.all() and not request.user.is_superuser): messages.add_message(request, messages.ERROR, _(u'You cannot edit this channel.')) raise PermissionDenied if request.POST and request.is_ajax(): if request.POST['action'] in THEME_ACTION: return eval('theme_edit_{0}(request, channel)'.format( request.POST['action'])) form_theme = FrontThemeForm(initial={"channel": channel}) return render(request, 'channel/theme_edit.html', { 'channel': channel, 'form_theme': form_theme })
def theme_edit_new(request, channel): form_theme = FrontThemeForm(initial={"channel": channel}) return render(request, "channel/form_theme.html", { 'form_theme': form_theme, 'channel': channel })