Opened 2 years ago

Closed 2 years ago

#20236 closed Cleanup/optimization (fixed)

ModelFormMixin get_context_data() duplicates some/all of parent SingleObjectMixin

Reported by: dracos Owned by: elektrrrus
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 2 years ago by mjtamlyn

  • Cc marc.tamlyn@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/optimization

comment:2 Changed 2 years ago by elektrrrus

  • Owner changed from nobody to elektrrrus
  • Status changed from new to assigned

comment:3 Changed 2 years ago by MarkusH

  • Cc info@… added

comment:4 Changed 2 years ago by elektrrrus

Last edited 2 years ago by elektrrrus (previous) (diff)

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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