def federation_edit(request, federation_slug=None): if federation_slug is None: federation = None else: federation = get_object_or_404(Federation, slug=federation_slug) if request.method == 'POST': form = FederationForm(request.POST, request.FILES, instance=federation) if form.is_valid(): form.save() if not federation: form.instance.editor_users.add(request.user) if 'file' in form.changed_data or 'file_url' in form.changed_data: form.instance.process_metadata() form.instance.process_metadata_entities(request=request) if federation: messages.success(request, _('Federation modified succesfully')) else: messages.success(request, _('Federation created succesfully')) return HttpResponseRedirect(form.instance.get_absolute_url()) else: messages.error(request, _('Please correct the errors indicated' ' below')) else: form = FederationForm(instance=federation) return render_to_response('metadataparser/federation_edit.html', {'form': form}, context_instance=RequestContext(request))
def federation_edit(request, federation_slug=None): federation = get_object_or_404(Federation, slug=federation_slug) if federation_slug else None if request.method == 'POST': form = FederationForm(request.POST, request.FILES, instance=federation) if not form.is_valid(): messages.error(request, _('Please correct the errors indicated below')) else: return federation_edit_post(request, federation, form) else: form = FederationForm(instance=federation) context = RequestContext(request) user = context.get('user', None) delete_federation = user and user.has_perm('metadataparser.delete_federation') return render_to_response('metadataparser/federation_edit.html', {'settings': settings, 'form': form, 'delete_federation': delete_federation}, context_instance=RequestContext(request))