<s> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from django . db import models <EOL> from django . http import HttpRequest <EOL> from pluggables . utils . picklefield import PickledObjectField <EOL> class PluggableManager ( models . Manager ) : <EOL> def pluggable ( self , request ) : <EOL> return self . filter ( pluggable_url = request . pluggable . pluggable_url_data ) <EOL> class PluggableModel ( models . Model ) : <EOL> pluggable_url = PickledObjectField ( blank = True ) <EOL> objects = PluggableManager ( ) <EOL> def save ( self , request , * args , ** kwargs ) : <EOL> if request : <EOL> self . pluggable_url = request . pluggable . pluggable_url_data <EOL> super ( PluggableModel , self ) . save ( * args , ** kwargs ) <EOL> class Meta : <EOL> abstract = True <EOL> class PluggableObjectManager ( PluggableManager ) : <EOL> def pluggable_object ( self , request ) : <EOL> if request . pluggable . view_context is None : <EOL> return self . filter ( pluggable_content_type__isnull = True , pluggable_object_id__isnull = True ) <EOL> else : <EOL> content_type = ContentType . objects . get_for_model ( request . pluggable . view_context ) <EOL> return self . filter ( pluggable_content_type = content_type , pluggable_object_id = request . pluggable . view_context . pk ) <EOL> class PluggableObjectModel ( PluggableModel ) : <EOL> pluggable_content_type = models . ForeignKey ( ContentType , null = True , blank = True ) <EOL> pluggable_object_id = models . PositiveIntegerField ( null = True , blank = True ) <EOL> pluggable_object = generic . GenericForeignKey ( fk_field = '<STR_LIT>' , ct_field = '<STR_LIT>' ) <EOL> objects = PluggableObjectManager ( ) <EOL> def save ( self , request , * args , ** kwargs ) : <EOL> if request : <EOL> self . pluggable_object = request . pluggable . view_context <EOL> super ( PluggableObjectModel , self ) . save ( request , * args , ** kwargs ) <EOL> class Meta : <EOL> abstract = True </s>
