def org_edit(request, slug): logger = getLogger('default') organization = get_object_or_404(Organization, slug=slug, sites__id=settings.SITE_ID) # model if not request.user.has_perm('can_edit_org', organization): # model raise PermissionDenied if request.method == "POST": form = OrganizationForm(request.POST, request.FILES, instance=organization) forms_args = djaloha_utils.extract_forms_args(request.POST) djaloha_forms = djaloha_utils.make_forms(forms_args, request.POST) if form.is_valid() and all([f.is_valid() for f in djaloha_forms]): logger.error('formulaire valide') organization = form.save() # if organization.temp_logo: # organization.logo = organization.temp_logo # organization.temp_logo = '' # organization.save() if djaloha_forms: [f.save() for f in djaloha_forms] messages.success(request, _(u'Your changes have been saved properly')) return HttpResponseRedirect(organization.get_absolute_url()) else: # import pdb # pdb.set_trace() for f in form.errors.keys(): logger.error(u'FORM ERROR | ' + unicode(f) + u' : ' + unicode(form.errors[f][0])) messages.error(request, _(u"An error has occured.")) else: from coop_bar.urls import bar if "pageSlide" not in bar.get_footer(request, RequestContext(request)): bar.register_footer(coop_bar_aloha_js) form = OrganizationForm(instance=organization) context_dict = { 'form': form, 'editable': True, 'edit_mode': True, 'title': organization.title, 'organization': organization, } return render_to_response( 'org/org_detail.html', context_dict, context_instance=RequestContext(request) )
def edit_newsletter(request, newsletter_id): newsletter = get_object_or_404(Newsletter, id=newsletter_id) newsletter_form_class = forms.get_newsletter_form() if not request.user.has_perm('can_edit_newsletter', newsletter): raise PermissionDenied from coop_bar.urls import bar if "pageSlide" not in bar.get_footer(request, RequestContext(request)): bar.register_footer(coop_bar_aloha_js) if request.method == "POST": form = newsletter_form_class(request.POST, instance=newsletter) forms_args = djaloha_utils.extract_forms_args(request.POST) djaloha_forms = djaloha_utils.make_forms(forms_args, request.POST) if form.is_valid(): # and all([f.is_valid() for f in djaloha_forms]): newsletter = form.save() if djaloha_forms: [f.save() for f in djaloha_forms] messages.success(request, _(u'The newsletter has been saved properly')) return HttpResponseRedirect(reverse('coop_edit_newsletter', args=[newsletter.id])) else: form = newsletter_form_class(instance=newsletter) context_dict = { 'form': form, 'post_url': reverse('coop_edit_newsletter', args=[newsletter.id]), 'editable': True, 'edit_mode': True, 'title': newsletter.subject, 'newsletter': newsletter, } return render_to_response( newsletter.get_template_name(), context_dict, context_instance=RequestContext(request) )
def edit_article(request, url): """edit the article""" logger = getLogger("default") article_class = get_article_class() article_form_class = get_article_form() article = get_object_or_404(article_class, slug=url) if not request.user.has_perm("can_edit_article", article): raise PermissionDenied if request.method == "POST": form = article_form_class(request.POST, request.FILES, instance=article) forms_args = djaloha_utils.extract_forms_args(request.POST) djaloha_forms = djaloha_utils.make_forms(forms_args, request.POST) if form.is_valid() and all([f.is_valid() for f in djaloha_forms]): logger.error("formulaire valide") article = form.save() if article.temp_logo: article.logo = article.temp_logo article.temp_logo = "" article.save() # logo = form.cleaned_data["logo"] # if logo: # article.logo.save(logo.name, logo) if djaloha_forms: [f.save() for f in djaloha_forms] messages.success(request, _(u"The article has been saved properly")) return HttpResponseRedirect(article.get_absolute_url()) else: messages.error(request, _(u"An error has occured.")) else: from coop_bar.urls import bar if "pageSlide" not in bar.get_footer(request, RequestContext(request)): bar.register_footer(coop_bar_aloha_js) form = article_form_class(instance=article) context_dict = { "form": form, "editable": True, "edit_mode": True, "title": article.title, "draft": article.publication == models.BaseArticle.DRAFT, "article": article, "ARTICLE_PUBLISHED": models.BaseArticle.PUBLISHED, } return render_to_response(get_article_template(article), context_dict, context_instance=RequestContext(request))