def media_edit(request, media_id): #check_permissions(request.user, [PERMISSION_USER_EDIT]) media = get_object_or_404(Media, pk=media_id) if request.method == 'POST': form = MediaForm(request.POST, request.FILES, instance=media) if form.is_valid(): media = form.save() messages.success(request, _(u'CMS media "%s" updated successfully.') % media) return HttpResponseRedirect(reverse('media_list')) else: form = MediaForm(instance=media) return render_to_response('generic_form.html', { 'template_id': u'crud_edit', 'title': _(u'edit CMS media: %s') % media, 'form': form, 'object': media, 'object_name': _(u'CMS media'), }, context_instance=RequestContext(request))
def media_add(request): #check_permissions(request.user, [PERMISSION_USER_CREATE]) title = _(u'add new CMS media') if request.method == 'POST': form = MediaForm(request.POST, request.FILES) if form.is_valid(): media = form.save() messages.success(request, _(u'CMS media "%s" created successfully.') % media) return HttpResponseRedirect(reverse('media_list')) #return HttpResponseRedirect(reverse('media_edit', args=[media.pk])) else: form = MediaForm() return render_to_response('generic_form.html', { 'template_id': u'crud_add', 'title': title, 'form': form, 'object_name': _(u'CMS media'), }, context_instance=RequestContext(request))