def entity_edit(request, federation_slug=None, entity_id=None): entity = None federation = None if federation_slug: federation = get_object_or_404(Federation, slug=federation_slug) if entity_id: entity = get_object_or_404(Entity, id=entity_id, federations__id=federation.id) if entity_id and not federation_slug: entity = get_object_or_404(Entity, id=entity_id) if request.method == 'POST': form = EntityForm(request.POST, request.FILES, instance=entity) if form.is_valid(): return entity_edit_post(request, form, federation, entity) else: messages.error(request, _('Please correct the errors indicated below')) else: form = EntityForm(instance=entity) return render_to_response('metadataparser/entity_edit.html', { 'settings': settings, 'form': form, 'federation': federation }, context_instance=RequestContext(request))
def entity_edit(request, federation_slug=None, entity_id=None): entity = None federation = None if federation_slug: federation = get_object_or_404(Federation, slug=federation_slug) if entity_id: entity = get_object_or_404(Entity, id=entity_id, federations__id=federation.id) if entity_id and not federation_slug: entity = get_object_or_404(Entity, id=entity_id) if request.method == 'POST': form = EntityForm(request.POST, request.FILES, instance=entity) if form.is_valid(): form.save() if (federation and not federation in form.instance.federations.all()): form.instance.federations.add(federation) form.instance.save() if entity: messages.success(request, _('Entity modified succesfully')) else: messages.success(request, _('Entity created succesfully')) return HttpResponseRedirect(form.instance.get_absolute_url()) else: messages.error(request, _('Please correct the errors indicated' ' below')) else: form = EntityForm(instance=entity) return render_to_response('metadataparser/entity_edit.html', {'form': form, 'federation': federation}, context_instance=RequestContext(request))
def entity_edit(request, federation_slug=None, entity_id=None): entity = None federation = None if federation_slug: federation = get_object_or_404(Federation, slug=federation_slug) if entity_id: entity = get_object_or_404(Entity, id=entity_id, federations__id=federation.id) if entity_id and not federation_slug: entity = get_object_or_404(Entity, id=entity_id) if request.method == 'POST': form = EntityForm(request.POST, request.FILES, instance=entity) if form.is_valid(): return entity_edit_post(request, form, federation, entity) else: messages.error(request, _('Please correct the errors indicated below')) else: form = EntityForm(instance=entity) return render_to_response('metadataparser/entity_edit.html', {'settings': settings, 'form': form, 'federation': federation}, context_instance=RequestContext(request))