Files
2012-02-21 01:15:00 -05:00

1 line
12 KiB
JSON

[{"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076784.2337711, "message": "You could either use a: $.load(...) where django gives HTML in ajax", "group_id": 81, "id": 854570}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304078162.9423079, "message": "either you use a template returned by javascript in which case your non ajax view template could include that template", "group_id": 81, "id": 854766}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076837.722667, "message": "I'm trying to find a way to avoid the \"dual\" code.. i.e. passing the information one time in html with djanog.. and one time in json", "group_id": 81, "id": 854576}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076705.323833, "message": "Say you load username in the Django templates..", "group_id": 81, "id": 854564}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076718.2867861, "message": "and then, you want to get new username by ajax", "group_id": 81, "id": 854566}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076806.0768399, "message": "or you could use something like backbone.js with your models and javascript template", "group_id": 81, "id": 854574}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304076857.6675949, "message": "I know it's not really clear, sorry.. but I was curious about the way you guys solve that?", "group_id": 81, "id": 854581}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304078057.7147329, "message": "I'm not sure I understand what you are looking for", "group_id": 81, "id": 854750}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304078127.830255, "message": "either you can replace the username by replacing the tag's content through javascript", "group_id": 81, "id": 854763}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304078190.946264, "message": "please replace javascript by ajax", "group_id": 81, "id": 854770}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304078463.6949871, "message": "I'd like to explain it more, I gotta run to job, I'll be back in a couple of time;( Sorry", "group_id": 81, "id": 854829}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304079562.422467, "message": "Breakout the parts of the template that you want to update through Ajax into their own template snippets. When serving the HTML, include the snippets in the main templates through {% include %} and when updating through Ajax render te snippets separately and send the resulting HTML in the response. This is a pretty easy pattern that follows generic DRY principles. For", "group_id": 81, "id": 855098}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304079727.461612, "message": "... more advanced scenarios, consider client-side templates (mustache.js, etc) and preload the javascript objects in a script tag (or take a look at backbone.js or similar client-side MVC frameworks)", "group_id": 81, "id": 855147}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084738.0599079, "message": "@ulmus exactly, that's the 2 situations I knew of", "group_id": 81, "id": 856343}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084750.547539, "message": "presently, I'm using the second solution", "group_id": 81, "id": 856345}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084880.2605169, "message": "So, for the backbone.js thing, I could do: OnLoad: Make all necessary ajax request.. but then, you waste lots of time / bandwith", "group_id": 81, "id": 856387}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084790.0150919, "message": "when you render the html for the first time, you need to provide the data in python objects.. then, when it's a ajax call, you return them in json.. so there's a kind of code duplication here.", "group_id": 81, "id": 856354}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084758.077986, "message": "with backbone.js.. the problem is during the \"first loading\"", "group_id": 81, "id": 856348}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084841.0431409, "message": "I've also tried the first solution, it's cute and works well.. the only thing I don't like is to give the html with ajax.. I find the json way cleaner (particularly with an API which returns the json so it's easier to test whereas you can't realy test something that returns html correctly)", "group_id": 81, "id": 856371}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304084725.034688, "message": "aight im back", "group_id": 81, "id": 856342}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304086696.9660289, "message": "Why doesn't you initial view call you ajax view to get the arguments ? or get one view either return a web page or an ajax answer ?", "group_id": 81, "id": 856797}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088100.1786671, "message": "if u want", "group_id": 81, "id": 857231}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304088228.983763, "message": "I just don't get what load_my_view does", "group_id": 81, "id": 857288}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304086878.4875641, "message": "Presently, my \"normal\" view call the ajax view, which returns json.. and I don't use django templates.. I just do something like: var bleh = {{ datas | safe }};", "group_id": 81, "id": 856848}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304086896.4881041, "message": "So, I \"manually\" load the json in my views at loading.. if you know what I mean", "group_id": 81, "id": 856856}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304087370.718333, "message": "make a function that returns your context and have one view process it to html another to json", "group_id": 81, "id": 856971}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304086830.22014, "message": "It does something like that.. the problem is my ajax view return JSON whereas my \"normal\" needs to have real python objects", "group_id": 81, "id": 856826}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304088027.8412449, "message": "however, I would be surprised you can't include the template part rendered by ajax within the original html page", "group_id": 81, "id": 857202}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304088083.416791, "message": "so, you get the common context variable from a commun function and the html page includes the ajax part through include tag for example", "group_id": 81, "id": 857222}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088005.858489, "message": "Hmm, well, it's not really backbone.. it's more about the fact that if you've got javascript MVC, you have json elements and you need to render them using a javascript template", "group_id": 81, "id": 857191}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088020.9414999, "message": "whereas, when you load the page with the django elements, you render them using the django templates", "group_id": 81, "id": 857199}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088319.750103, "message": "load_my_view is a javascript function which takes some json", "group_id": 81, "id": 857329}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088387.886976, "message": "that's the way I found to avoid duplicating everything", "group_id": 81, "id": 857369}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304087786.353025, "message": "You still get one html django template and one javascript template by doing it that way no?", "group_id": 81, "id": 857074}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088099.097038, "message": "<script..> load_my_view({{my_json_data|safe}})", "group_id": 81, "id": 857230}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088355.7137461, "message": "it gets called during an ajax call.. but also during the first page load by my django template.", "group_id": 81, "id": 857351}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304087956.1212549, "message": "I have no experiencec with backbone so things may be different", "group_id": 81, "id": 857160}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088070.6608651, "message": "well.. yeah, you can call some javascript functions with django's data", "group_id": 81, "id": 857218}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088428.670068, "message": "yeah", "group_id": 81, "id": 857380}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088208.8479769, "message": "yeah.. it's getting kind of complicated to follow :D", "group_id": 81, "id": 857278}, {"user_id": 26888, "stars": [], "topic_id": 21997, "date_created": 1304088413.6533909, "message": "ok, so you can indeed call it as you stated during the initial view :)", "group_id": 81, "id": 857376}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304088416.9047129, "message": "Like, my javascript templates are used even during the first loading of the page instead of the django's default one.", "group_id": 81, "id": 857378}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304093978.166379, "message": "it's just that in the code you need to have a normal view that returns django model, you need to have a ajax view that returns those models in json", "group_id": 81, "id": 859204}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304092863.7862239, "message": "Can't you bootstrap the backbone.js data on the page using collection.fetch( {{ mydjangomodels.my_jsonifier }} ) in the html template and then only use the client side templating, http://documentcloud.github.com/backbone/#FAQ-bootstrap", "group_id": 81, "id": 858909}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304093583.7513211, "message": "yeah, that's exactly what I'm doing", "group_id": 81, "id": 859082}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304093988.9565339, "message": "you need to have the .to_json on all your models", "group_id": 81, "id": 859211}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304095250.0051329, "message": "either a mixin class to serialize the model or a template filter \"jsonify\" that serializes the model?", "group_id": 81, "id": 859543}, {"user_id": 1917, "stars": [], "topic_id": 21997, "date_created": 1304094032.3197069, "message": "I'm sure there might be a way to simplify that..", "group_id": 81, "id": 859231}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304095562.0436139, "message": "The way I'm going with a similar setup is to avoid server side templates and views altogether and build a tastypie api and a static javascript frontend based on backbone.js. That way I can't bootstrap the initial data in the html, but the whole frontend is served statically, so a few extra ajax requests seems like a small price to pay to be able to put the frontend on cloudfront and the backend serving pure json through an api.", "group_id": 81, "id": 859621}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304095691.1345789, "message": "If the extra ajax requests prove to be a problem, I can piggyback some bootstrap data on the initial session handshaking ajax call. I prefer to leave it as it is for now however, no premature optimization :) My webapp is typically used for more than half an hour at a time, by recurring users, so initial load isn't that big of a problem.", "group_id": 81, "id": 859649}, {"user_id": 23244, "stars": [], "topic_id": 21997, "date_created": 1304095764.5493701, "message": "Also, with clearly separated backend and frontend, testing becomes easier and its also easier to make a new app (iOS? Android? Desktop?) or open up your api to others.", "group_id": 81, "id": 859662}]