Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   OOP noob question: Mixin properties (http://www.velocityreviews.com/forums/t955444-oop-noob-question-mixin-properties.html)

Micky Hulse 12-13-2012 03:49 AM

OOP noob question: Mixin properties
 
Dear Python Santa gurus, ;D

I have this Django mixin:

<https://github.com/registerguard/django-ad-manager/blob/8628bfe70f6ca68cb7b0373cee7da52613c7531a/ad_manager/mixins.py>

....which is used to override render_to_response() so I can output a
JSON response (the above code is pretty much straight from the Django
docs: <https://docs.djangoproject.com/en/1.3/topics/class-based-views/#more-than-just-html>).

The JSONResponseMixin() gets added to my view class like so:

class Api(JSONResponseMixin, BaseDetailView):
# ...

Within my the mixins.py file, at the top of the file, I've added these
constants:

CACHE_TIMEOUT = 86400 # 24 hours.
CACHE_NAME = 'ad_manager_api'

Question(s):

I'd like to convert those constants to properties and make my
JSONResponseMixin() class more generic and portable.

Django aside, could someone provide OOP Python examples of how I could
instantiate a mixin Class and set/override its properties before
passing data to said mixin?

I hope you don't mind that this question involves Django... I'm just
looking to improve my core Python skills (so, generic Python examples
would be cool).

Many thanks in advance!

Cheers,
Micky


All times are GMT. The time now is 04:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57