Re: Combine page content (html) and model instance (json) in ajax response

2014-06-13 Thread Max Demars
I got the solution from Daniel Rossman on SO:

Firstly, use `render_to_string` to get the template fragment as an HTML 
string. Secondy, serialize your object as a Python dict, not JSON. Then you 
can convert the whole lot to JSON in one go.

html = render_to_string("page_content.html", {'form': form}, 
context_instance=RequestContext(request))
param = serializers.serialize('python', object)
data = json.dumps({'html': html, 'param': param})
return StreamingHttpResponse(data, content_type="application/json")

Now your JS can parse the JSON and access the `html` and `param` values.

On Thursday, June 12, 2014 2:30:58 PM UTC-4, Max Demars wrote:
>
> I would like my view to return the page content and some parameters that I 
> would like to use in the Ext.Ajax.request success function.
>
> views.py
>
> def importFile(request):
> form = ImportVectorForm()
> html_response = render_to_response("page_content.html", {'form': 
> form, 'folder':folder, 
> 'nodes':nodes},context_instance=RequestContext(request))
> if request.POST:
> form = ImportVectorForm(request.POST, request.FILES)
> if form.is_valid():
> ## here im dealing with the form...
> object = MyObject.objects.create()
> html_response = render_to_response("page_content.html", 
> {'form': form},context_instance=RequestContext(request))
> json_param = serializers.serialize('json', object)
> return StreamingHttpResponse(html_response, 
> content_type="plain/text")
>
> else:
> html_response = render_to_response("page_content.html", 
> {'form': form},context_instance=RequestContext(request))
>
> return StreamingHttpResponse(html_response, 
> content_type="plain/text")
>
>
> ajax.js:
>
>   importFileAjax = function(node_id){
> Ext.Ajax.request({
>   method: "GET",
>   form: "importForm",
>   url: "/basqui/file/import/" + node_id + "/",
>   success: function(r){
>   // here I would like to access the model instance 
> created properties
>   Ext.get('table').update(r.responseText); //this 
> update the page content
>}
> });
>   }
>
> I would like to pass both html_response and json_param to Ajax. The fist 
> to update a div and the second to access its properties.
>
> What is the right way of doing that?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ef5bd5f-4af6-4e7e-9275-28537dd5bd11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django OneToOne field problem

2014-06-12 Thread Max Demars
You will have to do content.link_set to retrieve the Link model related to 
the Content model instance.

See: 
https://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward

On Thursday, June 12, 2014 2:54:48 PM UTC-4, Satinderpal Singh wrote:
>
> Suppose there are two tables defined in Django models: 
>
> class Link(models.Model): 
> links = models.CharField(max_length=50 ,blank=True) 
>
> and 
>
> class Content(models.Model): 
> link = models.OneToOneField(Link, primary_key=True) 
> title = models.CharField(max_length=50, blank=True) 
> content = models.CharField(max_length=1000, blank=True) 
> footer = models.CharField(max_length=150, blank=True) 
>
> In the above table "Content" the OneToOne field contains the Link.id 
> attribute of the 
> table"Link", but how could i get it as, Link.links. 
>
> -- 
> Satinderpal Singh 
> http://satindergoraya91.blogspot.in/ 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9b52e144-ef71-4753-8e2e-8c57c9a20a6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Combine page content (html) and model instance (json) in ajax response

2014-06-12 Thread Max Demars
I would like my view to return the page content and some parameters that I 
would like to use in the Ext.Ajax.request success function.

views.py

def importFile(request):
form = ImportVectorForm()
html_response = render_to_response("page_content.html", {'form': 
form, 'folder':folder, 
'nodes':nodes},context_instance=RequestContext(request))
if request.POST:
form = ImportVectorForm(request.POST, request.FILES)
if form.is_valid():
## here im dealing with the form...
object = MyObject.objects.create()
html_response = render_to_response("page_content.html", 
{'form': form},context_instance=RequestContext(request))
json_param = serializers.serialize('json', object)
return StreamingHttpResponse(html_response, 
content_type="plain/text")

else:
html_response = render_to_response("page_content.html", 
{'form': form},context_instance=RequestContext(request))

return StreamingHttpResponse(html_response, 
content_type="plain/text")


ajax.js:

  importFileAjax = function(node_id){
Ext.Ajax.request({
  method: "GET",
  form: "importForm",
  url: "/basqui/file/import/" + node_id + "/",
  success: function(r){
  // here I would like to access the model instance 
created properties
  Ext.get('table').update(r.responseText); //this 
update the page content
   }
});
  }

I would like to pass both html_response and json_param to Ajax. The fist to 
update a div and the second to access its properties.

What is the right way of doing that?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/169c4a0d-b314-4891-b5f6-17ddc1fea4b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django-tables2 - Mix queryset and non-queryset data in table

2014-04-14 Thread Max Demars
Hi!

I would like to create a table via the Table.Meta.model with some columns 
that are non-queryset data. I manage to populate those columns manually in 
the view (see below), but it's impossible to sort the table with those 
columns: Cannot resolve keyword u'name' into field.

What is the proper way to mix queryset and non-queryset data in the same 
table?

models.py:

class WMS(models.Model):
alias = models.SlugField(max_length=50)
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
url = models.URLField()

forms.py:

class WMSListTable(tables.Table):
alias = tables.LinkColumn('editWMS', args=[A('pk')])
name = tables.Column()
type = tables.Column()
version = tables.Column()
valid = tables.BooleanColumn()

class Meta:
model = WMS
fields = ('alias', 'url', 'date_created', 'date_updated')

views.py:

from owslib.wms import WebMapService

def listWMS(request):
wms_list = WMS.objects.all()
for wms in wms_list:
try:
instance = WebMapService(wms.url)
wms.name = instance.identification.title
wms.type = instance.identification.type
wms.version = instance.identification.version
wms.valid = True
except:
wms.valid = False

wms_table = WMSListTable(wms_list)
RequestConfig(request).configure(wms_table)
return render(request,"basqui/manage_layer_wms_list.html", 
{'wms_list':wms_table},context_instance=RequestContext(request))


Thanks a lot!
-Max Demars


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f351d25c-67f3-4f8e-b837-cf033c428ee0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django throws ImproperlyConfigured error when loading URLconf on startup

2014-04-03 Thread Max Demars
Greetings,

I encounter the same error here. In latest gunicorn release, it's not 
possible anymore to deploy gunicorn/django the old way doing python 
manage.py run_gunicorn, so I'm stuck...I'd like to know if someone found 
what causes this error.

-Max Demars

On Wednesday, November 28, 2012 6:03:10 PM UTC-5, Michael Dippery wrote:
>
> I have a Django app running on a production server. It is handled with 
> gunicorn 0.14.2 behind nginx. When I reload the app (by reloading the 
> gunicorn workers), I get this error: 
>
> --- 
> Traceback (most recent call last): 
>
>  File 
> "/opt/app/venv/myapp/lib/python2.6/site-packages/django/core/handlers/base.py",
>  
> line 101, in get_response 
>request.path_info) 
>
>  File 
> "/opt/app/venv/myapp/lib/python2.6/site-packages/django/core/urlresolvers.py",
>  
> line 250, in resolve 
>for pattern in self.url_patterns: 
>
>  File 
> "/opt/app/venv/myapp/lib/python2.6/site-packages/django/core/urlresolvers.py",
>  
> line 283, in _get_url_patterns 
>raise ImproperlyConfigured("The included urlconf %s doesn't have any 
> patterns in it" % self.urlconf_name) 
>
> ImproperlyConfigured: The included urlconf myapp.urls doesn't have any 
> patterns in it 
> --- 
>
> Others with this problem have commonly noted that it occurs while using 
> reverse in a URLconf, but I am not using reverse in any URLconfs (nor are 
> they used in any third-party apps). Also, this error only occurs in 
> production -- never in development (using the Django dev server) or on my 
> staging server (also using gunicorn 0.14.2 behind nginx). It also doesn't 
> seem to cause trouble with the site at any other time then during reloads. 
> And it only happens for the first 10-20 requests on the website (which 
> makes me wonder if it's some sort of race condition, perhaps). 
>
> Any ideas what's causing the problem?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b9653b7b-c3bc-408a-9b38-e8cd10e6e4d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Beginning Geo Django: Rich Gis Web Applications With Python" Where can I get the book?

2014-03-19 Thread Max Demars
Hi Alex,

I cannot help you with this book in particular, but I could suggest another 
book that helped me a lot.

Python Geospatial Development by Erik Westra

-Max Demars

On Tuesday, March 18, 2014 11:49:49 AM UTC-4, Alex wrote:
>
> Thats an interesting dilemma. I just looked around a no one has copies. 
> The publisher says "The eBook version of this title will be available 
> soon" 
> http://www.springer.com/computer/book/978-1-4302-2532-4 
>
> But I have no idea how long it's said that. 
>
> This appears to be the ISBN for the printed version 9781430225317 
> Some searches show it on back order at every store. 
>
> So yes it seems limited quantities and no eBook version yet. Maybe 
> contact Apress and ask when the eBook will be available. 
>
> Thanks, 
> Alex 
>
> FYI: I'm forwarding this to the Geodjango mailing list, you might want 
> to join it and ask more there. geod...@googlegroups.com  
>
> On 03/16/2014 07:43 PM, ruomu sh wrote: 
> > Yes I understand. But I could not figure out how can I get it here at 
> > Nepal. I will buy it. I find different price listed on internet. Some 
> site 
> > say it is out of stock. Is it published only limited copies? 
> > 
> > On Friday, February 21, 2014 6:47:20 PM UTC+5:45, Tom Evans wrote: 
> >> 
> >> On Fri, Feb 21, 2014 at 10:15 AM, Ram Shrestha 
> >> > 
>
> >> wrote: 
> >>> Dear All, 
> >>> I am want to learn GeoDjango in real world application. I believe this 
> >> book 
> >>> "Beginning Geo Django: Rich Gis Web Applications With Python" is the 
> >> best 
> >>> book for me. But I could not download download it. 
> >>> 
> >>> If anyone have this book Please share the book with me. Where can I 
> get 
> >> it 
> >>> for free! 
> >> 
> >> If the author or publisher does not make this book available as a free 
> >> download, it is not appropriate to use this list to try to pirate it. 
> >> 
> >> Doing so discourages future authors and publishers from writing books 
> >> about Django. 
> >> 
> >> 
> >> Cheers 
> >> 
> >> Tom 
> >> 
> > 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa515ed2-9e2b-4b91-924e-dc34e374d8c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: hstore support in postgis backend

2013-04-15 Thread Max Demars
Hi Matt

Have you test this hstore branch? Does it combines well the postgis backend 
with hstore modified postgres backend? Have you found something better so 
far?

Thank you,

Max Demars

On Wednesday, November 28, 2012 7:08:25 PM UTC-5, Matthew Cooper wrote:
>
> Hi Reiner
>
> Thanks for pointing out the latest version of django-hstore.
>
> That pull request looks great, seems only to be a couple of files, 
> wondering if that can be right, will have a look.
>
> Many thanks
>
> Matt
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Dynamic Models for CSV Importing

2013-04-15 Thread Max Demars
Hello André,

I wonder if you successfuly found a way to achieve what you were talking in 
this post. Actually, I am looking for something similar. Instead of 
uploading .csv my app would allow users to upload shapefile. I am reading 
about dynamic models but the doc is scarce. If you can share a bit of what 
you have learnt that would be much appreciated.

Thank you,
Max Demars

On Monday, June 20, 2011 7:04:07 PM UTC-4, Andre Terra (airstrike) wrote:
>
> Thanks for the quick reply, Shawn!
>
> The reason I wanted to use Django was so that I could leverage the ORM to 
> allow users to do arbitrary SQL filtering/grouping before the data gets 
> saved onto the production DB.
>
> Assuming a 1.5 million lines CSV file (which is probably the smallest file 
> users would upload), can I trust pymongo/MongoDB to be reliably fast? More 
> importantly, using map/reduce and having to write custom built functions 
> for things like aggregation would force me to reinvent the wheel 
> considering what the Django ORM has to offer, would it not?
>
> Finally, I still need to know if I should save the column name-type 
> mappings as a JSONField + custom widget or as a FK to a 
> "ColumnFieldMapping" model in my "ImportTemplate" model.
>
> Thanks again for your insight
>
>
> Sincerely,
> André Terra (airstrike)
>
>
>
>
>
> On Mon, Jun 20, 2011 at 6:44 PM, Shawn Milochik 
> 
> > wrote:
>
>> I don't see where Django comes in -- at least not for the core of the 
>> app. Python certainly, with the xlwt and xlrd modules being incredibly 
>> helpful.
>>
>> Secondly, I'd use MongoDB (via pymongo) to store the temporary data, 
>> because I wouldn't bet a nickel that you'll get data in a consistent 
>> format, and xlrd (or a csv reader or DictReader) into a MongoDB document is 
>> ultra-convenient.
>>
>> If you get the guts working and want to use Django as a front-end for the 
>> users then you certainly can, but I don't believe that Django's ORM has a 
>> place in the solution.
>>
>> Shawn
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to django-users...@**
>> googlegroups.com .
>> For more options, visit this group at http://groups.google.com/**
>> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>> .
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Dynamic runtime modeling: which is the best choice?

2013-04-14 Thread Max Demars
Hi Alessandro,

How your searches are going so far? Have you found something interresting 
with Dynamic-Models such Django-Mutant? I am exactly looking for the same 
thing you mentioned in this post, a solution that will allow Django ORM to 
manipulate uploaded shapefiles. So far, I have found a generic way as 
Andres Reyes Monge was talking about but I would prefer a table per 
shapefile also.

I was thinking about giving a try to django-mutant, so I would like to know 
if it works for you. Other idea I have is to use ogrinspect to update a 
models.py on every upload/delete of a shapefile maybe combining with a 
queue like Celery. I am not sure neither about this avenue.

Please give me a little feedback about this topic!

Max Demars

On Tuesday, January 31, 2012 10:15:44 AM UTC-5, Alessandro Candini wrote:
>
> Hi list.
> I need to create an app in which the user can upload a shapefile, which 
> must be stored in a database table with LayerMapping from 
> django.contrib.gis.utils, as explained here:
>
> https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/#layermapping
>
> The problem is that I need to update dynamically my models.py with a new 
> model and add a table for every shape inserted by the user, without 
> using syncdb.
>
> Trying to document myself about this topic, I encountered a lot of 
> interesting extensions like south, django-eav and django-mutant for 
> example.
> (An interesting discussion here: 
>
> http://stackoverflow.com/questions/7933596/django-dynamic-model-fields/7934577#7934577
> )
>
> But I'm very confused about what could be the best solution for my needs.
>
> Has anybody experience with this kind of tools?
>
> Thanks in advance.
>
> Alessandro
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Persist toggle (show/hide) state when form is submitted using window.localStorage

2013-02-25 Thread Max Demars
 

Hello,

I have a form that use the collapse.js of django admin (outiste django 
admin). I would like to persist the show/hide fieldsets state when the form 
is submitted. According to this 
questionthis
 can be achieve with a window.localStorage. What could be an efficient 
way to use it inside django admin collapse.js ? How should I modify 
collapse.js to achieve this?

collapse.js

(function($) {
$(document).ready(function() {
// Add anchor tag for Show/Hide link
$("fieldset.collapse").each(function(i, elem) {
// Don't hide if fields in this fieldset have errors
if ($(elem).find("div.errors").length == 0) {
$(elem).addClass("collapsed").find("h2").first().append(' (' + gettext("Show") +
')');
}
});
// Add toggle to anchor tag
$("fieldset.collapse a.collapse-toggle").toggle(
function() { // Show

$(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset",
 [$(this).attr("id")]);
return false;
},

function() { // Hide

$(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset",
 [$(this).attr("id")]);
return false;
}
);
});})(django.jQuery);

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.