Skip to content

Commit

Permalink
Refactor page title handling into own method
Browse files Browse the repository at this point in the history
It's not unlikely that a custom deployment would like to change the
title handling. Also adds a more sensible title when editing child
products without a title (instead of showing the parent's title).
  • Loading branch information
maiksprenger committed Aug 1, 2014
1 parent 765c72e commit afe5d23
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions oscar/apps/dashboard/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,26 @@ def get_context_data(self, **kwargs):
ctx = super(ProductCreateUpdateView, self).get_context_data(**kwargs)
ctx['product_class'] = self.product_class
ctx['parent'] = self.parent
ctx['title'] = self.get_page_title()

for ctx_name, formset_class in six.iteritems(self.formsets):
if ctx_name not in ctx:
ctx[ctx_name] = formset_class(self.product_class,
self.request.user,
instance=self.object)
return ctx

if self.object is not None:
ctx['title'] = self.object.get_title()
elif self.parent is not None:
ctx['title'] = _('Create new variant of %s') % self.parent.title
def get_page_title(self):
if self.creating:
if self.parent is None:
return _('Create new %s product') % self.product_class.name

This comment has been minimized.

Copy link
@codeinthehole

codeinthehole Aug 12, 2014

Contributor

When merging variables into translated strings, is it a best practice to always have a named variable? Or does it not matter when there's only one?

This comment has been minimized.

Copy link
@mbertheau

mbertheau Aug 12, 2014

Contributor

I think for context a named variable is better.

else:
return _('Create new variant of %s') % self.parent.title
else:
ctx['title'] = _('Create new %s product') % self.product_class.name
return ctx
if self.object.title:
return self.object.title
else:
return _('Editing variant of %s') % self.parent.title

def get_form_kwargs(self):
kwargs = super(ProductCreateUpdateView, self).get_form_kwargs()
Expand Down

0 comments on commit afe5d23

Please sign in to comment.