|
I would like to add a 'draft' or 'private' mode to OSQA: Users should be able to post/answer one or more questions that only they are able to see. Later on they can decide to 'publish' them, so everyone else can see and answer those question too. What is the best way to implement this? I did the following: First I added a boolean field called 'private' to models.node.Node (using a forum_module and 'add_to_class' threw errors) A middleware checks when a user is in private or public mode by using a session variable. It then does the following: * In private mode, It wraps around 'NodeManager.get_query_set' to make it exclude all questions except the private questions of the current user. * In public mode, it filters out all private questions. * It changes the default value of the 'private' field according to the current mode: Node._meta.get_field('private').default = request.session['private_mode'] This is very slim (~20 lines) and nice by now. Unfortunately, some caching mechanism seems to get into my way: Once a private questions was accessed by its 'owner'/user, it can also be accessed by others via the same URL. (as long as the user did not access it this isn't the case) Now I came across the 'state' of Nodes, which I overlooked before. Wouldn't it be better to implement a private mode by adding a 'private' state to OSQA Nodes? Or should I go on with my 'private' field in models.node.Node? What do you consider the best way to implement a private mode? |
|
Finally everything works as expected; I did the following: Added the 'private' field in forum.models.Node. I want cutom skins, so I created and activated a custom Template-Loader which searches for templates if we are in private mode (it accesses the current thread to know this). The loader is based on forum.skins.SkinsTemplateLoader, and sits in a custom forum_module. In the normal urls.py I provide the private mode with
I created a custom urls_private.py where just the order of this changes:
The private mode is then accessible in '/private'. And if we are in private mode all Links will automatically get the 'private/' prefix. Added middleware which monitors the current private state. It does:
OSQA caches nodes. Cached private nodes would also be accessible by other users, so we prevent them from being cached in models.base.BaseModel.cache():
And a small function to publish threads, which is also located in a custom forum_module. And of course some minor changes in the templates: The possibility to switch the mode, custom CSS and so on. Everything works perfectly. The changes to the OSQA core are just 3 lines: the private field and preventing private nodes from being cached. Everything else works via a forum_module and middleware, which of course interfere with the core. SOunds like nice work, @Flipper. Part of OSQA's good performance is due to the use of very effective caching, so bypassing node caching could cause slowdown at some point.
(01 Mar, 06:49)
rickross ♦♦
Thanks! I'm aware of that. 'Public' nodes are still cached, so just the private mode will be a bit slower. There aren't many private questions yet, but it seems to not be a problem.
(01 Mar, 06:56)
Flipper
|