Opened 4 years ago

Closed 4 years ago

#20236 closed Cleanup/optimization (fixed)

ModelFormMixin get_context_data() duplicates some/all of parent SingleObjectMixin

Reported by: Matthew Somerville Owned by: Karol Sikora
Component: Generic views Version: master
Severity: Normal Keywords:
Cc: marc.tamlyn@…, info@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The get_context_data function on ModelFormMixin sets context[context_object_name] if self.object and context_object_name are present - then its parent SingleObjectMixin does the same (without checking self.object). So ModelFormMixin's function could be reduced to:

def get_context_data(self, **kwargs):
    context = {}
    if self.object:
        context['object'] = self.object
    context.update(kwargs)
    return super(ModelFormMixin, self).get_context_data(**context)

If #20234 is applied, the get_context_data of ModelFormMixin becomes entirely superfluous, as then SingleObjectMixin sets context['object'] too, and it can just inherit its behaviour.

Change History (5)

comment:1 Changed 4 years ago by Marc Tamlyn

Cc: marc.tamlyn@… added
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:2 Changed 4 years ago by Karol Sikora

Owner: changed from nobody to Karol Sikora
Status: newassigned

comment:3 Changed 4 years ago by Markus Holtermann

Cc: info@… added

comment:4 Changed 4 years ago by Karol Sikora

Last edited 4 years ago by Karol Sikora (previous) (diff)

comment:5 Changed 4 years ago by Karol Sikora <elektrrrus@…>

Resolution: fixed
Status: assignedclosed

In 3eba8c7f7fc4877e7df0f83fe3bacd88082ac33e:

Fixed #20234 and #20236 -- SingleObjectMixin fixes

Added object on SingleObjectMixin returned context,
some code clanup.

Note: See TracTickets for help on using tickets.
Back to Top