Example #1
0
    def change_view(self, request, object_id, extra_context=None):
        """
        The 'change' admin view for this model.
        This follows closely the base implementation from Django 1.3's
        django.contrib.admin.options.ModelAdmin,
        with the explicitly marked modifications.
        """
        # pylint: disable-msg=C0103
        model = self.model
        opts = model._meta

        obj = self.get_object(request, unquote(object_id))

        if not self.has_change_permission(request, obj):
            raise PermissionDenied

        #### begin modification ####
        # make sure that the user has a full session length time for the current
        # edit activity
        request.session.set_expiry(settings.SESSION_COOKIE_AGE)
        #### end modification ####

        if obj is None:
            raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})

        if request.method == 'POST' and "_saveasnew" in request.POST:
            return self.add_view(request, form_url='../add/')

        ModelForm = self.get_form(request, obj)
        formsets = []
        if request.method == 'POST':
            form = ModelForm(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                form_validated = True
                new_object = self.save_form(request, form, change=True)
            else:
                form_validated = False
                new_object = obj
            prefixes = {}
            for FormSet, inline in zip(self.get_formsets(request, new_object),
                                       self.inline_instances):
                #### begin modification ####
                if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                    continue
                #### end modification ####
                prefix = FormSet.get_default_prefix()
                prefixes[prefix] = prefixes.get(prefix, 0) + 1
                if prefixes[prefix] != 1:
                    prefix = "%s-%s" % (prefix, prefixes[prefix])
                formset = FormSet(request.POST, request.FILES,
                                  instance=new_object, prefix=prefix,
                                  queryset=inline.queryset(request))
                #### begin modification ####
                if prefix in self.model.get_fields()['required']:
                    self.set_required_formset(formset)
                #### end modification ####    

                formsets.append(formset)

            if all_valid(formsets) and form_validated:
                #### begin modification ####
                for formset in formsets:
                    # this replaces the call to self.save_formsets()
                    changes = formset.save()
                    # if there are any changes in the current inline and if this
                    # inline is a reverse inline, then we need to manually make
                    # sure that the inline data is connected to the parent
                    # object:
                    if changes:
                        parent_fk_name = getattr(formset, 'parent_fk_name', '')
                        if parent_fk_name:
                            assert len(changes) == 1
                            setattr(new_object, parent_fk_name, changes[0])
                    # If we have deleted a one-to-one inline, we must manually unset the field value.
                    if formset.deleted_objects:
                        parent_fk_name = getattr(formset, 'parent_fk_name', '')
                        if parent_fk_name:
                            setattr(new_object, parent_fk_name, None)

                self.save_model(request, new_object, form, change=True)
                form.save_m2m()
                # for resource info, explicitly write its metadata XML and
                # storage object to the storage folder
                if self.model.__schema_name__ == "resourceInfo":
                    new_object.storage_object.update_storage()
                #### end modification ####

                change_message = self.construct_change_message(request, form, formsets)
                self.log_change(request, new_object, change_message)
                return self.response_change(request, new_object)

        else:
            form = ModelForm(instance=obj)
            prefixes = {}
            for FormSet, inline in zip(self.get_formsets(request, obj), self.inline_instances):
                #### begin modification ####
                if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                    continue
                #### end modification ####
                prefix = FormSet.get_default_prefix()
                prefixes[prefix] = prefixes.get(prefix, 0) + 1
                if prefixes[prefix] != 1:
                    prefix = "%s-%s" % (prefix, prefixes[prefix])
                formset = FormSet(instance=obj, prefix=prefix,
                                  queryset=inline.queryset(request))
                formsets.append(formset)

        #### begin modification ####
        media = self.media or []
        #### end modification ####
        inline_admin_formsets = []
        for inline, formset in zip(self.inline_instances, formsets):
            fieldsets = list(inline.get_fieldsets(request, obj))
            readonly = list(inline.get_readonly_fields(request, obj))
            inline_admin_formset = helpers.InlineAdminFormSet(inline, formset,
                fieldsets, readonly, model_admin=self)
            #### begin modification ####
            self.add_lang_templ_params(inline_admin_formset)
            #### end modification ####
            inline_admin_formsets.append(inline_admin_formset)
            media = media + inline_admin_formset.media

        #### begin modification ####
        adminForm = OrderedAdminForm(form, self.get_fieldsets_with_inlines(request, obj),
            self.prepopulated_fields, self.get_readonly_fields(request, obj),
            model_admin=self, inlines=inline_admin_formsets)
        media = media + adminForm.media
        #### end modification ####

        context = {
            'title': _('Change %s') % force_unicode(opts.verbose_name),
            'adminform': adminForm,
            'object_id': object_id,
            'original': obj,
            'is_popup': "_popup" in request.REQUEST or \
                        "_popup_o2m" in request.REQUEST,
            'media': mark_safe(media),
            'inline_admin_formsets': inline_admin_formsets,
            'errors': helpers.AdminErrorList(form, formsets),
            'root_path': self.admin_site.root_path,
            'app_label': opts.app_label,
            'kb_link': settings.KNOWLEDGE_BASE_URL,
            'comp_name': _('%s') % force_unicode(opts.verbose_name),
        }
        context.update(extra_context or {})

        #### begin modification ####
        # redirection for reusable entities which are no master copies:
        if hasattr(obj, 'copy_status') and obj.copy_status != MASTER:
            context['url'] = obj.source_url
            context_instance = template.RequestContext(
                request, current_app=self.admin_site.name)
            return render_to_response('admin/repository/cannot_edit.html',
                context, context_instance=context_instance)
        # redirection for resources and their parts which are no master copies:
        else:
            for res in [r for r in get_root_resources(obj)
                        if not r.storage_object.master_copy]:
                context['redirection_url'] = model_utils.get_lr_master_url(res)
                context['resource'] = res
                context_instance = template.RequestContext(
                    request, current_app=self.admin_site.name)
                return render_to_response('admin/repository/cannot_edit.html',
                    context, context_instance=context_instance)
        #### end modification ####

        return self.render_change_form(request, context, change=True, obj=obj)
Example #2
0
def download(request, object_id):
    """
    Renders the resource download/purchase view including license selection,
    etc.
    """
    user_membership = _get_user_membership(request.user)

    # here we are only interested in licenses (or their names) of the specified
    # resource that allow the current user a download/purchase
    resource = get_object_or_404(resourceInfoType_model,
                                 storage_object__identifier=object_id,
                                 storage_object__publication_status=PUBLISHED)
    licences = _get_licences(resource, user_membership)

    # Check whether the resource is from the current node, or whether it must be
    # redirected to the master copy
    if not resource.storage_object.master_copy:
        return render_to_response('repository/redirect.html',
                { 'resource': resource,
                  'redirection_url': model_utils.get_lr_master_url(resource) },
                context_instance=RequestContext(request))

    licence_choice = None
    if request.method == "POST":
        licence_choice = request.POST.get('licence', None)
        if licence_choice and 'in_licence_agree_form' in request.POST:
            la_form = LicenseAgreementForm(licence_choice, data=request.POST)
            if la_form.is_valid():
                # before really providing the download, we have to make sure
                # that the user hasn't tried to circumvent the permission system
                if licences[licence_choice][1]:
                    return _provide_download(request, resource,
                                licences[licence_choice][0].downloadLocation)
            else:
                return render_to_response('repository/licence_agreement.html',
                    { 'form': la_form, 'resource': resource,
                      'licence_name': licence_choice, 'licence_path': \
                      LICENCEINFOTYPE_URLS_LICENCE_CHOICES[licence_choice][0],
                      'download_available': licences[licence_choice][1] },
                    context_instance=RequestContext(request))
        elif licence_choice and not licence_choice in licences:
            licence_choice = None

    if len(licences) == 1:
        # no need to manually choose amongst 1 license ...
        licence_choice = licences.iterkeys().next()

    if licence_choice:
        return render_to_response('repository/licence_agreement.html',
            { 'form': LicenseAgreementForm(licence_choice),
              'resource': resource, 'licence_name': licence_choice, 
              'licence_path': \
                LICENCEINFOTYPE_URLS_LICENCE_CHOICES[licence_choice][0],
              'download_available': licences[licence_choice][1] },
            context_instance=RequestContext(request))
    elif len(licences) > 1:
        return render_to_response('repository/licence_selection.html',
            { 'form': LicenseSelectionForm(licences), 'resource': resource },
            context_instance=RequestContext(request))
    else:
        return render_to_response('repository/lr_not_downloadable.html',
                                  { 'resource': resource,
                                    'reason': 'no_suitable_license' },
                                  context_instance=RequestContext(request))
Example #3
0
def download(request, object_id):
    """
    Renders the resource download/purchase view including license selection,
    etc.
    """
    user_membership = _get_user_membership(request.user)

    # here we are only interested in licenses (or their names) of the specified
    # resource that allow the current user a download/purchase
    resource = get_object_or_404(resourceInfoType_model,
                                 storage_object__identifier=object_id,
                                 storage_object__publication_status=PUBLISHED)
    licences = _get_licences(resource, user_membership)

    # Check whether the resource is from the current node, or whether it must be
    # redirected to the master copy
    if not resource.storage_object.master_copy:
        return render_to_response('repository/redirect.html',
                { 'resource': resource,
                  'redirection_url': model_utils.get_lr_master_url(resource) },
                context_instance=RequestContext(request))

    licence_choice = None
    if request.method == "POST":
        licence_choice = request.POST.get('licence', None)
        if licence_choice and 'in_licence_agree_form' in request.POST:
            la_form = LicenseAgreementForm(licence_choice, data=request.POST)
            if la_form.is_valid():
                # before really providing the download, we have to make sure
                # that the user hasn't tried to circumvent the permission system
                if licences[licence_choice][1]:
                    return _provide_download(request, resource,
                                licences[licence_choice][0].downloadLocation)
            else:
                return render_to_response('repository/licence_agreement.html',
                    { 'form': la_form, 'resource': resource,
                      'licence_name': licence_choice, 'licence_path': \
                      LICENCEINFOTYPE_URLS_LICENCE_CHOICES[licence_choice][0],
                      'download_available': licences[licence_choice][1] },
                    context_instance=RequestContext(request))
        elif licence_choice and not licence_choice in licences:
            licence_choice = None

    if len(licences) == 1:
        # no need to manually choose amongst 1 license ...
        licence_choice = licences.iterkeys().next()

    if licence_choice:
        return render_to_response('repository/licence_agreement.html',
            { 'form': LicenseAgreementForm(licence_choice),
              'resource': resource, 'licence_name': licence_choice, 
              'licence_path': \
                LICENCEINFOTYPE_URLS_LICENCE_CHOICES[licence_choice][0],
              'download_available': licences[licence_choice][1] },
            context_instance=RequestContext(request))
    elif len(licences) > 1:
        return render_to_response('repository/licence_selection.html',
            { 'form': LicenseSelectionForm(licences), 'resource': resource },
            context_instance=RequestContext(request))
    else:
        return render_to_response('repository/lr_not_downloadable.html',
                                  { 'resource': resource,
                                    'reason': 'no_suitable_license' },
                                  context_instance=RequestContext(request))
Example #4
0
    def change_view(self, request, object_id, form_url='', extra_context=None):
        """
        The 'change' admin view for this model.
        This follows closely the base implementation from Django 1.4's
        django.contrib.admin.options.ModelAdmin,
        with the explicitly marked modifications.
        """
        # pylint: disable-msg=C0103
        model = self.model
        opts = model._meta

        obj = self.get_object(request, unquote(object_id))

        if not self.has_change_permission(request, obj):
            raise PermissionDenied

        #### begin modification ####
        # make sure that the user has a full session length time for the current
        # edit activity
        request.session.set_expiry(settings.SESSION_COOKIE_AGE)
        #### end modification ####

        if obj is None:
            raise Http404(
                _('%(name)s object with primary key %(key)r does not exist.') %
                {
                    'name': force_unicode(opts.verbose_name),
                    'key': escape(object_id)
                })

        if request.method == 'POST' and "_saveasnew" in request.POST:
            return self.add_view(
                request,
                form_url=reverse('admin:%s_%s_add' %
                                 (opts.app_label, opts.module_name),
                                 current_app=self.admin_site.name))

        ModelForm = self.get_form(request, obj)
        formsets = []
        inline_instances = self.get_inline_instances(request)
        if request.method == 'POST':
            form = ModelForm(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                form_validated = True
                new_object = self.save_form(request, form, change=True)
            else:
                form_validated = False
                new_object = obj
            prefixes = {}
            for FormSet, inline in zip(self.get_formsets(request, new_object),
                                       inline_instances):
                #### begin modification ####
                if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                    continue
                #### end modification ####
                prefix = FormSet.get_default_prefix()
                prefixes[prefix] = prefixes.get(prefix, 0) + 1
                if prefixes[prefix] != 1 or not prefix:
                    prefix = "%s-%s" % (prefix, prefixes[prefix])
                formset = FormSet(request.POST,
                                  request.FILES,
                                  instance=new_object,
                                  prefix=prefix,
                                  queryset=inline.queryset(request))
                #### begin modification ####
                if prefix in self.model.get_fields()['required']:
                    self.set_required_formset(formset)
                #### end modification ####

                formsets.append(formset)

            if all_valid(formsets) and form_validated:
                #### begin modification ####
                for formset in formsets:
                    # this replaces the call to self.save_formsets()
                    changes = formset.save()
                    # if there are any changes in the current inline and if this
                    # inline is a reverse inline, then we need to manually make
                    # sure that the inline data is connected to the parent
                    # object:
                    if changes:
                        parent_fk_name = getattr(formset, 'parent_fk_name', '')
                        if parent_fk_name:
                            assert len(changes) == 1
                            setattr(new_object, parent_fk_name, changes[0])
                    # If we have deleted a one-to-one inline, we must manually unset the field value.
                    if formset.deleted_objects:
                        parent_fk_name = getattr(formset, 'parent_fk_name', '')
                        if parent_fk_name:
                            setattr(new_object, parent_fk_name, None)

                self.save_model(request, new_object, form, change=True)
                form.save_m2m()
                # for resource info, explicitly write its metadata XML and
                # storage object to the storage folder
                if self.model.__schema_name__ == "resourceInfo":
                    new_object.storage_object.update_storage()
                #### end modification ####

                change_message = self.construct_change_message(
                    request, form, formsets)
                self.log_change(request, new_object, change_message)
                return self.response_change(request, new_object)

        else:
            form = ModelForm(instance=obj)
            prefixes = {}
            for FormSet, inline in zip(self.get_formsets(request, obj),
                                       inline_instances):
                #### begin modification ####
                if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                    continue
                #### end modification ####
                prefix = FormSet.get_default_prefix()
                prefixes[prefix] = prefixes.get(prefix, 0) + 1
                if prefixes[prefix] != 1 or not prefix:
                    prefix = "%s-%s" % (prefix, prefixes[prefix])
                formset = FormSet(instance=obj,
                                  prefix=prefix,
                                  queryset=inline.queryset(request))
                formsets.append(formset)

        #### begin modification ####
        media = self.media or []
        #### end modification ####
        inline_admin_formsets = []
        for inline, formset in zip(inline_instances, formsets):
            fieldsets = list(inline.get_fieldsets(request, obj))
            readonly = list(inline.get_readonly_fields(request, obj))
            prepopulated = dict(inline.get_prepopulated_fields(request, obj))
            inline_admin_formset = helpers.InlineAdminFormSet(inline,
                                                              formset,
                                                              fieldsets,
                                                              prepopulated,
                                                              readonly,
                                                              model_admin=self)
            #### begin modification ####
            self.add_lang_templ_params(inline_admin_formset)
            #### end modification ####
            inline_admin_formsets.append(inline_admin_formset)
            media = media + inline_admin_formset.media
        #### begin modification ####
        adminForm = OrderedAdminForm(
            form,
            self.get_fieldsets_with_inlines(request, obj),
            self.get_prepopulated_fields(request, obj),
            self.get_readonly_fields(request, obj),
            model_admin=self,
            inlines=inline_admin_formsets)
        media = media + adminForm.media
        #### end modification ####

        context = {
            'title': _('Change %s') % force_unicode(opts.verbose_name),
            'adminform': adminForm,
            'object_id': object_id,
            'original': obj,
            'is_popup': "_popup" in request.REQUEST or \
                        "_popup_o2m" in request.REQUEST,
            'media': media,
            'inline_admin_formsets': inline_admin_formsets,
            'errors': helpers.AdminErrorList(form, formsets),
            'app_label': opts.app_label,
            'kb_link': settings.KNOWLEDGE_BASE_URL,
            'comp_name': _('%s') % force_unicode(opts.verbose_name),
        }
        context.update(extra_context or {})

        #### begin modification ####
        # redirection for reusable entities which are no master copies:
        if hasattr(obj, 'copy_status') and obj.copy_status != MASTER:
            context['url'] = obj.source_url
            context_instance = template.RequestContext(
                request, current_app=self.admin_site.name)
            return render_to_response('admin/repository/cannot_edit.html',
                                      context,
                                      context_instance=context_instance)
        # redirection for resources and their parts which are no master copies:
        else:
            for res in [
                    r for r in get_root_resources(obj)
                    if not r.storage_object.master_copy
            ]:
                context['redirection_url'] = model_utils.get_lr_master_url(res)
                context['resource'] = res
                context_instance = template.RequestContext(
                    request, current_app=self.admin_site.name)
                return render_to_response('admin/repository/cannot_edit.html',
                                          context,
                                          context_instance=context_instance)
        #### end modification ####

        return self.render_change_form(request,
                                       context,
                                       change=True,
                                       obj=obj,
                                       form_url=form_url)
Example #5
0
    def changeform_view(self,
                        request,
                        object_id=None,
                        form_url='',
                        extra_context=None):
        """
        This follows closely the base implementation from Django 1.7's
        django.contrib.admin.options.ModelAdmin,
        with the explicitly marked modifications.
        """
        to_field = request.POST.get(TO_FIELD_VAR,
                                    request.GET.get(TO_FIELD_VAR))
        if to_field and not self.to_field_allowed(request, to_field):
            raise DisallowedModelAdminToField(
                "The field %s cannot be referenced." % to_field)

        model = self.model
        opts = model._meta
        add = object_id is None

        if add:
            if not self.has_add_permission(request):
                raise PermissionDenied
            obj = None

        else:
            obj = self.get_object(request, unquote(object_id))

            if not self.has_change_permission(request, obj):
                raise PermissionDenied

            if obj is None:
                raise Http404(
                    _('%(name)s object with primary key %(key)r does not exist.'
                      ) % {
                          'name': force_text(opts.verbose_name),
                          'key': escape(object_id)
                      })

            if request.method == 'POST' and "_saveasnew" in request.POST:
                return self.add_view(
                    request,
                    form_url=reverse('admin:%s_%s_add' %
                                     (opts.app_label, opts.model_name),
                                     current_app=self.admin_site.name))

        #### begin modification ####
        # make sure that the user has a full session length time for the current
        # edit activity
        request.session.set_expiry(settings.SESSION_COOKIE_AGE)
        #### end modification ####

        ModelForm = self.get_form(request, obj)
        if request.method == 'POST':
            form = ModelForm(request.POST, request.FILES, instance=obj)
            if form.is_valid():
                form_validated = True
                new_object = self.save_form(request, form, change=not add)
            else:
                form_validated = False
                new_object = form.instance
            formsets, inline_instances = self._create_formsets(request,
                                                               new_object,
                                                               change=not add)
            if all_valid(formsets) and form_validated:
                #### begin modification ####
                unsaved_formsets = []
                for formset in formsets:
                    parent_fk_name = getattr(formset, 'parent_fk_name', '')
                    # for the moment ignore all formsets that are no reverse
                    # inlines
                    if add:
                        if not parent_fk_name:
                            unsaved_formsets.append(formset)
                            continue

                    # this replaces the call to self.save_formsets()
                    changes = formset.save()
                    # if there are any changes in the current inline and if this
                    # inline is a reverse inline, then we need to manually make
                    # sure that the inline data is connected to the parent
                    # object:
                    if changes:
                        if parent_fk_name:
                            assert len(changes) == 1
                            setattr(new_object, parent_fk_name, changes[0])

                    # If we have deleted a one-to-one inline, we must manually
                    # unset the field value.
                    if formset.deleted_objects:
                        if parent_fk_name:
                            setattr(new_object, parent_fk_name, None)

                self.save_model(request, new_object, form, not add)
                form.save_m2m()

                for formset in unsaved_formsets:
                    self.save_formset(request, form, formset, add)

                # for resource info, explicitly write its metadata XML and
                # storage object to the storage folder
                if self.model.__schema_name__ == "resourceInfo":
                    new_object.storage_object.update_storage()
                #### end modification ####
                if add:
                    self.log_addition(request, new_object)
                    return self.response_add(request, new_object)
                else:
                    change_message = self.construct_change_message(
                        request, form, formsets)
                    self.log_change(request, new_object, change_message)
                    return self.response_change(request, new_object)
        else:
            if add:
                initial = self.get_changeform_initial_data(request)
                form = ModelForm(initial=initial)
                formsets, inline_instances = self._create_formsets(
                    request, self.model(), change=False)
            else:
                form = ModelForm(instance=obj)
                formsets, inline_instances = self._create_formsets(request,
                                                                   obj,
                                                                   change=True)

        #### begin modification ####
        media = self.media or []
        #### end modification ####

        inline_formsets = self.get_inline_formsets(request, formsets,
                                                   inline_instances, obj)
        for inline_formset in inline_formsets:
            media = media + inline_formset.media

        #### begin modification ####
        adminForm = OrderedAdminForm(
            form,
            list(self.get_fieldsets_with_inlines(request)),
            self.prepopulated_fields,
            self.get_readonly_fields(request, obj),
            model_admin=self,
            inlines=inline_formsets)
        media = media + adminForm.media
        #### end modification ####

        context = dict(self.admin_site.each_context(),
            title=(_('Add %s') if add else _('Change %s')) % force_text(opts.verbose_name),
            adminform=adminForm,
            object_id=object_id,
            original=obj,
            is_popup=(IS_POPUP_VAR in request.REQUEST or \
                      IS_POPUP_O2M_VAR in request.REQUEST),
            to_field=to_field,
            media=media,
            inline_admin_formsets=inline_formsets,
            errors=helpers.AdminErrorList(form, formsets),
            preserved_filters=self.get_preserved_filters(request),
            kb_link=settings.KNOWLEDGE_BASE_URL,
            app_label=opts.app_label,
            show_delete=False,
        )

        context.update(extra_context or {})

        #### begin modification ####
        if not add:
            # redirection for reusable entities which are no master copies:
            if hasattr(obj, 'copy_status') and obj.copy_status != MASTER:
                context['url'] = obj.source_url
                context_instance = template.RequestContext(
                    request, current_app=self.admin_site.name)
                return render_to_response('admin/repository/cannot_edit.html',
                                          context,
                                          context_instance=context_instance)
            # redirection for resources and their parts which are no master copies:
            else:
                for res in [
                        r for r in get_root_resources(obj)
                        if not r.storage_object.master_copy
                ]:
                    context['redirection_url'] = model_utils.get_lr_master_url(
                        res)
                    context['resource'] = res
                    context_instance = template.RequestContext(
                        request, current_app=self.admin_site.name)
                    return render_to_response(
                        'admin/repository/cannot_edit.html',
                        context,
                        context_instance=context_instance)
        #### end modification ####
        return self.render_change_form(request,
                                       context,
                                       add=add,
                                       change=not add,
                                       obj=obj,
                                       form_url=form_url)
Example #6
0
 def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
     """
     This follows closely the base implementation from Django 1.7's
     django.contrib.admin.options.ModelAdmin,
     with the explicitly marked modifications.
     """
     to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
     if to_field and not self.to_field_allowed(request, to_field):
         raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field)
 
     model = self.model
     opts = model._meta
     add = object_id is None
 
     if add:
         if not self.has_add_permission(request):
             raise PermissionDenied
         obj = None
 
     else:
         obj = self.get_object(request, unquote(object_id))
 
         if not self.has_change_permission(request, obj):
             raise PermissionDenied
         if obj is None:
             return HttpResponseNotFound(_('%(name)s object with primary key %(key)r does not exist.') % {
                 'name': force_text(opts.verbose_name), 'key': escape(object_id)})
         
         if request.method == 'POST' and "_saveasnew" in request.POST:
             return self.add_view(request, form_url=reverse('admin:%s_%s_add' % (
                 opts.app_label, opts.model_name),
                 current_app=self.admin_site.name))
     
     request.session.set_expiry(settings.SESSION_COOKIE_AGE)
     
     ModelForm = self.get_form(request, obj)
     formsets = []
     if request.method == 'POST':
         form = ModelForm(request.POST, request.FILES, instance=obj)
         if form.is_valid():
             form_validated = True
             new_object = self.save_form(request, form, change=not add)
         else:
             form_validated = False
             new_object = form.instance
             
         prefixes = {}
         
         for FormSet, inline in zip(self.get_formsets(request, new_object), self.inline_instances):
             #### begin modification ####
             if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                 continue
             #### end modification ####
             prefix = FormSet.get_default_prefix()
             prefixes[prefix] = prefixes.get(prefix, 0) + 1
             if prefixes[prefix] != 1 or not prefix:
                 prefix = "%s-%s" % (prefix, prefixes[prefix])
             formset = FormSet(data=request.POST, files=request.FILES,
                               instance=new_object,
                               save_as_new="_saveasnew" in request.POST,
                               prefix=prefix, queryset=inline.queryset(request))
             #### begin modification ####
             if prefix in self.model.get_fields()['required']:
                 self.set_required_formset(formset)
             #### end modification ####
             formsets.append(formset)
         
         if all_valid(formsets) and form_validated:
             #### begin modification ####
             unsaved_formsets = []
             for formset in formsets:
                 parent_fk_name = getattr(formset, 'parent_fk_name', '')
                 # for the moment ignore all formsets that are no reverse
                 # inlines
                 if not parent_fk_name:
                     unsaved_formsets.append(formset)
                     continue
                 # this replaces the call to self.save_formsets()
                 changes = formset.save()
                 # if the current reverse inline is used (i.e., filled with
                 # data), then we need to manually make sure that the inline
                 # data is connected to the parent object:
                 if changes:
                     parent_fk_name = getattr(formset, 'parent_fk_name', '')
                     # for the moment ignore all formsets that are no reverse
                     # inlines
                     if parent_fk_name:
                         # if the current reverse inline is used (i.e., filled with
                         # data), then we need to manually make sure that the inline
                         # data is connected to the parent object:
                         assert len(changes) == 1
                         setattr(new_object, parent_fk_name, changes[0])
                 if not add:
                     # If we have deleted a one-to-one inline, we must manually unset the field value.
                     if formset.deleted_objects:
                         parent_fk_name = getattr(formset, 'parent_fk_name', '')
                         if parent_fk_name:
                             setattr(new_object, parent_fk_name, None)
             self.save_model(request, new_object, form, not add)
             self.save_related(request, form, formsets, not add)
             for formset in unsaved_formsets:
                 self.save_formset(request, form, formset, not add)
             
             # for resource info, explicitly write its metadata XML and
             # storage object to the storage folder
             if self.model.__schema_name__ == "resourceInfo":
                 new_object.storage_object.update_storage()
             #### end modification ####
             if add:
                 self.log_addition(request, new_object)
                 return self.response_add(request, new_object)
             else:
                 change_message = self.construct_change_message(request, form, formsets)
                 self.log_change(request, new_object, change_message)
                 return self.response_change(request, new_object)
     else:
         if add:
             # Prepare the dict of initial data from the request.
             # We have to special-case M2Ms as a list of comma-separated PKs.
             initial = dict(request.GET.items())
             for k in initial:
                 try:
                     f = opts.get_field(k)
                 except models.FieldDoesNotExist:
                     continue
                 if isinstance(f, models.ManyToManyField):
                     initial[k] = initial[k].split(",")
             form = ModelForm(initial=initial)
             prefixes = {}
             for FormSet, inline in zip(self.get_formsets(request),
                                        self.inline_instances):
                 #### begin modification ####
                 if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                     continue
                 #### end modification ####
                 prefix = FormSet.get_default_prefix()
                 prefixes[prefix] = prefixes.get(prefix, 0) + 1
                 if prefixes[prefix] != 1:
                     prefix = "%s-%s" % (prefix, prefixes[prefix])
                 formset = FormSet(instance=self.model(), prefix=prefix,
                                   queryset=inline.queryset(request))
                 formsets.append(formset)
         else:
             form = ModelForm(instance=obj)
             prefixes = {}
             for FormSet, inline in zip(self.get_formsets(request, obj), self.inline_instances):
                 #### begin modification ####
                 if getattr(FormSet, 'parent_fk_name', None) in self.no_inlines:
                     continue
                 #### end modification ####
                 prefix = FormSet.get_default_prefix()
                 prefixes[prefix] = prefixes.get(prefix, 0) + 1
                 if prefixes[prefix] != 1:
                     prefix = "%s-%s" % (prefix, prefixes[prefix])
                 formset = FormSet(instance=obj, prefix=prefix,
                                   queryset=inline.queryset(request))
                 formsets.append(formset)
             
     #### begin modification ####
     media = self.media or []
     #### end modification ####
     inline_admin_formsets = []
     prepopulated = {}
     for inline, formset in zip(self.inline_instances, formsets):
         fieldsets = list(inline.get_fieldsets(request))
         readonly = list(inline.get_readonly_fields(request))
         prepopulated.update(dict(inline.get_prepopulated_fields(request, obj)))
         inline_admin_formset = helpers.InlineAdminFormSet(inline, formset,
             fieldsets, prepopulated, readonly, model_admin=self)
         #### begin modification ####
         self.add_lang_templ_params(inline_admin_formset)
         #### end modification ####
         inline_admin_formsets.append(inline_admin_formset)
         media = media + inline_admin_formset.media
         
     adminForm = OrderedAdminForm(form, list(self.get_fieldsets_with_inlines(request, obj)),
         prepopulated, self.get_readonly_fields(request),
         model_admin=self, inlines=inline_admin_formsets)
     
     media = media + adminForm.media
     context = dict(self.admin_site.each_context(),
         title=(_('Add %s') if add else _('Change %s')) % force_text(opts.verbose_name),
         adminform=adminForm,
         object_id=object_id,
         original=obj,
         is_popup=(IS_POPUP_VAR in request.POST or
                   IS_POPUP_VAR in request.GET),
         to_field=to_field,
         media=mark_safe(media),
         inline_admin_formsets=inline_admin_formsets,
         errors=helpers.AdminErrorList(form, formsets),
         preserved_filters=self.get_preserved_filters(request),
         kb_link=settings.KNOWLEDGE_BASE_URL,
         root_path=self.admin_site.site_url,
         app_label=opts.app_label,
         show_delete=False,
     )
 
     context.update(extra_context or {})
     if not add:
         #### begin modification ####
         # redirection for reusable entities which are no master copies:
         if hasattr(obj, 'copy_status') and obj.copy_status != MASTER:
             context['url'] = obj.source_url
             context_instance = template.RequestContext(
                 request, current_app=self.admin_site.name)
             return render_to_response('admin/repository/cannot_edit.html',
                 context, context_instance=context_instance)
         # redirection for resources and their parts which are no master copies:
         else:
             for res in [r for r in get_root_resources(obj)
                         if not r.storage_object.master_copy]:
                 context['redirection_url'] = model_utils.get_lr_master_url(res)
                 context['resource'] = res
                 context_instance = template.RequestContext(
                     request, current_app=self.admin_site.name)
                 return render_to_response('admin/repository/cannot_edit.html',
                     context, context_instance=context_instance)
         #### end modification ####
     return self.render_change_form(request, context, add=add, change=not add, obj=obj, form_url=form_url)