Re: How to model postal address in django ???

2012-04-01 Thread Mario Gudelj
You can use django-countries for county names and codes -
http://code.google.com/p/django-countries/ or
https://bitbucket.org/smileychris/django-countries

There are probably more apps out there.

For geo-coding you can try http://geodjango.org/. It's awesome but it may
be a bit hard to implement. If you find it a bit hard you can always use
Google http://djangosnippets.org/snippets/2241/. Note that you only get
2 free lat long lookups a day with google.

Cheers,

-m




On 31 March 2012 03:54, Ariel Isaac Romero Cartaya wrote:

> Hi everybody, is there any model in Django to represent postal
> address, I mean is there already models like Countries, provinces and
> cities with theirs relations to make this, and how to model the others
> attributes: streets, postal code, between streets and perhaps latitude
> and longitude  to use google maps 
>
> How hope you can help me.
> Any help would be appreciated.
>
> Regards,
> Ariel
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> 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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: getting POST 500 (OK), when using $.ajax on that url

2012-04-01 Thread Daniel Roseman
On Saturday, 31 March 2012 23:23:26 UTC+1, Ahmad wrote:
>
> I trying to use jquery ajax to send json data to django
>
> sorry if providing javascript code but it may help solving my problem
> 
> $("#send").click(function() {
> events = $('#calendar').fullCalendar('clientEvents');
>console.log(events);
>var filter = new Array();
>filter[0] = 'start';
>filter[1] = 'end';
>filter[2] = 'title';
>events = JSON.stringify(events, filter, '\t');
>console.log(events);
>$.ajax({
>type: "POST",
>data: "events",
>url: ,
>});
> });
> _
>
> on chrome devtool every thing is ok until the last $.ajax()
>
> it throw this error
>
>
>1. POST   500 (OK)
>   1. 
> f.support.ajax.f.ajaxTransport.sendjquery-1.7.1.min.js:4
>   2. 
> f.extend.ajaxjquery-1.7.1.min.js:4
>   3. (anonymous function) 
>   4. 
> f.event.dispatchjquery-1.7.1.min.js:3
>   5. f.event.add.h.handle.i
>   
>
>
> so why am I getting 500 error, event I tried to use csrf_exempt or 
> disabling the csrf entirely but nothing changed
>
> If any one can figure out what I'm doing wrong please go ahead 
>
> thanks in advance
>
> Ahmad
>
>1. 
>
>

If that's your real code, you seem to be sending the string "events" as the 
POST data. Presumably you meant to send the contents of the variable events 
instead.
--
DR. 

>
>1.  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/IyNt8bVGtN4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Filtering results before & after update?

2012-04-01 Thread akaariai


On Apr 1, 4:24 am, symmitchry  wrote:
> I have a straightforward form that simply reduces an item count by 1, for a
> selected product. (The form essentially "ships" a product, so need to
> decrease remaining term_length by 1).
>
> I have the following code:
>
>             cd = form.cleaned_data
>
>             q = Subscription.objects.filter(product_key__exact =
> cd['product'])
>             q = q.filter(status__iexact='Active')
>             q = q.filter(term_length__gt=0)
>
>             # Decrement our terms remaining by 1.
>             rec_count = q.update(term_length=F('term_length') - 1)
>
>             return render_to_response('subs/shipped.html',{ 'q':
> q, 'rec_count': rec_count })
>
> What happens is that the results I want to display on the "shipped" page
> are still being filtered according to the criteria I used to select the
> rows for updating. Since I have a >= 0 filter, I do not see those rows that
> were reduced from 1 to 0. I can't use {{ q|length }} to get number of
> records updated, for example.
>
> How would I go about returning, for example, a list of the freshly updated
> records from BEFORE they were updated. I can't search after the fact, since
> status and term_length would be Inactive and 0 for a huge number of
> records; there will be nothing distinct about the ones that were last
> changed.
>
> Thanks for the help.
>
> M.

It seems your best bet is to do something like this:

to_be_updated = list(q.select_for_update())
q.filter(pk__in=to_be_updated).update(...)

The above is written in a way trying to guarantee that the
to_be_updated set is exactly the same as the actual set you are going
to update. However, you need to fetch the objects from the database
which can be costly. If you don't want to do that, you could fetch
just the PK list or add another column to the update discriminating
the set (modified_by=someid). It could be useful if you could directly
get the updated PK list from .update(), but that is not supported by
the ORM.

 - Anssi

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



Setup A Django VM with Vagrant, VirtualBox, and Chef

2012-04-01 Thread michaeljsmalley
I just wanted to let everyone here know that I've written an article
about getting a Django development environment configured with
Vagrant, Chef, and VirtualBox.  It's been pretty popular among
friends, and I thought it's time to share. I genuinely hope some of
you find it useful.

http://blog.smalleycreative.com/tutorials/setup-a-django-vm-with-vagrant-virtualbox-and-chef/

Thank you!
Michael

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



sorting a list of objects when objects is returning two fields

2012-04-01 Thread Nikhil Verma
Hi All

I have a model structure like this :-

class Visit(Model):
patient = models.ForeignKey(Patient)
... and so on 
topics  = models.ManyToManyField(Topic,
limit_choices_to={'reporting':False})
research_protocol   =
models.ManyToManyField(ResearchProtocol,blank=True)
history_log = JSONField(blank=True)


...and so on .
class Meta:
ordering = ("-date_created",)

def __unicode__(self):
result = """Visit id:%s pt:%s""" % (self.id, self.patient.id)
return result

  So the objects looks like this  


Now at some table i am making a query that returns me list of objects like
this :-

research_obj = ResearchProtocol.objects.get(id=id)
# You can see research_protocol is ManyToManyField in the above model.
visit_ids = research_obj.visit_set.all()

[ , , , ]

Now i want to sort this list of objects in such a manner that i get this
new sorted list :-

*[ , , ,, ]*

You can see the pt is also getting sorted and Visit Id is also getting
sorted .

I am using this :-

ordered_total_visit_ids = sorted(total_visit_ids, key=lambda x: x.patient,
reverse=False)

Thanks for help in advance.


-- 
Regards
Nikhil Verma
+91-958-273-3156

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



plugins django-apps in sidebar with eval()

2012-04-01 Thread kase
i want made a plugin sistem  for one CMS  my idea is:

#plugin
def plugin ():
do somting
return render_to_string('plugin.html',{})

and  one database whit plugins  method name  "Plugin_sidebar"

#view
def home(request):
ps = Plugin_sidebar.objects.all()
return render_to_response('home.html',{'ps':ps})


and  template whit custom tag  eval()

{%for  item in  ps %}
{%eval  item%}   #custom tag
{%endfor%}


with this sistem the user can add and remove plugins... what do you think?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/LhdpKj6M3tUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Preprocess data before showing it on Admin

2012-04-01 Thread Pedro Vasconcelos
Hello!

Anyone knows how preprocess data before showing it on Admin (change page)?

 __  __  ___
/  \/  \/   \
|  DB  | -> | PREPROCESSOR | -> | ADMIN |
\__/\__/\___/


I want to edit data (in Admin) in a human-friendly-format (my custom
format) and store it in XML. So, when a user comes to edit data on Admin,
it cant be the raw data from DB. It need to be converted (preprocessed)
before and then showed.

Anyone can help me? Thanks!

-- 
Pedro Vasconcelos
85 8767.1843
ptronico (skype)

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



Re: Preprocess data before showing it on Admin

2012-04-01 Thread Marc Aymerich
On Sun, Apr 1, 2012 at 9:25 PM, Pedro Vasconcelos  wrote:
> Hello!
>
> Anyone knows how preprocess data before showing it on Admin (change page)?
>
>  __      __      ___
> /      \    /              \    /       \
> |  DB  | -> | PREPROCESSOR | -> | ADMIN |
> \__/    \__/    \___/
>
>
> I want to edit data (in Admin) in a human-friendly-format (my custom format)
> and store it in XML. So, when a user comes to edit data on Admin, it cant be
> the raw data from DB. It need to be converted (preprocessed) before and then
> showed.
>
> Anyone can help me? Thanks!

HI pedro,
you can do it creating a custom modelform
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form
-- 
Marc

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



Re: Preprocess data before showing it on Admin

2012-04-01 Thread Pedro Vasconcelos
Hello Marc!

Thanks for replying. Unfortunately I cant realised how to get the current
value, change it and populate the form using a ModelForm. I've tried it
actually.

I appreciate if you send me tips on that direction!

Thanks a lot!

On Sun, Apr 1, 2012 at 4:36 PM, Marc Aymerich  wrote:

> On Sun, Apr 1, 2012 at 9:25 PM, Pedro Vasconcelos 
> wrote:
> > Hello!
> >
> > Anyone knows how preprocess data before showing it on Admin (change
> page)?
> >
> >  __  __  ___
> > /  \/  \/   \
> > |  DB  | -> | PREPROCESSOR | -> | ADMIN |
> > \__/\__/\___/
> >
> >
> > I want to edit data (in Admin) in a human-friendly-format (my custom
> format)
> > and store it in XML. So, when a user comes to edit data on Admin, it
> cant be
> > the raw data from DB. It need to be converted (preprocessed) before and
> then
> > showed.
> >
> > Anyone can help me? Thanks!
>
> HI pedro,
> you can do it creating a custom modelform
>
> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form
> --
> Marc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Pedro Vasconcelos
85 8767.1843
ptronico (skype)

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



Looking for Django IDE

2012-04-01 Thread Mark Phillips
What IDE do you use/recommend for developing django web sites? Or, if not
an IDE, what editor/setup is most useful? I am developing on Linux version
3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I
use eclipse for developing android/java projects. Since I am using django
in conjunction with an android project, I don't want to use the plugin for
eclipse. Switching between python and java perspectives is a little
annoying, so I thought I would find a separate ide for my django work and
just alt-tab between them.

I have tried gedit, but I cannot get the django plugin to work. I am
looking at ninja, but there does not appear to be a django plugin.

Thanks,

Mark

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



Re: Preprocess data before showing it on Admin

2012-04-01 Thread Marc Aymerich
On Sun, Apr 1, 2012 at 9:42 PM, Pedro Vasconcelos  wrote:
> Hello Marc!
>
> Thanks for replying. Unfortunately I cant realised how to get the current
> value, change it and populate the form using a ModelForm. I've tried it
> actually.
>
sure, you can do it on form __init__ method

something like

class YourForm(ModelForm):
def __init__(self, *args, **kwargs):
super(YourForm, self).__init__(*args, **kwargs)
self.fields['your_field'].initial = your_postprocess_method()

also you should override the save form method in order to "reverse"
the postprocess and save the data in raw format.


-- 
Marc

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



Re: Looking for Django IDE

2012-04-01 Thread Alexandros Karypidis

Hi,

I'm using PyDev in Eclipse and it seems quite nice: http://pydev.org/

Have a look at the Django-specific stuff: 
http://pydev.org/manual_adv_django.html


Please note that you must use a nightly build for Django 1.4 due to this:
http://sourceforge.net/projects/pydev/forums/forum/293649/topic/5158643

Cheers,
Alex

On 1/4/2012 7:30 μμ, Mark Phillips wrote:
What IDE do you use/recommend for developing django web sites? Or, if 
not an IDE, what editor/setup is most useful? I am developing on Linux 
version 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something 
open source. I use eclipse for developing android/java projects. Since 
I am using django in conjunction with an android project, I don't want 
to use the plugin for eclipse. Switching between python and java 
perspectives is a little annoying, so I thought I would find a 
separate ide for my django work and just alt-tab between them.


I have tried gedit, but I cannot get the django plugin to work. I am 
looking at ninja, but there does not appear to be a django plugin.


Thanks,

Mark
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Looking for Django IDE

2012-04-01 Thread Alexandros Karypidis

Oh, regarding your problem of the 'annoying switching of perspectives':

1) Start eclipse
2) Open your java project, switch to the Java perspective
3) From the menu: Window->New Window
4) In the new window, open your django project and switch to the PyDev 
perspective
5) Alt-tab between the two Eclipse windows (one will be in PyDev and the 
other in Java perspective)


You can also create two different Eclipse work-spaces and run two 
instances of eclipse (if you have ample RAM on your system).


On 1/4/2012 8:56 μμ, Alexandros Karypidis wrote:

Hi,

I'm using PyDev in Eclipse and it seems quite nice: http://pydev.org/

Have a look at the Django-specific stuff: 
http://pydev.org/manual_adv_django.html


Please note that you must use a nightly build for Django 1.4 due to this:
http://sourceforge.net/projects/pydev/forums/forum/293649/topic/5158643

Cheers,
Alex

On 1/4/2012 7:30 μμ, Mark Phillips wrote:
What IDE do you use/recommend for developing django web sites? Or, if 
not an IDE, what editor/setup is most useful? I am developing on 
Linux version 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use 
something open source. I use eclipse for developing android/java 
projects. Since I am using django in conjunction with an android 
project, I don't want to use the plugin for eclipse. Switching 
between python and java perspectives is a little annoying, so I 
thought I would find a separate ide for my django work and just 
alt-tab between them.


I have tried gedit, but I cannot get the django plugin to work. I am 
looking at ninja, but there does not appear to be a django plugin.


Thanks,

Mark
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Looking for Django IDE

2012-04-01 Thread Masklinn
On 2012-04-01, at 20:30 , Mark Phillips wrote:

> What IDE do you use/recommend for developing django web sites? Or, if not
> an IDE, what editor/setup is most useful? I am developing on Linux version
> 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I
> use eclipse for developing android/java projects. Since I am using django
> in conjunction with an android project, I don't want to use the plugin for
> eclipse. Switching between python and java perspectives is a little
> annoying, so I thought I would find a separate ide for my django work and
> just alt-tab between them.
> 
> I have tried gedit, but I cannot get the django plugin to work. I am
> looking at ninja, but there does not appear to be a django plugin.

There's Jetbrains's PyCharm, which has a lot of built-in dedicated
Django support (e.g. inspections and quick fixes, visual debugging of
templates) and more generally excellent Python support (language &
ecosystem, supports virtualenvs and cython for instance).

And it has the usual excellent support for webby stuff (HTML, CSS, JS)

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



Re: Looking for Django IDE

2012-04-01 Thread Alexandr Aibulatov
Try to use vim with plugins for django.
02.04.2012 1:48 пользователь "Mark Phillips" 
написал:

> What IDE do you use/recommend for developing django web sites? Or, if not
> an IDE, what editor/setup is most useful? I am developing on Linux version
> 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I
> use eclipse for developing android/java projects. Since I am using django
> in conjunction with an android project, I don't want to use the plugin for
> eclipse. Switching between python and java perspectives is a little
> annoying, so I thought I would find a separate ide for my django work and
> just alt-tab between them.
>
> I have tried gedit, but I cannot get the django plugin to work. I am
> looking at ninja, but there does not appear to be a django plugin.
>
> Thanks,
>
> Mark
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> 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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Looking for Django IDE

2012-04-01 Thread yati sagade
Aptana Studio 3  is basically Eclipse beefed up with
PyDev and other useful plugins, targeted towards web devel. I use it
regularly, and besides the cool colour schemes, the thing is pretty stable
(I was really tired of scouring the web just to get my Eclipse builds
running properly).
If you can shell out some money,.PyCharm
is an *excellent* IDE, with true
virtualenv support and all. It costs a
little, but it is worth it.

2012/4/2 Alexandros Karypidis 

> Oh, regarding your problem of the 'annoying switching of perspectives':
>
> 1) Start eclipse
> 2) Open your java project, switch to the Java perspective
> 3) From the menu: Window->New Window
> 4) In the new window, open your django project and switch to the PyDev
> perspective
> 5) Alt-tab between the two Eclipse windows (one will be in PyDev and the
> other in Java perspective)
>
> You can also create two different Eclipse work-spaces and run two
> instances of eclipse (if you have ample RAM on your system).
>
>
> On 1/4/2012 8:56 μμ, Alexandros Karypidis wrote:
>
>> Hi,
>>
>> I'm using PyDev in Eclipse and it seems quite nice: http://pydev.org/
>>
>> Have a look at the Django-specific stuff: http://pydev.org/manual_adv_**
>> django.html 
>>
>> Please note that you must use a nightly build for Django 1.4 due to this:
>> http://sourceforge.net/**projects/pydev/forums/forum/**
>> 293649/topic/5158643
>>
>> Cheers,
>> Alex
>>
>> On 1/4/2012 7:30 μμ, Mark Phillips wrote:
>>
>>> What IDE do you use/recommend for developing django web sites? Or, if
>>> not an IDE, what editor/setup is most useful? I am developing on Linux
>>> version 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open
>>> source. I use eclipse for developing android/java projects. Since I am
>>> using django in conjunction with an android project, I don't want to use
>>> the plugin for eclipse. Switching between python and java perspectives is a
>>> little annoying, so I thought I would find a separate ide for my django
>>> work and just alt-tab between them.
>>>
>>> I have tried gedit, but I cannot get the django plugin to work. I am
>>> looking at ninja, but there does not appear to be a django plugin.
>>>
>>> Thanks,
>>>
>>> Mark
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users+unsubscribe@*
>>> *googlegroups.com .
>>> For more options, visit this group at 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 post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>


-- 
Yati Sagade 

Twitter: @yati_itay 

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869

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



URL encoding, templates and apps: are apps not portlets?

2012-04-01 Thread Alexandros Karypidis

Hi,

My fondness of Python (while scripting things for work) grew to the 
point where I decided to try web development with it. Having 
(apparently) nothing better to do on a Sunday afternoon, I went through 
the Django tutorials.


The tutorial goes to some length to keep the "polls" app self-contained 
and easily embeddable into the mysite project. However, it seems to do 
so only for the back-end logic and not so much for the front-end UI.


In part 3 
(https://docs.djangoproject.com/en/1.4/intro/tutorial03/#decoupling-the-urlconfs) 
it rewrites the URLConfs to "mount" the app under some site-specific 
prefix (/polls).


urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),

I quote from the tutorial:

"The idea behind include() 
 
and URLconf decoupling is to make it easy to plug-and-play URLs. Now 
that polls are in their own URLconf, they can be placed under "/polls/", 
or under "/fun_polls/", or under "/content/polls/", or any other path 
root, and the app will still work."


Ironically, it does not seem to be bothered with the HTML side of 
things. Therefore:


1) index.html produces a hard-coded list of polls, which MUST be mounted 
at "/polls", with:

{% for poll in latest_poll_list %}
{{ poll.question }}
{% endfor %}
2) detail.html routes the voting action to "/polls" POST

3) results.html takes you back to voting in "/polls"
Vote again?

As I suspected, changing "mysite.urls" to this:

urlpatterns = patterns('',
url(r'^fun_polls/', include('polls.urls')),

... broke everything which was carefully crafted on the application-code 
side of things.


I am currently tinkering to define a "app_prefix" variable in the code 
and trying to have the templates read it from the context, so that 
things become more modular...


I thought apps in Django were supposed to be like "Wicket components" or 
"Java portlets" (i.e. carry their UI along). Am I letting my Java 
background take me to the wrong direction here? Obviously, if someone 
were to use the polls code mounted under "/fun_polls" they could create 
their own version of "index/details/results.html" that use "/fun_polls" 
for their prefix (and even display things differently)...


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



Re: Preprocess data before showing it on Admin

2012-04-01 Thread Pedro Vasconcelos
Thanks for your time and your tips Marc!

I had tried earlie what you suggested but it didnt solved my problem
because it only assigns initial values to new records and not to existents
ones.

But i finally figured out a small change on code which does it well. I just
replaced "self.fields['your_field'].initial" with "self.initial['text']".

Thanks again! Regards,

On Sun, Apr 1, 2012 at 4:55 PM, Marc Aymerich  wrote:

> On Sun, Apr 1, 2012 at 9:42 PM, Pedro Vasconcelos 
> wrote:
> > Hello Marc!
> >
> > Thanks for replying. Unfortunately I cant realised how to get the current
> > value, change it and populate the form using a ModelForm. I've tried it
> > actually.
> >
> sure, you can do it on form __init__ method
>
> something like
>
> class YourForm(ModelForm):
>def __init__(self, *args, **kwargs):
>super(YourForm, self).__init__(*args, **kwargs)
>self.fields['your_field'].initial = your_postprocess_method()
>
> also you should override the save form method in order to "reverse"
> the postprocess and save the data in raw format.
>
>
> --
> Marc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Pedro Vasconcelos
85 8767.1843
ptronico (skype)

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



Re: URL encoding, templates and apps: are apps not portlets?

2012-04-01 Thread Alexandros Karypidis
So, having discovered how to extend the context of a generic view, I've 
now managed to make things a bit more self-contained:


1) In polls.urls add a name for the index page (just like for the 
'poll_results' case)

--
urlpatterns = patterns('',
# ...
name='poll_index'),
2) In polls.init create a module-wide utility-function to reverse the 
index url:

--
from django.core.urlresolvers import reverse
def get_polls_prefix():
return reverse('poll_index').strip('/')

3) Subclass ListView/DetailsView to add a "prefix" value to the template 
context. For example (PollDetailsView is similar):

--
class PollListView(ListView):
def get_context_data(self, **kwargs):
context = super(PollListView, self).get_context_data(**kwargs)
context['prefix'] = polls.get_polls_prefix()
return context

urlpatterns = patterns('',
url(r'^$',
PollListView.as_view(
queryset=Poll.objects.order_by('-pub_date')[:5],
context_object_name='latest_poll_list',
template_name='polls/index.html'),
name='poll_index'),

4) Now, all my web pages use the prefix from the context; e.g. 
index.html looks like this:

--

{% for poll in latest_poll_list %}
{{ poll.question }}
{% endfor %}


On 1/4/2012 9:20 ??, Alexandros Karypidis wrote:

Hi,

My fondness of Python (while scripting things for work) grew to the 
point where I decided to try web development with it. Having 
(apparently) nothing better to do on a Sunday afternoon, I went 
through the Django tutorials.


The tutorial goes to some length to keep the "polls" app 
self-contained and easily embeddable into the mysite project. However, 
it seems to do so only for the back-end logic and not so much for the 
front-end UI.


In part 3 
(https://docs.djangoproject.com/en/1.4/intro/tutorial03/#decoupling-the-urlconfs) 
it rewrites the URLConfs to "mount" the app under some site-specific 
prefix (/polls).


urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),

I quote from the tutorial:

"The idea behind include() 
 
and URLconf decoupling is to make it easy to plug-and-play URLs. Now 
that polls are in their own URLconf, they can be placed under 
"/polls/", or under "/fun_polls/", or under "/content/polls/", or any 
other path root, and the app will still work."


Ironically, it does not seem to be bothered with the HTML side of 
things. Therefore:


1) index.html produces a hard-coded list of polls, which MUST be 
mounted at "/polls", with:

{% for poll in latest_poll_list %}
{{ poll.question }}
{% endfor %}
2) detail.html routes the voting action to "/polls" POST

3) results.html takes you back to voting in "/polls"
Vote again?

As I suspected, changing "mysite.urls" to this:

urlpatterns = patterns('',
url(r'^fun_polls/', include('polls.urls')),

... broke everything which was carefully crafted on the 
application-code side of things.


I am currently tinkering to define a "app_prefix" variable in the code 
and trying to have the templates read it from the context, so that 
things become more modular...


I thought apps in Django were supposed to be like "Wicket components" 
or "Java portlets" (i.e. carry their UI along). Am I letting my Java 
background take me to the wrong direction here? Obviously, if someone 
were to use the polls code mounted under "/fun_polls" they could 
create their own version of "index/details/results.html" that use 
"/fun_polls" for their prefix (and even display things differently)...


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Questions about UnicodeDecodeError

2012-04-01 Thread Bill Freeman
If you can, switch to UTF-8 in the db.  Web traffic can arrive in a variety of
encodings, and while the headers tell the server how to make unicode out
of it, but by having the db set for ASCII, you limit what you can store (since
not all unicode characters can be converted to ASCII.

On Fri, Mar 30, 2012 at 7:45 PM, Ali Mesdaq  wrote:
> I have a situation where I am reading data that I have no control over and
> inserting it into a db. The data is http headers. I am storing them in
> postgres db in a text field and the db encoding is SQL_ASCII. Since the
> data can be anything even non compliant http headers with anything for its
> values I don't want to modify the data before I store it in the db.
> However this is causing issues with certain values causing the
> UnicodeDecodeError. For example I have a specific case where the user
> agent is set to 'KC\xd4\xda\xcf\xdf\xc9\xfd\xbc\xb6'. I have been trying
> to look for a way to deal with these cases gracefully in the models
> __unicode__ method but nothing I have tried has worked.
>
> Thanks,
> Ali Mesdaq
> Security Researcher
> Cell:  +1 (619) 952-8488  |  Fax:  +1 (408) 321-9818
> Email:  ali.mes...@fireeye.com
>
>
> Next Generation Threat Protection
> http://www.FireEye.com 
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> 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 post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Looking for Django IDE

2012-04-01 Thread kase
komodo edit   http://www.activestate.com/komodo-edit   

El domingo 1 de abril de 2012 13:30:03 UTC-5, mark escribió:
>
> What IDE do you use/recommend for developing django web sites? Or, if not 
> an IDE, what editor/setup is most useful? I am developing on Linux version 
> 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I 
> use eclipse for developing android/java projects. Since I am using django 
> in conjunction with an android project, I don't want to use the plugin for 
> eclipse. Switching between python and java perspectives is a little 
> annoying, so I thought I would find a separate ide for my django work and 
> just alt-tab between them.
>
> I have tried gedit, but I cannot get the django plugin to work. I am 
> looking at ninja, but there does not appear to be a django plugin. 
>
> Thanks,
>
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/MYUmTKK0fZEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Looking for Django IDE

2012-04-01 Thread thongor
I use vim with a plugin called "python mode" which can be found 
here. 
It's a collection of several python plugins that gives you a lot of 
options. You can also check out various vimrc files on github for other 
ideas.


On Sunday, April 1, 2012 2:30:03 PM UTC-4, mark wrote:
>
> What IDE do you use/recommend for developing django web sites? Or, if not 
> an IDE, what editor/setup is most useful? I am developing on Linux version 
> 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I 
> use eclipse for developing android/java projects. Since I am using django 
> in conjunction with an android project, I don't want to use the plugin for 
> eclipse. Switching between python and java perspectives is a little 
> annoying, so I thought I would find a separate ide for my django work and 
> just alt-tab between them.
>
> I have tried gedit, but I cannot get the django plugin to work. I am 
> looking at ninja, but there does not appear to be a django plugin. 
>
> Thanks,
>
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/t3eiaOGl6ggJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: canceling account

2012-04-01 Thread Python_Junkie
It does not appear that anyone truly answered your question.

The accounts are maintained in a database.

Figure out which table and which columns the account that you want to 
remove are maintained.  You can accomplish this by viewing a development 
server that you may have in house and spinning up a new instance and create 
an admin account.

Then just delete the account from the database to remove the person that 
you want to remove.

Or you could just change the name  so that you have control of the account 
your self.

Good luck

On Saturday, March 31, 2012 9:52:20 AM UTC-4, JoeLinux wrote:
>
> Lilian,
>
> To be clear here, Django is a web framework for creating web applications. 
> Then there are web hosting services out there that will let you run your 
> Django applications on their servers. Within your own Django application, 
> you may have administrative accounts setup.
>
> What account (and where) is it that you need removed, exactly?
>
> --
> Joey Espinosa
> Software Engineer
> http://about.me/joelinux
> On Mar 31, 2012 9:44 AM, "Sergiy Khohlov"  wrote:
>
>> Hello,
>>  What do you  mean ?
>> Each  django application has  ability to add  django superuser account.
>> Also hoster company provide a  account  for setting django application
>>  at the host.
>> Please clarify  what do you want to do
>>
>>  Thanks,
>> Serge
>>
>> 2012/3/31 Lillian Cauldwell :
>> >
>> > My previous webmaster set up my company's d'jango account.
>> > He no longer works for me.
>> > How do I cancel my account?
>> >
>> > Thanks,
>> > Lillian
>> > --
>> > "Creator" Cauldwell
>> > CEO, Passionate World Radio, Inc.
>> > Distinguish Yourself From the Ordinary! (c) 2010-2011 PWR
>> > http://www.internetvoicesradio.com
>> > http://www.amazingworldsoflscauldwell.com
>> > http://pwrwebtv.intuitwebsites.com
>> > 734-827-9407
>> >
>> > --
>> > You received this message because you are subscribed to the Google 
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > 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 post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ATwivI_wFU0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



form.Forms + POST + forms.ChoiceField

2012-04-01 Thread Barry Morrison
Full Disclosure: I've been using Python for 5-6 months. Django for maybe 3

I have this: https://gist.github.com/a934fe08643e0c3ee017

In an effort to teach myself, I'm simply building a Django app. For 
teaching purposes only. It's an aggregator of favorites across multiple 
sites. Right now, I'm simply dealing with saved items from Reddit. 

The problem I'm having is the drop-down selector POST'ing and creating a 
the new URL. 

http://imgur.com/a/FL32I << Screen shots

1) root or /feeds/
2) Select Reddit from drop-down
3) Displays Reddit items only /feeds/Reddit/
4) Select 'Python' from drop-down, displays items from r/Python with URL 
/feeds/Reddit/Python

This works (manually entering URL's), the drop down does not. 

I currently get "Error 1" from the gist. 

On views.py, if I uncomment lines 16 - 19, and comment the lines 21 - 23, I 
get a different error: "Error2" from the gist.  What I don't understand 
regarding the 2nd error, is that it is in fact returning: source: u'Reddit' 
and that exists in the Model, so it makes me think it's expecting something 
other than u'Reddit'.  

I'm at a loss, so this is me asking for help.  Sorry for the long post and 
crazy amounts of information. 

Any help is GREATLY APPRECIATED! 

Thanks! 
POST

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/zXNmsoqAfdMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Bulk Creating Django Models from CSV File?

2012-04-01 Thread Victor Hooi
Hi,

I have several large CSV files that I'm hoping to parse, and use to create 
Django objects. Each line looks might look something like this:

"Server Hostname", "Classification", "Country", "Operating System"

"foo.bar.com", "Prod", "Australia", "Solaris"

"alex.john.com", "Dev", "UK", "Linux"

"bob.hope.com", "UAT, "Japan", "Windows


For performance reasons, it would be nice to use something like 1.4's 
bulk_create:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.bulk_create
 

However, I noticed the caveat about it not populating the auto-incrementing 
PK field. What's the recommended way to populate the PK field then? How do 
you use it?

Secondly, the models will have FK relationships to other models (for 
instance, Classification, Country and Operating System would be stored in a 
lookup table). What's the best way to look these up, and assign the 
appropriate FK, whilst still preserving good performance and using bulk 
inserts?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bP0RG4NXJjEJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



RE: Looking for Django IDE

2012-04-01 Thread Sells, Fred
Is there a Django 1.4.1 in the works that would solve this problem?  I
also use Eclipse+PyDev and am planning to upgrade to Django 1.4 shortly.
However my management is not going to allow using a nightly build in a
production system regardless of the justification.  I guess my options
are to stick with 1.3 or create a dummy project manually and copy and
tweak it whenever I need a new project.  Any suggestions.

>From the forum post, it was not clear if this is a Django, PyDev or
Eclipse issue.  Any thoughts?

Fred.

-Original Message-
From: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] On Behalf Of Alexandros Karypidis
Sent: Sunday, April 01, 2012 3:57 PM
To: django-users@googlegroups.com
Subject: Re: Looking for Django IDE

Hi,

I'm using PyDev in Eclipse and it seems quite nice: http://pydev.org/

Have a look at the Django-specific stuff: 
http://pydev.org/manual_adv_django.html

Please note that you must use a nightly build for Django 1.4 due to
this:
http://sourceforge.net/projects/pydev/forums/forum/293649/topic/5158643

Cheers,
Alex


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



Doubt regarding endless pagination

2012-04-01 Thread Swaroop Shankar V
Hi All,
This question is regarding a django app called endless pagination. I want
to add a '|' in between the pagination numbers so that it will look like
<>

I went through the documents but could not figure out how to do this. If
anyone have already implemented something like this please tell me know the
method to implement the same. Thank You

Regards,

Swaroop Shankar V

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