Opened 12 years ago

Closed 12 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: dev
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 by Marc Tamlyn, 12 years ago

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

comment:2 by Karol Sikora, 12 years ago

Owner: changed from nobody to Karol Sikora
Status: newassigned

comment:3 by Markus Holtermann, 12 years ago

Cc: info@… added

comment:4 by Karol Sikora, 12 years ago

Version 0, edited 12 years ago by Karol Sikora (next)

comment:5 by Karol Sikora <elektrrrus@…>, 12 years ago

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