How To Asynchronously Retrieve Web-Service-Based Master Page Content in MVC3 - web-services

I'm developing an application that uses a parent controller class and a common Master page to make hundreds of database configuration fields available to multiple child controllers (like a "wrapper" class). I'm adding an external web service/feed that will also be used by all child controllers. It will read content from an XML, text or HTML file on a remote web server and use it on the Master page that is being shared by all Views (i.e. common content to all pages coming from an external source). However, I need to use an asynchronous pipeline to handle the request so that it's not tying up server threads waiting for calls to these remote web services.
Is there a way I can use MVC's AsyncController to accomplish this? I understand how it works in a simple scenario where I have a basic controller and a couple of Action Results. But this application has about 20 different Action methods in various controllers, and I really don't want to have to split all of them up into "Async" and "Completed" methods, especially since the retrieved data is only being displayed on the common Master page. Is there something I can implement at the "parent" controller level so that it's inherited by all the child controllers, or only in the Master page itself?

Related

Django: implementing websockets to work with my existing MVT-based app (Channels seems to need me to throw out my entire existing code)

I have an existing Django project in the sports domain with apps that are built on the Model-View-Template structure. Many of the models and views are fairly sophisticated and work well currently. Data from the database (scores etc) is combined with some incoming user inputs through forms (HTTP POST requests) to be displayed on a web page via templates.
However, I now need live data to be displayed to users and be automatically refreshed to all the users continuously, either because one of the users entered something new (in the front-end), or because the scores changed during the game (directly enters the back-end).
I've done some research on Stack Overflow as well as tutorials on Youtube/ rest of the web and it appears that for me to use Django Channels, I'd have to start from scratch and build everything ground-up, which I'd like to avoid. How do I use the websocket protocol for my Django app easily without having to completely rework everything that I've done so far?
You don't really need to start from scratch or anything. You just need to add a module using channels. I am assuming that currently, the data is fetched only when the page is refreshed. What you need to do is write a consumer that is used to send messages directly to the client via websocket. Then in the front you can update the widget with the scores on each message received in the websocket. You can also stream user actions through the websocket to the server which will then be broadcasted by the consumer to needed clients. You may not even need to change anything in the existing code.
It will be easier to understand how this works and how you can incorporate it to your project by reading the channels tutorials. It became clearer to me after reading it so I would advice you do the same

How to structure a project directory in django?

Suppose you are building a Google website. (ok big dream)
Google has web search/youtube/email/news/etc ..
For this site, I'd like to structure my django directory like
Google/
search
youtube
email
news
and so on.
How do I structure such a site?
Create an app for each even though I'm not expecting to publish any of the category as an app?
Where would a common stuff (such as user model, utility modules, decorators..) would go, create a common_app?
Applications are reusable components for a django project that revolve around a central purpose. Applications don't need to map directly to your url structure of the website. While there is a standard structure for a django application to tie in with some of the management commands, such as tests.py, models.py, static files at /static/ you don't need to have any of it to be an application. For example, South is a popular django application used to provide database migrations. It adds a few management commands to manage.py.
When you are adding functionality and it doesn't map directly to the purpose of the application, just create a new one. So instead of thinking of it a a common_app, think about what the purpose of the application would be and how it might be utilized by your other applications.
In my projects, I tend to create a base application to handle the base template and static assets that are used in the base template. I'll create an accounts application to handle the user model and implement things like password reset. To deal with global notifications from any part of my site, I'll create an alerts application. The list can go on for a lot of the common functionality, but it's grouped in a way that revolves around a function and written as if it would be distributed.
So, in your specific case, you'll likely have at least an application for each of the domains such as search, youtube, email, and news, but also an application for each common component you might want to use across your core domains.

Multiple stateful components with Ember Router

I am writing an Ember app that consists of a handful of complex, stateful components. I am having trouble wrapping my head around how Ember handles this kind of app as it is not the traditional CRUD app.
It is a highly interactive single page application. Some example components are
Xmpp Text Chat,
Multi party audio,
Xmpp Shared whiteboard, and
Pop up notifications
There is a global state (which I can see handling via the router) that sets the user context (who I am working with on the audio/whiteboard). What I don't quite understand is what role if any the router would play in setting chat context which is unrelated to Audio and Whiteboard but still stateful. I can't picture how the URL string from the router can reflect state from all of these components simultaneously.
Is this a case where I skip using the router entirely? If so how can I link my application's views/controllers? Up till now I have been using the router's connectOutlets method to link my views and controllers. Without calling this method what would be another (structured and organized) way to do this binding?
Thanks
Good question!
Global state: Use the router
Application state: In controller singletons associated with your application components
As a general rule I recommend using the router to manage state that a user can bookmark or use browser forward/back buttons to interact with. Just guessing but for your app that might include id of the whiteboard.
Components like chat, audio, and notifications would typically exist and maintain state independent of the router. In some cases these components might behave differently depending on the route (like chat might bind to a specific channel depending on which whiteboard is shown) but the state of the chat widget itself be stored as properties on the ChatController singleton.
The ember guides are not complete yet, but you may find the last section of the controllers guide "Storing Application Properties" helpful http://emberjs.com/guides/controllers/

HMVC framework for Coldfusion?

I'm given a task to develop a couple of applications in ColdFusion that will share some of the data - same data but different presentation.
The first solution that comes in mind is to create a ColdFusion widget that as I understand breaks some MVC rules within ColdBox I am currently using. I need more of a view within another view with its own controller and model (all in CFML, no Ajax). My understanding is that MVC does not support such hierarchy whilst its inherent in HMVC.
Any suggestion on the graceful workaround and/or alternative HMVC framework?
You can use ColdBox Viewlets, which basically makes the views self sufficient when rendered. This means that you basically render the widget "renderView("widgets/myWidget")" Then inside of your widget, you will broadcast an event for data retrieval. Basically, calling the view's controller layer.
Then your widget will be ready for use and be bound only to its announced event.
I am not sure I am understanding your question correctly, but with mvc, you should be able to have two views using the same model. Or, you could split the model out into a different place using webservices or something like that, and then have your model in your two different apps connect to it to retrieve your data. Or am I misunderstanding?

Plone-like search box in Django?

Plone has a beautiful search box with a "Google suggest" like functionality for its site. It even indexes uploaded documents like PDFs. Does anyone know of a module that can provide this kind of functionality in a Django site?
Plone implements it's LiveSearch feature by maintaining a separate metadata table of indexed attributes (fields such as last modified, creator, title are copied from the content objects into this table). Content objects then send ObjectAdded/ObjectModified/ObjectRemoved events, and an event subscriber listens for these events and is responsible for updating the metadata table (in Django events are named signals). Then there is a Browser View exposed at a fixed URL that searches the metadata and returns the appropriate LiveSearch HTML, and finally each HTML page is sent the appropriate JavaScript to handle the autocomplete AJAX functionality to query this view and slot the resulting HTML results into the DOM.
If you want your LiveSearch to query multiple Models/Content Types, you are likely going to need to send your own events and have a subscriber handle them appropriately. This isn't necessary for a smaller data sets or lower traffic sites, where the performance penalty for doing multiple queries for a single search isn't a concern (or you only want to search a single content type) and you can just do several queries from your View.
As for the JavaScript side, you can roll-your-own or use an existing JavaScript library. This is usually called autocomplete in the JS library. There is YUI autocomplete and Scriptaculous autocomplete for starters, and likely lots more JavaScript autocomplete implementations out there. Plone uses KSS for it's JavaScript library, the KSS livesearch plugin is a good place to start if looking for example code to pluck from.
http://pypi.python.org/pypi/kss.plugin.livesearch
And a tutorial on using KSS with Django:
http://kssproject.org/docs/tutorial/kss-in-django-with-kss-django-application
KSS is quite nice since it cleanly separates behaviour from content on the client side (without needing to write JavaScript), but Scriptaculous is conceptually a little simpler and has somewhat better documentation (http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter).