vkk.generic.mixins
A collection of reusable and extendable mixin classes.
1""" 2A collection of reusable and extendable mixin classes. 3""" 4 5from django.core.exceptions import ImproperlyConfigured 6from django.urls import reverse 7 8 9class OnSuccessMixin(): 10 """ 11 A simple mixin providing some functionality for redirecting after an successful action. 12 """ 13 on_success = None 14 drop_key = None 15 kwarg_override = None 16 17 def get_success_url(self): 18 """ 19 Return the URL meant for redirecting after a successful action. 20 """ 21 if not self.on_success: 22 raise ImproperlyConfigured( 23 "No name to redirect to. Provide a on_success.") 24 25 match = self.request.resolver_match 26 kwargs = match.kwargs 27 if self.kwarg_override is not None: 28 kwargs.update(self.kwarg_override) 29 namespaces = match.namespaces 30 31 if self.drop_key is not None and self.drop_key in kwargs: 32 del kwargs[self.drop_key] 33 34 return reverse( 35 ':'.join(namespaces + [self.on_success]), 36 kwargs=kwargs, 37 )
class
OnSuccessMixin:
10class OnSuccessMixin(): 11 """ 12 A simple mixin providing some functionality for redirecting after an successful action. 13 """ 14 on_success = None 15 drop_key = None 16 kwarg_override = None 17 18 def get_success_url(self): 19 """ 20 Return the URL meant for redirecting after a successful action. 21 """ 22 if not self.on_success: 23 raise ImproperlyConfigured( 24 "No name to redirect to. Provide a on_success.") 25 26 match = self.request.resolver_match 27 kwargs = match.kwargs 28 if self.kwarg_override is not None: 29 kwargs.update(self.kwarg_override) 30 namespaces = match.namespaces 31 32 if self.drop_key is not None and self.drop_key in kwargs: 33 del kwargs[self.drop_key] 34 35 return reverse( 36 ':'.join(namespaces + [self.on_success]), 37 kwargs=kwargs, 38 )
A simple mixin providing some functionality for redirecting after an successful action.
def
get_success_url(self):
18 def get_success_url(self): 19 """ 20 Return the URL meant for redirecting after a successful action. 21 """ 22 if not self.on_success: 23 raise ImproperlyConfigured( 24 "No name to redirect to. Provide a on_success.") 25 26 match = self.request.resolver_match 27 kwargs = match.kwargs 28 if self.kwarg_override is not None: 29 kwargs.update(self.kwarg_override) 30 namespaces = match.namespaces 31 32 if self.drop_key is not None and self.drop_key in kwargs: 33 del kwargs[self.drop_key] 34 35 return reverse( 36 ':'.join(namespaces + [self.on_success]), 37 kwargs=kwargs, 38 )
Return the URL meant for redirecting after a successful action.