Ticket #3529: context_update.2.patch

File context_update.2.patch, 1.0 KB (added by Chris Beaven, 17 years ago)
  • django/template/context.py

     
    5858                return d[key]
    5959        return otherwise
    6060
    61     def update(self, other_dict):
    62         "Like dict.update(). Pushes an entire dictionary's keys and values onto the context."
    63         self.dicts = [other_dict] + self.dicts
     61    def update(self, other_dict, push=True):
     62        """
     63        Similar to dict.update(). Updates the current context's keys and values
     64        from other_dict.
     65       
     66        If push is True, it will push the other_dict dictionary on to the
     67        context, otherwise the most recent context dictionary will be updated.
     68        """
     69        if push:
     70            self.dicts = [other_dict] + self.dicts
     71        else:
     72            self.dicts[0].update(other_dict)
    6473
    6574# This is a function rather than module-level procedural code because we only
    6675# want it to execute if somebody uses RequestContext.
Back to Top