Re: response to ajax (jquery) with variables

2014-08-30 Thread Andreas Kuhne
Hi again Antonio,

First of all, make sure you are using a good browser with debugging
capabilities (I prefer Chrome), because you'll need it.

Secondly, I usually use the $.ajax request, instead of the post. Mainly
because post is a wrapper around ajax and you can more finely change the
settings of ajax.

So the post in your case would be:

$.ajax({
type: 'POST',   // Make sure you post
dataType: 'json',  // Use this so that you request json from
the server
url: "/sitioweb/json/",
data: data,
success: function(data) {
// The data that is returned is your json data, already parser, so
you don't have to parse it!
alert(data.array[0]); // Need to write "array" because that is
what you are sending to the browser (your structure looks like that, check
what the server is responding with)
},
error: function(xhr, textStatus, errorThrown) {
console.log('AJAX communication failed:', textStatus, errorThrown);
   // In case there is an error (for example a 500)
}
});

Regards,

Andréas

2014-08-30 4:57 GMT+02:00 Antonio Russoniello :

>  Now I can read data from  ajax to my def but I have not idea to how send,
> for examle, an array to jquery and manage this from javascript...
>
> I tried:
>
> def json_prueba(request):
> arrg = [1,2,3,4]
> if request.method == 'POST':
> return HttpResponse(simplejson.dumps({'array': arrg}),
> content_type="application/json")
> return HttpResponse('FAIL!')
>
> from the page side:
>
> function updateDB(){
> $.post("/sitioweb/json/", data, function(response){
> if(response){
> var data = JSON.parse(*response*); <- NOT SURE IF
> THIS IS CORRECT
> alert(data[0]); }  <- I´m trying to put on
> an alert windows the first item of my array arrg
> else{ alert('Error! :(');}
> });
> }
>
> Thanks in advande.
>
> AR
>
>
> El 28/08/2014 02:57 a.m., Andreas Kuhne escribió:
>
> Hi Antonio,
>
>  import simplejson as json
>
>  return HttpResponse(
>  json.dumps({
> 'array': example
> }),
>  content_type="application/json"
> )
>
>  That would do the trick. This is returned as JSON. Remember to set the
> content_type, otherwise the client can get confused.
>
>  Regards,
>
>  Andréas
>
> 2014-08-28 2:56 GMT+02:00 Antonio Russoniello  >:
>
>>  Hello,
>>
>> i hope you can help me with this, I'm trying to send to an ajax (jquery
>> from my html template) a response but i would like to send also a new
>> variable.
>>
>> in my html template I have:
>>
>> $("#init_date").click(function(){
>> var some_date = {'init_date': init_date, 'end_date': end_date};
>> $.post("/filter_dates/", some_date, function(response){
>> if(response === 'success'){
>> *MAKE SOMETHING**!!!*
>> else{ alert('error'); }
>> });
>> });
>>
>> my django view look like:
>>
>> def filter_date(request):
>> if request.method == 'POST':
>> example = ['A','B','C']
>> init_date = request.POST['init_date']
>> end_date = request.POST['end_date']
>>  MAKE SOMETHING!!
>> return HttpResponse('success') *AND HERE I WOULD LIKE TO SEND
>> THE example ARRAY...*
>> else:
>> return HttpResponse('error')
>>
>> How can I send the array o some other variable as response?
>>
>> Regards,
>> AR
>>  --
>> 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/53FE7E44.4020104%40musicparticles.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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/CALXYUbnxRG8cs7_4-ALJUubXRPhx%2B2FQE1NA7bkTiBqoB1ySLw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to the Google Gro

Re: Django framework plugin

2014-08-30 Thread Collin Anderson
All you need to do is make sure the directory containing "Djangowork" is on 
the python path, then just add "Djangowork" to the INSTALLED_APPS of a 
different project.

see here for more 
info: https://docs.djangoproject.com/en/dev/intro/reusable-apps/

-- 
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/1647bb22-a5d5-44e8-b26b-477716b48dc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to call django web page with ordinary html page

2014-08-30 Thread Collin Anderson
If it helps, you can read/set the csrf cookie using javascript. here's some 
rough code:

  if(!document.cookie.match('csrftoken=([a-zA-Z0-9]{32})')){
for(var c = ''; c.length < 32;) c += Math.random().toString(36).substr(2
, 1)
document.cookie = 'csrftoken=' + c + '; path=/'
  }
  document.write('')

-- 
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/e696027d-09ef-4b6a-8e59-dc7c441020e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.7 tutorial: Use generic views

2014-08-30 Thread Pitchblack


I need to use Jython instead of Python, I found that jython2.7b2 works with 
DJango 1.7. So, I am stuck using the beta version. I am trying to follow 
the current Django tutorial and I have ran into a problem. I am not sure if 
I am using generic views properly. When I try to change the urls.py (polls) 
file. I see that pydev complains that views.IndexView, views.DetailView, 
and ResultsView don't exist. Am I doing something wrong? Or did they change 
the way generics work in version 1.7?

My System:

   - Windows 7
   - jython2.7b2
   - Django-1.7c3
   - postgresql-9.3.5-1-windows-x64
   - postgresql-9.3-1102.jdbc41.jar

Here is the url for the tutorial, go to the section "Use generic views: 
Less code is better"
https://docs.djangoproject.com/en/dev/intro/tutorial04/






-- 
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/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to insert an inline in admin with the simple model without fk?

2014-08-30 Thread Gladson Simplício Brito

class Infos(Model):

created = DateTimeField(auto_now_add=True)modified = DateTimeField(
auto_now=True)

name = CharField(max_length=255, blank=False, null=False)
phone = CharField(max_length=255, blank=False, null=False)
address = CharField(max_length=255, blank=False, null=False)

And back in the admin list display the saved objects.
I appreciate the help!

-- 
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/84054c45-79c1-41fe-b963-8faba748e833%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to get a list of all installed applications

2014-08-30 Thread Cj Welborn


On Sunday, May 20, 2007 11:51:49 AM UTC-5, Malcolm Tredinnick wrote:
>
> Have a look in django/db/models/loading.py . There are a number of
> useful methods in there. In particular, get_apps(), which contrary to
> what you claim above, should give you all installed apps, not installed
> models (you use get_models(app_name) to get all the models for an app).
>
> Regards,
> Malcolm
>

Hello, this is a very old post but seeing how I got here from a Google 
search I figure someone else might also. Looking at get_apps() this is what 
I get:

from django.db.models import loading
for mod in loading.get_apps():
print(mod.__name__)


And the output:
django.contrib.auth.models
django.contrib.contenttypes.models
django.contrib.sessions.models
django.contrib.sites.models
django.contrib.messages.models
django.contrib.staticfiles.models
django.contrib.admin.models
django.contrib.admindocs.models
debug_toolbar.models
django_extensions.models
solo.models
wp_user_agents.models
home.models
projects.models
# <...plus all of my other app's models...>


So you see, *get_apps()* *does* return the *models*, not the *apps* 
themselves.

However, I did find this that works:
from django.conf import settings
from django.utils.module_loading import import_module
apps = []
for appname in settings.INSTALLED_APPS:
apps.append(import_module(appname))


Or to shorten it:
from django.conf import settings
from django.utils.module_loading import import_module
apps = [import_module(appname) for appname in settings.INSTALLED_APPS]


I needed it to design a search app for my site. If anyone has a better way 
I would really like to hear about it (no sarcasm).




-- 
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/ee48eaaa-a507-4d54-a6ef-d3fa57503234%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django admin can't display user detail view: 500 error

2014-08-30 Thread amarshall
Okay, I got everything working. I was totally over thinking things I think. 
I added the ADMINS variable in my settings to get a traceback and it seems 
a package(django-tastypie) I installed on my development side I forgot to 
install on the production side. Once I installed it, I migrated it's new 
tables using South and everything worked.

On Thursday, August 28, 2014 8:22:00 PM UTC-4, amarshall wrote:
>
> I've deployed my django application using Nginx and uWSGI. 
>
> In development I can login to my django admin-> users-> [username] and it 
> shows the users information. However in development once I click on a user 
> I get a "server 500" error. I have the same code for both deployment and 
> development. I can't think of what the problem could be ?
>

-- 
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/bb542db8-0dad-44fc-995d-3443afad9070%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 tutorial: Use generic views

2014-08-30 Thread Sithembewena Lloyd Dube
I suggest typing:
- manage.py shell
- from polls import views
- dir(views)

What output do you get? i.e, nspect views like the regular python module
that it is.


On Sat, Aug 30, 2014 at 6:41 PM, Pitchblack  wrote:

> I need to use Jython instead of Python, I found that jython2.7b2 works
> with DJango 1.7. So, I am stuck using the beta version. I am trying to
> follow the current Django tutorial and I have ran into a problem. I am not
> sure if I am using generic views properly. When I try to change the urls.py
> (polls) file. I see that pydev complains that views.IndexView,
> views.DetailView, and ResultsView don't exist. Am I doing something wrong?
> Or did they change the way generics work in version 1.7?
>
> My System:
>
>- Windows 7
>- jython2.7b2
>- Django-1.7c3
>- postgresql-9.3.5-1-windows-x64
>- postgresql-9.3-1102.jdbc41.jar
>
> Here is the url for the tutorial, go to the section "Use generic views:
> Less code is better"
> https://docs.djangoproject.com/en/dev/intro/tutorial04/
>
>
> 
>
>
> 
>
> --
> 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/5be54cfd-ed53-40ca-b7e1-297814c1727d%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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/CAH-SnCBTSo-C_99JOZuu4fZd3Uyc_UyOU5JEW%2BPYDqdJMYhYag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to get a list of all installed applications

2014-08-30 Thread Collin Anderson
The soon-to-be-released version 1.7 has a documented API for accessing all 
models and apps:

https://docs.djangoproject.com/en/1.7/ref/applications/

-- 
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/091a7d80-c155-4f7b-8df4-0eaa7ea6790c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Change "Add another" text in inline views

2014-08-30 Thread stuartl
Hi all,

This is a bit of a silly question, but I wonder if it is possible to change 
the "Add Another" text that appears on inline forms with related models.  
I'm in the process of writing a network configuration module in Django that 
talks with NetworkManager with the intent on using it for headless 
appliances for energy management and possibly SCADA applications.

I have a number of polymorphic models (thank-you django-polymorphic!) that 
describe the various types of network connection, and attached to these, 
are some "settings" objects that describe different aspects of the 
connection.  Some of these are one-to-many relationships (e.g. IP 
addresses, routes, DNS servers), but some are one-to-one relationships 
(IPv4/IPv6 options: which specify things like DHCP vs static, 802.1x 
settings, bridge port configuration, etc).

The form at present looks like this: 
http://www.longlandclan.yi.org/~stuartl/images_tmp/django-inlines-add-another.png

Also of note is the capitalisation of some objects, e.g. "Ipv4" instead of 
"IPv4", but I guess I just missed a Meta variable somewhere.  I think I 
have seen something that sets this.

For the related objects that are one-to-one, I've defined my admin models 
like so:

class IPv4SettingAdmin(admin.StackedInline):
model = models.NetIPv4Setting
extra = 0
min_num = 0
max_num = 1

i.e. the related object is optional, not provided by default, and at most 
there can only be one.  You'll note that despite max_num being set to 1, it 
still says "Add another".  Is it possible to delete the word "another" from 
that text to make it more sensible?  (Better yet, can it drop the word 
"another" when the count currently sits at 0 since "another" implies an 
object of that type already exists?)

Apologies if this has been asked: I've only seen replies to the question of 
how to remove the "add another" option completely, which isn't what I want 
to do.

Regards,
Stuart Longland

-- 
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/9489756e-4813-43cf-8aa8-6cbfedbd87af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Change "Add another" text in inline views

2014-08-30 Thread Mike Dewhirst

On 31/08/2014 10:05 AM, stua...@longlandclan.yi.org wrote:

Hi all,

This is a bit of a silly question, but I wonder if it is possible to
change the "Add Another" text that appears on inline forms with related
models.  I'm in the process of writing a network configuration module in
Django that talks with NetworkManager with the intent on using it for
headless appliances for energy management and possibly SCADA applications.

I have a number of polymorphic models (thank-you django-polymorphic!)
that describe the various types of network connection, and attached to
these, are some "settings" objects that describe different aspects of
the connection.  Some of these are one-to-many relationships (e.g. IP
addresses, routes, DNS servers), but some are one-to-one relationships
(IPv4/IPv6 options: which specify things like DHCP vs static, 802.1x
settings, bridge port configuration, etc).

The form at present looks like this:
http://www.longlandclan.yi.org/~stuartl/images_tmp/django-inlines-add-another.png

Also of note is the capitalisation of some objects, e.g. "Ipv4" instead
of "IPv4", but I guess I just missed a Meta variable somewhere.  I think
I have seen something that sets this.

For the related objects that are one-to-one, I've defined my admin
models like so:

|
classIPv4SettingAdmin(admin.StackedInline):
 model =models.NetIPv4Setting
 extra =0
 min_num =0
 max_num =1
|

i.e. the related object is optional, not provided by default, and at
most there can only be one.  You'll note that despite max_num being set
to 1, it still says "Add//another".  Is it possible to delete the word
"another" from that text to make it more sensible?  (Better yet, can it
drop the word "another" when the count currently sits at 0 since
"another" implies an object of that type already exists?)


I'm somewhat interested in your success with this because I enjoy it 
when the user interface helps the user understand the software. But I 
think you might have to dig a little deeper for a nice solution.


I found where the Admin has "add another" ...

Searching for: add another
options.py(945): msg = _('The %(name)s "%(obj)s" was added successfully. 
You may add another %(name)s below.') % msg_dict
options.py(983): msg = _('The %(name)s "%(obj)s" was changed 
successfully. You may add another %(name)s below.') % msg_dict

widgets.py(262): % (static('admin/img/icon_addlink.gif'), _('Add Another')))
Found 3 occurrence(s) in 2 file(s)

... which all looks interesting but maybe too big a job for the 
anticipated benefit.


Good luck

Mike




Apologies if this has been asked: I've only seen replies to the question
of how to remove the "add another" option completely, which isn't what I
want to do.

Regards,
Stuart Longland

--
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/9489756e-4813-43cf-8aa8-6cbfedbd87af%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
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/5402B69F.6070505%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Change "Add another" text in inline views

2014-08-30 Thread Stuart Longland
Hi Mike,
On 31/08/14 15:46, Mike Dewhirst wrote:
>> i.e. the related object is optional, not provided by default, and at
>> most there can only be one.  You'll note that despite max_num being set
>> to 1, it still says "Add//another".  Is it possible to delete the word
>> "another" from that text to make it more sensible?  (Better yet, can it
>> drop the word "another" when the count currently sits at 0 since
>> "another" implies an object of that type already exists?)
> 
> I'm somewhat interested in your success with this because I enjoy it
> when the user interface helps the user understand the software. But I
> think you might have to dig a little deeper for a nice solution.
> 
> I found where the Admin has "add another" ...
> 
> Searching for: add another
> options.py(945): msg = _('The %(name)s "%(obj)s" was added successfully.
> You may add another %(name)s below.') % msg_dict
> options.py(983): msg = _('The %(name)s "%(obj)s" was changed
> successfully. You may add another %(name)s below.') % msg_dict
> widgets.py(262): % (static('admin/img/icon_addlink.gif'), _('Add
> Another')))
> Found 3 occurrence(s) in 2 file(s)
> 
> ... which all looks interesting but maybe too big a job for the
> anticipated benefit.

I'll admit I didn't think to just do a grep of the file structure.  When
I do it I get:

> /usr/lib/python2.7/dist-packages/django/contrib/admin/locale/en/LC_MESSAGES/django.po:msgid
>  "Add another %(verbose_name)s"
> /usr/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/edit_inline/tabular.html:
> addText: "{% blocktrans with 
> inline_admin_formset.opts.verbose_name|capfirst as verbose_name %}Add another 
> {{ verbose_name }}{% endblocktrans %}",
> /usr/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/edit_inline/stacked.html:
> addText: "{% blocktrans with 
> verbose_name=inline_admin_formset.opts.verbose_name|capfirst %}Add another {{ 
> verbose_name }}{% endblocktrans %}"

The latter two being the HTML templates used for the stacked and tabular
inline widgets.  I guess that's a starting point then. :-)

Regards,
-- 
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
  ...it's backed up on a tape somewhere.

-- 
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/5402B8C9.5020606%40longlandclan.yi.org.
For more options, visit https://groups.google.com/d/optout.