RE: Cannot import mypackage with code in the __init__.py file

2013-06-19 Thread Sells, Fred
Thanks Bill, I've tried all but the __future__ option.  I'll give it a try.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Bill Freeman
Sent: Wednesday, June 19, 2013 3:03 PM
To: django-users
Subject: Re: Cannot import mypackage with code in the __init__.py file

Have you tried
   import app.mypackage
or
from app import mypackage
Or, from within views.py or mymodule.py, if you have done
from __future__ import absolute_imports
then try
  import .mypackage
(There is a period before "mypackage" on that line.)

On Wed, Jun 19, 2013 at 2:51 PM, fred 
mailto:fred.se...@adventistcare.org>> wrote:
I'm upgrading to django 1.5.1 on CentOs 6.4 with python 2.6.6  although I'm 
developing on a W7 with the django debug server.

I am getting executing my view.py and most of the modules it uses.  But in one 
scenario, the import fails, see directory outline below

NewMdsServer
   |___NewMdsServer
  |___settings.py
  |___wsgi.py
  |___ ...
   |___app
|___views.py
|___mymodule.py
|___mypackage
   |___  __init__.py
   |___  x.py
   |___  y.py

I have code in the __init__.py which then imports x, y, etc

I cannot seem to import mypackage from views or other modules at the same 
level.  I've tried multiple variants as shown below and sys.path includes the 
directory above app.
from app import mypackage  -- "No module named mypackage"
import mypackage  -- "No module named ..
import app.mypackage -- ditto

The really strange thing is I could swear this was working last week  before I 
got pulled off onto another project for a few days.  I'm the only one using 
this server and I have root access.  I've tried google, but cannot find a 
phrase that gives me anything useful.  I would really appreciate some advice on 
what I'm doing wrong.

Thanks,

Fred.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.



--
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.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to use lxml with django

2013-06-19 Thread cha
waiting for you

On Wednesday, 19 June 2013 16:24:07 UTC-4, ovnicraft wrote:
>
> Hello,
>
> On Wed, Jun 19, 2013 at 3:09 PM, cha >wrote:
>
>> how generate xml or dme file django
>> I want the result be like this : 
>> 
>>   asfa Adnan 
>> Company
>>   asfa 
>> Adnan
>>   Company Model for asfa 
>> Adnan
>>   Alaaadnan
>>   
>> Company
>> 
>>
>
>  Your question is more about lxml, you can read about it in 
> http://lxml.de/tutorial.html.
>
> If you can provide us more info about it, we can help you.
>
> Best regards, 
>
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Cristian Salamea
> @ovnicraft 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Script to move django 1.4.3 to 1.5.1

2013-06-19 Thread Deepak
Okay but my situation is bit different. I am updating my university software. 
That software is wrote in django version 1.3.1. My challenge was to run that 
software on 1.5.1 and i completed that. As many things changed in django 1.5.1 
like < direct_to_template > changed to  < TemplateView> and few more. So my 
next target is that, that i make one script ( shell script ) so that i give 
command in terminal like $ sudo apt-get install  and it install. Shifting 
from 1.3 to 1.5.1 is it possible? If yes than how?

If i want to run my software which is currently running on 1.5.1 with command 
in terminal i.e i write $ sudo apt-get install mysoftware and it install. I 
don't want to install it manually. How i do that process with shell script? 

Help me @django-users member cos my head is on edge of knife.  

Deepak Kumar Sharma 
Blog
http://deekaysharma.wordpress.com


On 20-Jun-2013, at 5:25 AM, Russell Keith-Magee  wrote:

> You shouldn't need any sort of scrip to upgrade your Django version. If 
> you're running under Django 1.4.3, and you haven't been getting any warnings 
> when you run your code, you should be able to just update to Django 1.5.1 and 
> run without making any other changes.
> 
> The only cases where this won't be the case is where you're relying on 
> undocumented or internal APIs. Django has a very strict backwards 
> compatibility policy on its public APIs -- if we need to make any backwards 
> incompatible change to code, we introduce those changes over several 
> versions, and make the server raise warnings to give you an indication that 
> you need to update code.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Installing/implementing a Python-based API on my website

2013-06-19 Thread C. N. Desrosiers
Hi,

I recently completed the Capitol Words API course at codecademy.com and I 
have experience building websites in HTML + CSS, but I have never installed 
an API before.  I can manipulate the Python code on its own, but I don't 
understand the steps between having the Python code in order and actually 
implementing it on a site.  I can't seem to find any helpful tutorials. 
 Everything I find seems to assume that the user knows how to complete this 
final step.  Does this have to be done via Django?  Can anyone point me to 
a tutorial?

Thanks in advance.

CND

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: user authentication with extended (AbstractUser) user model

2013-06-19 Thread Russell Keith-Magee
On Thu, Jun 20, 2013 at 4:16 AM, Evan Stone  wrote:

> Sure thing. Here are the snippets that gave me pause:
>
> "Think carefully before handling information not directly related to
> authentication in your custom User Model.
>
> It may be better to store app-specific user information in a model that
> has a relation with the User model. That allows each app to specify its own
> user data requirements without risking conflicts with other apps"
>
> along with
>
> "One limitation of custom User models is that installing a custom User
> model will break any proxy model extending 
> User.
> ..."
>
> and
>
> "Another limitation of custom User models is that you can’t use
> django.contrib.auth.get_user_model()
>  as
> the sender or target of "
>
>
> Thanks for giving those details. I've opened ticket #20629 [1] to track
this problem -- hopefully we can get this documentation cleaned up so we
don't scare others in the future.

[1] https://code.djangoproject.com/ticket/20629

By way of explanation:

Points 1 and 2 are asking you to consider an architectural question -- do
you need a custom user model at all? If you actually *are* using a
username-based login system, and you just want to track some extra
information about the user, the right approach may *not* be to create a
custom user model.

Points 3 and 4 are pointing out known limitations. Proxy models are a
problem because they use subclassing, and they will be subclassing the
wrong class; signals are a problem because at the point the signal is
registered, there's no guarantee that the User model has been correctly
defined. There's not much we can do about (3); (4) is something that should
get cleaned up when we eventually land app refactor.

Yours,
Russ Magee %-)

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Calling ffmpeg doesn't work on apache server

2013-06-19 Thread John
Chad,

Are you restarting apache after each change? It sounds like you have the
default 2 workers and you are getting two different 'versions'
alternately. Apache needs to be restarted if you change something (or
there's some magic touch you can do with wsgi that I forget).

Otherwise it does look like permissions, or running in the wrong
directory, or such like.

John

On 20/06/13 00:48, Chad Vernon wrote:
> One last observation:
>
> I think it has something to do with the apache user permissions.  I'm
> running the mod_wsgi daemon process with myself as the user and I need
> to specify the full path to ffmpeg (/usr/local/bin/ffmpeg).  Even when
> I do that the function runs every other time.  So I'm totally confused
> now.  I'm an apache/django beginner so bear with me please!
>
>
>
> On Wednesday, June 19, 2013 4:12:02 PM UTC-7, Chad Vernon wrote:
>
> Looks like it has something to do with calling subprocess from the
> server because this gives the same error:
>
> response = subprocess.check_output(['which', 'ls'])
>
> Anyone have any suggestions?
>
> On Wednesday, June 19, 2013 4:01:30 PM UTC-7, Chad Vernon wrote:
>
> I'm trying to use ffmpeg to generate a thumbnail for a video.
>  It works just fine when I call it from a python shell and
> when I test it in "python manage.py shell".  However when I
> try to run from the apache server running locally, I get an
> error:
>
> # normally I call subprocess.call, but for debug here I'm
> calling check_call
> response = subprocess.check_call(['ffmpeg', '-i',
> self.file.path], stderr=fh)
>
> # actual path taken out for brevity
> Command '['ffmpeg', '-i', u'...']' returned non-zero exit
> status -6
>
> I've verified that the video path is correct.
>
> Any suggestions?
>
> Thanks!
> Chad
>
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Script to move django 1.4.3 to 1.5.1

2013-06-19 Thread Russell Keith-Magee
On Thu, Jun 20, 2013 at 3:17 AM, Deepak Sharma wrote:

> Hi everyone
>
> I just started learning django. Question arises in my mind to write a
> script, by using that script i wanted to jump django version  1.5.1 without
> effecting my previous settings or effecting my application which is
> currently running on django 1.4.3. Is it possible to do that? If yes than
> how? I have just little bit knowledge about script. Can anyone help me in
> this process.?
>
>
You shouldn't need any sort of scrip to upgrade your Django version. If
you're running under Django 1.4.3, and you haven't been getting any
warnings when you run your code, you should be able to just update to
Django 1.5.1 and run without making any other changes.

The only cases where this won't be the case is where you're relying on
undocumented or internal APIs. Django has a very strict backwards
compatibility policy on its public APIs -- if we need to make any backwards
incompatible change to code, we introduce those changes over several
versions, and make the server raise warnings to give you an indication that
you need to update code.

Yours,
Russ Magee %-)

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Calling ffmpeg doesn't work on apache server

2013-06-19 Thread Chad Vernon
One last observation:

I think it has something to do with the apache user permissions.  I'm 
running the mod_wsgi daemon process with myself as the user and I need to 
specify the full path to ffmpeg (/usr/local/bin/ffmpeg).  Even when I do 
that the function runs every other time.  So I'm totally confused now.  I'm 
an apache/django beginner so bear with me please!



On Wednesday, June 19, 2013 4:12:02 PM UTC-7, Chad Vernon wrote:
>
> Looks like it has something to do with calling subprocess from the server 
> because this gives the same error:
>
> response = subprocess.check_output(['which', 'ls'])
>
> Anyone have any suggestions?
>
> On Wednesday, June 19, 2013 4:01:30 PM UTC-7, Chad Vernon wrote:
>>
>> I'm trying to use ffmpeg to generate a thumbnail for a video.  It works 
>> just fine when I call it from a python shell and when I test it in "python 
>> manage.py shell".  However when I try to run from the apache server running 
>> locally, I get an error:
>>
>> # normally I call subprocess.call, but for debug here I'm calling 
>> check_call
>> response = subprocess.check_call(['ffmpeg', '-i', self.file.path], 
>> stderr=fh)
>>
>> # actual path taken out for brevity
>> Command '['ffmpeg', '-i', u'...']' returned non-zero exit status -6
>>
>> I've verified that the video path is correct.
>>
>> Any suggestions?
>>
>> Thanks!
>> Chad
>>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Per-Request Query-set Cache

2013-06-19 Thread Joey Espinosa
Look into johnny-cache.

https://github.com/jmoiron/johnny-cache

--
Joey "JoeLinux" Espinosa
Python Developer
http://about.me/joelinux
On Jun 19, 2013 7:33 PM, "Kurtis"  wrote:

> I could have sworn I've already asked this question but didn't see it in
> my search results. Anyways,
>
> I have a large set of calculations in my models. I'm trying to stick with
> the OOP style for future maintainers or whomever else has to work with the
> code. The problem is that I'm up to 100 queries on a single view. Many of
> these queries are duplicated. Others are very close to being duplicated
> except for the 'comparison key'. (e.g. where user = foo)
>
> I'm hoping there is some sort of mechanism out there to easily cache these
> DB calls on a per-query basis. The calculations themselves are incredibly
> intensive (relatively speaking) but 100 queries per view can easily turn
> into a nightmare if this project becomes popular.
>
> Is there any "out of the box" solutions to caching Query Sets within the
> scope of a single request? I am using a combination of class methods,
> instance methods, and in some places simple generic methods so I'm really
> pursuing a way to cache these at a lower level. These should only be cached
> for the duration of the request.
>
> I've seen some 'hackish' options and of course there are the larger ORM
> caching libraries but I'd like to find a clean solution without a whole lot
> of overhead.
>
> Thanks!
> - Kurtis
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Per-Request Query-set Cache

2013-06-19 Thread Kurtis
I could have sworn I've already asked this question but didn't see it in my 
search results. Anyways,

I have a large set of calculations in my models. I'm trying to stick with 
the OOP style for future maintainers or whomever else has to work with the 
code. The problem is that I'm up to 100 queries on a single view. Many of 
these queries are duplicated. Others are very close to being duplicated 
except for the 'comparison key'. (e.g. where user = foo)

I'm hoping there is some sort of mechanism out there to easily cache these 
DB calls on a per-query basis. The calculations themselves are incredibly 
intensive (relatively speaking) but 100 queries per view can easily turn 
into a nightmare if this project becomes popular.

Is there any "out of the box" solutions to caching Query Sets within the 
scope of a single request? I am using a combination of class methods, 
instance methods, and in some places simple generic methods so I'm really 
pursuing a way to cache these at a lower level. These should only be cached 
for the duration of the request.

I've seen some 'hackish' options and of course there are the larger ORM 
caching libraries but I'd like to find a clean solution without a whole lot 
of overhead.

Thanks!
- Kurtis

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Calling ffmpeg doesn't work on apache server

2013-06-19 Thread Chad Vernon
Looks like it has something to do with calling subprocess from the server 
because this gives the same error:

response = subprocess.check_output(['which', 'ls'])

Anyone have any suggestions?

On Wednesday, June 19, 2013 4:01:30 PM UTC-7, Chad Vernon wrote:
>
> I'm trying to use ffmpeg to generate a thumbnail for a video.  It works 
> just fine when I call it from a python shell and when I test it in "python 
> manage.py shell".  However when I try to run from the apache server running 
> locally, I get an error:
>
> # normally I call subprocess.call, but for debug here I'm calling 
> check_call
> response = subprocess.check_call(['ffmpeg', '-i', self.file.path], 
> stderr=fh)
>
> # actual path taken out for brevity
> Command '['ffmpeg', '-i', u'...']' returned non-zero exit status -6
>
> I've verified that the video path is correct.
>
> Any suggestions?
>
> Thanks!
> Chad
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Calling ffmpeg doesn't work on apache server

2013-06-19 Thread Chad Vernon
I'm trying to use ffmpeg to generate a thumbnail for a video.  It works
just fine when I call it from a python shell and when I test it in "python
manage.py shell".  However when I try to run from the apache server running
locally, I get an error:

# normally I call subprocess.call, but for debug here I'm calling check_call
response = subprocess.check_call(['ffmpeg', '-i', self.file.path],
stderr=fh)

# actual path taken out for brevity
Command '['ffmpeg', '-i', u'...']' returned non-zero exit status -6

I've verified that the video path is correct.

Any suggestions?

Thanks!
Chad

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Multiple modelforms, mixing existing and non existing instances

2013-06-19 Thread Freddy
Hi everyone,

I'm trying to get a particular formset, but i'm stuck on it.

In my database, I have some information stored around external data, 
represented by this kind of model :

LiveInfo(models.Model):
external_id = models.IntegerField()
live_url = models.URLField()
description = models.TextField()

(I receive data from an external API, and I store the above information 
around it, external_id refers to the external element)
Not all external elements have local information associated, depending of 
the needs for a "live" or not.

What I need to do is, from a list of external ids, to construct a set of 
forms representing the data I may have around them.
For exemple, from the external ids [12, 20, 48, 50, 55, 58, ], I need to 
construct a set of forms for each element, filled with the local LiveInfo 
data if present, empty forms for the others.
The problem is that I need them in the exact order that I receive the ids. 
This means that my formset will alternate empty and filled forms.

On global save, of course, I update the already present LiveInfo, and 
create new ones for the others.

But I can't find any way to do this properly with formsets. Maybe it's 
simply not possible, and I have to construct my own set of individual 
forms, an manage my own global validation.

I don't know if I'm clear enough, hope so.

Any idea please ? :D

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to use lxml with django

2013-06-19 Thread cha
Please Can Give Me Simple Example For View in Django

On Wednesday, 19 June 2013 16:24:07 UTC-4, ovnicraft wrote:
>
> Hello,
>
> On Wed, Jun 19, 2013 at 3:09 PM, cha >wrote:
>
>> how generate xml or dme file django
>> I want the result be like this : 
>> 
>>   asfa Adnan 
>> Company
>>   asfa 
>> Adnan
>>   Company Model for asfa 
>> Adnan
>>   Alaaadnan
>>   
>> Company
>> 
>>
>
>  Your question is more about lxml, you can read about it in 
> http://lxml.de/tutorial.html.
>
> If you can provide us more info about it, we can help you.
>
> Best regards, 
>
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Cristian Salamea
> @ovnicraft 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to use lxml with django

2013-06-19 Thread Ovnicraft
Hello,

On Wed, Jun 19, 2013 at 3:09 PM, cha  wrote:

> how generate xml or dme file django
> I want the result be like this :
> 
>   asfa Adnan
> Company
>   asfa Adnan
>   Company Model for asfa
> Adnan
>   Alaaadnan
>
> Company
> 
>

Your question is more about lxml, you can read about it in
http://lxml.de/tutorial.html.

If you can provide us more info about it, we can help you.

Best regards,

>
>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Cristian Salamea
@ovnicraft

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




RE: Sending emails, models or views?

2013-06-19 Thread Babatunde Akinyanmi
Coincidentally, I debated this with myself this afternoon. At the end,
i put my notify_by_email method in models.py because I didn't need the
request object and it kinda "felt at home" there. However, I'd have put
it in my view if I needed the request object so personally, it depends
on use case.


Sent from my Windows Phone
From: Marc Aymerich
Sent: 6/19/2013 7:13 PM
To: django-users@googlegroups.com
Subject: Sending emails, models or views?
Yep,
I'm more or less convinced that the logic needed for sending an email
should go into models. But what about the action (method call) of
sending the email? what layer should be responsible for triggering an
email notification? models or views? This is something I keep
wondering myself for a long time ...

for example, imagine we have a simple Ticket model with two methods,
update() and notify_owner()

class Ticket(models.Model):
def update(self):
self.updated_on = now()
self.save()

def notify_owner(self, msg):
send_mail(self.owner, msg)


now we want to notify the owner each time a Ticket is updated, shall
we include a self.notify_owner('updated!') call on the update()
method, so we make sure of that? or maybe it is better to do this on
the view each time ticket.update() is called?

There are some pros and cons,
In the views we have access to the request object which some times is
handy because we need some request info to include on the mail.
Including the call into the model we make sure that each time we will
send an email notification and DRY is good, but is this behavior
correct? maybe we only want to notify under certain circumstances...

So anyone has thought about this? any rule of thumb? maybe it totally
depends on the use case? does this question even make sense? :)

Thanks for your answers!
-- 
Marc

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: user authentication with extended (AbstractUser) user model

2013-06-19 Thread Evan Stone
Also, thank you again!

On Wednesday, June 19, 2013 3:16:05 PM UTC-5, Evan Stone wrote:
>
> Sure thing. Here are the snippets that gave me pause:
>
> "Think carefully before handling information not directly related to 
> authentication in your custom User Model.
>
> It may be better to store app-specific user information in a model that 
> has a relation with the User model. That allows each app to specify its own 
> user data requirements without risking conflicts with other apps"
>
> along with
>
> "One limitation of custom User models is that installing a custom User 
> model will break any proxy model extending 
> User.
>  
> ..."
>
> and
>
> "Another limitation of custom User models is that you can’t use 
> django.contrib.auth.get_user_model()
>  as 
> the sender or target of "
>
>
>
>
> On Tuesday, June 18, 2013 6:34:16 PM UTC-5, Russell Keith-Magee wrote:
>>
>>
>> On Tue, Jun 18, 2013 at 11:37 PM, Evan Stone  wrote:
>>
>>> Russ, 
>>>
>>> Thanks so much for getting back to me! I shouldn't have posted that 
>>> without my code in front of me... (was posting from my phone, in bed) 
>>>
>>> It turns out that I did NOT have AUTH_USER_MODEL set. I had 
>>> AUTH_PROFILE_MODULE set.
>>>
>>
>> Ah - that'll do it :-) 
>>  
>>
>>> I changed it to AUTH_USER_MODEL and followed the custom user model 
>>> example in the docs. I was really reluctant to do so earlier because the 
>>> docs make it sound like everything is pain moving forward with a custom 
>>> user model. Is it?
>>>
>>  
>> There are some things you need to keep in mind, but they're generally 
>> complications because you can't rely on User having a 30 character username 
>> and option email address, and so on. The trivial solution will always to be 
>> the builtin User model, but as long as you're aware of the assumptions 
>> you're making about your user model, switching to a new User model 
>> shouldn't be too much pain at all. The changes required should be 
>> relatively obvious -- for example, you'll need a new form definition for 
>> any User-based forms, because Django can't know what fields are needed for 
>> *your* User model.
>>
>> Can you elaborate what aspect of the docs made you feel like the process 
>> of using a custom User model would be a pain? We added the feature because 
>> we feel it will be useful (and in my experience so far, it is). We want 
>> people to be aware that there will be complications, but we don't want to 
>> unilaterally scare people off. 
>>
>> Yours,
>> Russ Magee %-)
>>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: user authentication with extended (AbstractUser) user model

2013-06-19 Thread Evan Stone
Sure thing. Here are the snippets that gave me pause:

"Think carefully before handling information not directly related to 
authentication in your custom User Model.

It may be better to store app-specific user information in a model that has 
a relation with the User model. That allows each app to specify its own 
user data requirements without risking conflicts with other apps"

along with

"One limitation of custom User models is that installing a custom User 
model will break any proxy model extending 
User.
 
..."

and

"Another limitation of custom User models is that you can’t use 
django.contrib.auth.get_user_model()
 as 
the sender or target of "




On Tuesday, June 18, 2013 6:34:16 PM UTC-5, Russell Keith-Magee wrote:
>
>
> On Tue, Jun 18, 2013 at 11:37 PM, Evan Stone 
> > wrote:
>
>> Russ, 
>>
>> Thanks so much for getting back to me! I shouldn't have posted that 
>> without my code in front of me... (was posting from my phone, in bed) 
>>
>> It turns out that I did NOT have AUTH_USER_MODEL set. I had 
>> AUTH_PROFILE_MODULE set.
>>
>
> Ah - that'll do it :-) 
>  
>
>> I changed it to AUTH_USER_MODEL and followed the custom user model 
>> example in the docs. I was really reluctant to do so earlier because the 
>> docs make it sound like everything is pain moving forward with a custom 
>> user model. Is it?
>>
>  
> There are some things you need to keep in mind, but they're generally 
> complications because you can't rely on User having a 30 character username 
> and option email address, and so on. The trivial solution will always to be 
> the builtin User model, but as long as you're aware of the assumptions 
> you're making about your user model, switching to a new User model 
> shouldn't be too much pain at all. The changes required should be 
> relatively obvious -- for example, you'll need a new form definition for 
> any User-based forms, because Django can't know what fields are needed for 
> *your* User model.
>
> Can you elaborate what aspect of the docs made you feel like the process 
> of using a custom User model would be a pain? We added the feature because 
> we feel it will be useful (and in my experience so far, it is). We want 
> people to be aware that there will be complications, but we don't want to 
> unilaterally scare people off. 
>
> Yours,
> Russ Magee %-)
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




How to use lxml with django

2013-06-19 Thread cha
how generate xml or dme file django
I want the result be like this : 

  asfa Adnan 
Company
  asfa Adnan
  Company Model for asfa 
Adnan
  Alaaadnan
  
Company


-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Script to move django 1.4.3 to 1.5.1

2013-06-19 Thread Deepak Sharma
Hi everyone

I just started learning django. Question arises in my mind to write a
script, by using that script i wanted to jump django version  1.5.1 without
effecting my previous settings or effecting my application which is
currently running on django 1.4.3. Is it possible to do that? If yes than
how? I have just little bit knowledge about script. Can anyone help me in
this process.?

Thanks
-- 
Deepak Kumar Sharma

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Cannot import mypackage with code in the __init__.py file

2013-06-19 Thread fred
a quick update,  if I use >python manage.py shell   everything works as I 
would expect, no problems.
also I tried removing all code from my __init__.py (yes I'm grasping at 
straws) and that did not 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Cannot import mypackage with code in the __init__.py file

2013-06-19 Thread Bill Freeman
Have you tried

   import app.mypackage

or

from app import mypackage

Or, from within views.py or mymodule.py, if you have done

from __future__ import absolute_imports

then try

  import .mypackage

(There is a period before "mypackage" on that line.)


On Wed, Jun 19, 2013 at 2:51 PM, fred  wrote:

> I'm upgrading to django 1.5.1 on CentOs 6.4 with python 2.6.6  although
> I'm developing on a W7 with the django debug server.
>
> I am getting executing my view.py and most of the modules it uses.  But in
> one scenario, the import fails, see directory outline below
>
> NewMdsServer
>|___NewMdsServer
>   |___settings.py
>   |___wsgi.py
>   |___ ...
>|___app
> |___views.py
> |___mymodule.py
> |___mypackage
>|___  __init__.py
>|___  x.py
>|___  y.py
>
> I have code in the __init__.py which then imports x, y, etc
>
> I cannot seem to import mypackage from views or other modules at the same
> level.  I've tried multiple variants as shown below and sys.path includes
> the directory above app.
> from app import mypackage  -- "No module named mypackage"
> import mypackage  -- "No module named ..
> import app.mypackage -- ditto
>
> The really strange thing is I could swear this was working last week
> before I got pulled off onto another project for a few days.  I'm the only
> one using this server and I have root access.  I've tried google, but
> cannot find a phrase that gives me anything useful.  I would really
> appreciate some advice on what I'm doing wrong.
>
> Thanks,
>
> Fred.
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Cannot import mypackage with code in the __init__.py file

2013-06-19 Thread fred
I'm upgrading to django 1.5.1 on CentOs 6.4 with python 2.6.6  although I'm 
developing on a W7 with the django debug server.

I am getting executing my view.py and most of the modules it uses.  But in 
one scenario, the import fails, see directory outline below

NewMdsServer
   |___NewMdsServer
  |___settings.py
  |___wsgi.py 
  |___ ...
   |___app
|___views.py
|___mymodule.py
|___mypackage
   |___  __init__.py
   |___  x.py
   |___  y.py

I have code in the __init__.py which then imports x, y, etc

I cannot seem to import mypackage from views or other modules at the same 
level.  I've tried multiple variants as shown below and sys.path includes 
the directory above app.
from app import mypackage  -- "No module named mypackage"
import mypackage  -- "No module named ..
import app.mypackage -- ditto

The really strange thing is I could swear this was working last week  
before I got pulled off onto another project for a few days.  I'm the only 
one using this server and I have root access.  I've tried google, but 
cannot find a phrase that gives me anything useful.  I would really 
appreciate some advice on what I'm doing wrong.

Thanks,

Fred.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: reverse funtion gives me url including server path

2013-06-19 Thread Timster
It's this line:

PythonOption django.root /var/www/project

Change that to / or anything else and you should be all set.

On Wednesday, June 19, 2013 10:32:12 AM UTC-4, Jiří Kupka wrote:
>
> Hi! I have little trouble with reverse function in my project. When I run 
> it over ./manage runserver, everything is fine - reverse gives me url in 
> /page/xx format. When I run my project over apache2 using this conf file:
>
> Listen 8001
>
> 
> ServerName project.tld
> DocumentRoot "/var/www/project"
> ErrorLog /var/www/project/error.log
> CustomLog /var/www/project/access.log combined
> 
> SetHandler python-program
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE settings
> PythonOption django.root /var/www/project
> PythonDebug Off
> PythonPath 
> "['/var/www/','/var/www/project','/usr/local/lib/site-packages/django'] + 
> sys.path"
> 
> 
>
> reverse gives me url in /var/www/project/page/xxx format -> 
> http://project.tld/var/www/project/page/xxx. What is interesting, I can 
> open http://project.tld/page/xxx and 
> http://project.tld/var/www/project/page/xxx and I get same results, but 
> reverese function returns "ugly" full path...
>
> Any suggestions, how can I fix it?
>
> Thanks,
> Jirka
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




DjangoCon. US CFP extended

2013-06-19 Thread Christophe Pettus
Hi, all,

We're extending the CFP for DjangoCon US 2013 through 6/25, since there was a 
last-minute burst of activity.  We are still looking for talks and tutorials; 
first-time presenters particularly encouraged to participate!  The URL is:

http://www.djangocon.us/cfp/

(The site is being updated shortly, but if it still says 6/18, don't worry.)

Thanks,
--
-- Christophe Pettus
   x...@thebuild.com

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Sending emails, models or views?

2013-06-19 Thread Marc Aymerich
Yep,
I'm more or less convinced that the logic needed for sending an email
should go into models. But what about the action (method call) of
sending the email? what layer should be responsible for triggering an
email notification? models or views? This is something I keep
wondering myself for a long time ...

for example, imagine we have a simple Ticket model with two methods,
update() and notify_owner()

class Ticket(models.Model):
def update(self):
self.updated_on = now()
self.save()

def notify_owner(self, msg):
send_mail(self.owner, msg)


now we want to notify the owner each time a Ticket is updated, shall
we include a self.notify_owner('updated!') call on the update()
method, so we make sure of that? or maybe it is better to do this on
the view each time ticket.update() is called?

There are some pros and cons,
In the views we have access to the request object which some times is
handy because we need some request info to include on the mail.
Including the call into the model we make sure that each time we will
send an email notification and DRY is good, but is this behavior
correct? maybe we only want to notify under certain circumstances...

So anyone has thought about this? any rule of thumb? maybe it totally
depends on the use case? does this question even make sense? :)

Thanks for your answers!
-- 
Marc

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: captcha field django form designer, success html mail.

2013-06-19 Thread Felipe Coelho
2013/6/19 pradnya 

> ...
>
> ('django.forms.RegexField', _('Regex')),
>
> ('django.forms.FileField', _('File')),
>
> # ('captcha.fields.CaptchaField', _('Captcha')),
>
>
 The django-recaptcha field is called "ReCaptchaField", not just
"CaptchaField"

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




captcha field django form designer, success html mail.

2013-06-19 Thread pradnya
Hi !,

I am working on django cms based website. Where I used django form 
designer( https://github.com/samluescher/django-form-designer)

Now I want to integrate djago-recaptcha with django form designer to add 
captch field in form.

In django-form-designer settings.py 

FIELD_CLASSES = getattr(settings, 'FORM_DESIGNER_FIELD_CLASSES', (
('django.forms.CharField', _('Text')),
('django.forms.EmailField', _('E-mail address')),
('django.forms.URLField', _('Web address')),
('django.forms.IntegerField', _('Number')),
('django.forms.DecimalField', _('Decimal number')),
('django.forms.BooleanField', _('Yes/No')),
('django.forms.DateField', _('Date')),
('django.forms.DateTimeField', _('Date & time')),
('django.forms.TimeField', _('Time')),
('django.forms.ChoiceField', _('Choice')),
('django.forms.MultipleChoiceField', _('Multiple Choice')),
('django.forms.ModelChoiceField', _('Model Choice')),
('django.forms.ModelMultipleChoiceField', _('Model Multiple Choice')),
('django.forms.RegexField', _('Regex')),
('django.forms.FileField', _('File')),
# ('captcha.fields.CaptchaField', _('Captcha')),
))

Captcha field is commented, so I tried to override the settings in my project's 
settings. 
Then I get error "CaptchaField does not exist". What should I do ?

And another doubt is how to send html email after successful submission of form.

Any pointer or help would be great.

Thanks 

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: export .csv file from database

2013-06-19 Thread Radomir Wojcik

>
> this might come of use, it exports any query set to csv. I use it a lot:
>
>
def queryset_export_csv(qs):
import csv
#from django.db.models.loading import get_model

response = HttpResponse(mimetype='text/csv')
# force download.
response['Content-Disposition'] = 
'attachment;filename="service_export.csv"'

# the csv writer
writer = csv.writer(response)

qs_model = qs.model

headers = []
for field in qs_model._meta.fields:
headers.append(field.name)
writer.writerow(headers)

for obj in qs:
row = []
for field in headers:
val = getattr(obj, field)
if callable(val):
val = val()
if type(val) == unicode:
val = val.encode("utf-8")
row.append(val)
writer.writerow(row)

return response 

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: export .csv file from database

2013-06-19 Thread Vernon D. Cole
 I am guessing that your csv writer is outputting something that your 
spreadsheet is reading incorrectly.  Try opening the csv with a text editer 
(a good one, like Notepad++) so that you can really see what is going on. 
Embedded commas or quotes inside a field are invitations for disaster, and 
you have both.  You may need to change the settings on the csv writer -- it 
has lots of them, and different spreadsheet programs interpret different 
csv files differently.  The default settings are usually good for Excel, 
but you don't mention which spreadsheet you are trying to do the reading 
with, nor what settings you are using at import time.  You must find a 
combination that works for your situation (and it will not be easy.)  It 
may actually be easier to re-design the target system than to meet its 
existing requirements.
  Another option would be to use a tool like xlwt and send out a real 
spreadsheet rather than a .csv.  That way, all interpretation is under your 
control.  


On Monday, June 17, 2013 4:44:39 PM UTC+1, roopas...@gmail.com wrote:
>
> views.py
>
> @login_requireddef export_csv(request):
> user = request.user
> # heading columns
> headerrow = ['Filename', 'Description','Notes other','Reporter Name']
> allrows = []
> today = datetime.datetime.today() # default to show today
> reports = Report.objects.filter(user=user)
> reports = reports.filter(created_date_time__year=today.year)
> for report in reports:
> row = []
> row.append(report.report_number);
> row.append(report.report_description);
> row.append(report.notes_other);
> row.append(report.reporter_name);
> allrows.append(row)
> # setup CSV export
> response = HttpResponse(mimetype='text/csv')
> filename = "%s-%s.csv" % ('Daily-reports', 
> datetime.datetime.now().strftime('%Y-%m-%d'))
> response['Content-Disposition'] = 'attachment; filename=%s' % filename
> writer = UnicodeWriter(response, encoding='utf-8')
> writer.writerow(headerrow)
> for writerow in allrows:
> writer.writerow(writerow)
> return response
>
> csv_unicode.py
>
> import csv, codecs, cStringIOclass UnicodeWriter:
>def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
> # Redirect output to a queue
> self.queue = cStringIO.StringIO()
> self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
> self.stream = f
> self.encoder = codecs.getincrementalencoder(encoding)()
>
> def writerow(self, row):
> self.writer.writerow([unicode(s).encode("utf-8") for s in row])
> # Fetch UTF-8 output from the queue ...
> data = self.queue.getvalue()
> data = data.decode("utf-8")
> # ... and reencode it into the target encoding
> data = self.encoder.encode(data)
> # write to the target stream
> self.stream.write(data)
> # empty queue
> self.queue.truncate(0)
>
> def writerows(self, rows):
> for row in rows:
> self.writerow(row)
>
> The above code is exporting the database data into .csv file.
>
> Problem i am facing is,the exported data like Filename,Description,Notes 
> Others,Reporter Name are exported in separate cell.Will show the output
>  i am getting and required output.
>
> You can see my existing and required format. 
>
> I had attached two format,file name existing_csv is the output file i ma 
> getting,required_csv is the .csv file i am expecting.
>
> Need some ones 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.
For more options, visit https://groups.google.com/groups/opt_out.




multi-object form, objects all of same class

2013-06-19 Thread Radomir Wojcik
So I have been looking at different examples using multi-object forms where 
you bring in objects of different classes. I also looked at formsets but I 
don't think these fit what I want to do.


class Alarm(models.Model):
location = models.ForeignKey(Location, related_name='alarms')
owners = models.ManyToManyField(User, related_name='users')
#active = models.NullBooleanField(default=True, blank=True, null=True)
trigger = models.CharField(max_length=25, blank=False, null=True)
critical_low = models.DecimalField(max_digits=10, decimal_places=3)
critical_high = models.DecimalField(max_digits=10, decimal_places=3)


I want to present the user with a form that allows the user to select 
multiple locations without storing the locations in the one record (avoid 
using many to many relationship).  I want it to create as many alarm 
records as there is locations selected. So if location 1 & 2 is selected, 2 
alarm objects will be crated/saved with the exact  same data for owners, 
trigger and low/high fields.

I'm relatively new to Django and don't know how to approach this.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Having an issue with Minimal File Upload utility

2013-06-19 Thread Matt Lind
My Settings.py:

# Django settings for EqlAnalystToolSet project.


import os, ldap
from django_auth_ldap.config import LDAPSearch, ActiveDirectoryGroupType

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '',  # Or path to database 
file if using sqlite3.
'USER': '',  # Not used with sqlite3.
'PASSWORD': '',  # Not used with sqlite3.
'HOST': '',  # Set to empty string for 
localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for default. 
Not used with sqlite3.
}
}

# AUTH_LDAP settings added by MJL

AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
)

AUTH_LDAP_SERVER_URI = 'ldap://'

AUTH_LDAP_BIND_DN = 
"CN=,CN=Users,DC=,DC=,DC=com"
AUTH_LDAP_BIND_PASSWORD = ''
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=,dc=,dc=com", 
ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)",)
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=,dc=,dc=com", 
ldap.SCOPE_SUBTREE, '(objectClass=group)',)
AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType()
AUTH_LDAP_REQUIRE_GROUP = 
'CN=,CN=Users,DC=,DC=,DC=com'

AUTH_LDAP_USER_ATTR_MAP = {
 "first name": "givenName",
 "last name":  "sn",
 "email":  "mail",
}

# SITE Variables adding by MJL

LOGIN_URL = '/login/'
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))

# Hosts/domain names that are valid for this site; required if DEBUG is 
False
# See https://docs.djangoproject.com/en/1.3/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded 
files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/";, "http://example.com/media/";
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/";
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/";, "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = ')2)@8&pfwo!m!6c3&nlkrr)a0u%%4($hj6srh^xio$e4dyr6+)'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'myproject.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or 
"C:/www/django/templates".
   

reverse function gives me url including server path

2013-06-19 Thread Jiří Kupka
Hi! I have little trouble with reverse function in Django. When I run my 
project as ./manage runserver, everything is just fine - reverse gives me 
url in /page/xxx format. When I run it as apache2 instance using this conf 
file:

Listen 8001


ServerName project.tld
DocumentRoot "/var/www/project"
ErrorLog /var/www/project/error.log
CustomLog /var/www/project/access.log combined

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /var/www/project
PythonDebug Off
PythonPath 
"['/var/www/','/var/www/project','/usr/local/lib/site-packages/django'] 
+ sys.path"



reverse function returns url including server path - 
/var/www/project/page/xxx. It means, reverse returns url in this format: 
http://project.tld/var/www/project/page/xxx. What is interesting, 
 http://project.tld/var/www/project/page/xxx and 
http://project.tld/page/xxx gives me same results, but reverse() returns 
url with "ugly" server path.

Any suggestions how can I fix it?

Thanks,
Jirka

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




reverse funtion gives me url including server path

2013-06-19 Thread Jiří Kupka
Hi! I have little trouble with reverse function in my project. When I run 
it over ./manage runserver, everything is fine - reverse gives me url in 
/page/xx format. When I run my project over apache2 using this conf file:

Listen 8001


ServerName project.tld
DocumentRoot "/var/www/project"
ErrorLog /var/www/project/error.log
CustomLog /var/www/project/access.log combined

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /var/www/project
PythonDebug Off
PythonPath 
"['/var/www/','/var/www/project','/usr/local/lib/site-packages/django'] + 
sys.path"



reverse gives me url in /var/www/project/page/xxx format -> 
http://project.tld/var/www/project/page/xxx. What is interesting, I can 
open http://project.tld/page/xxx and 
http://project.tld/var/www/project/page/xxx and I get same results, but 
reverese function returns "ugly" full path...

Any suggestions, how can I fix it?

Thanks,
Jirka

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: readonly_fields

2013-06-19 Thread Timster
It's all in the documentation:

https://docs.djangoproject.com/en/1.5/ref/forms/widgets/

On Wednesday, June 19, 2013 9:37:41 AM UTC-4, tony gair wrote:
>
> Ah thanks that explains that I'll look into changing the readonly 
> attribute on the widget, is there a list of widgets do you know as some of 
> these are choice fields i.e. non text and non integer fields
>
>
> On Wed, Jun 19, 2013 at 1:26 PM, Timster 
> > wrote:
>
>> Where are you setting that? readonly_fields is for ModelAdmin when you 
>> are working with the admin app.
>>
>> If you want to do it in a normal form, you will need to set readonly 
>> attribute on the widget.
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-users/SEWttelj3h0/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Passing parameters via POST in django 1.5

2013-06-19 Thread o_r
They are not in the url, but in the body. I saw this now:

Changed in Django 1.5: 

Before Django 1.5, HttpRequest.POST contained non-form data.
This means I have to put this in the header:

ContentType: application/x-www-form-urlencoded

Seems that jquery does this for you when you serialize a form, but not 
otherwise.

Thanks anyway!

kl. 16:10:58 UTC+2 onsdag 19. juni 2013 skrev Anderson Borges følgende:
>
> if the parameters are in the URL the correct is request.GET
> https://docs.djangoproject.com/en/dev/ref/request-response/
>
>
> On Wed, Jun 19, 2013 at 8:09 AM, o_r >wrote:
>
>> Hi,
>>
>> We're upgrading our application from 1.3 to 1.5. We have quite a few rest 
>> apis in our application. This used to work in 1.3:
>>
>> Url:
>> /path/to/api
>>
>> Passing parameters in the body like this:
>>
>> &someParamter=someValue&otherParameter=otherValue
>>
>> but it doesn't in 1.5, request.POST is empty in the view. I've tried both 
>> via a restclient and javascript. I can't find any documentation that this 
>> has changed, so what am I missing?
>>
>> Thanks!
>>
>> Odd-R.
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Anderson Dias Borges
> Senior Analyst Developer
>
> Tu cumprirás o desejo do meu coração se eu Te buscar...
> I can't see but I'll take my chances
> To hear You call my name 
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: File wsgi.py identify SO

2013-06-19 Thread Hélio Miranda
ok, thanks for 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: File wsgi.py identify SO

2013-06-19 Thread Gustavo Carneiro
On Wed, Jun 19, 2013 at 3:15 PM, Hélio Miranda  wrote:

> I was trying this:
> *if os.name == 'nt':*
> *sys.path.append('c:/Projectos/Test/') # Windows*
> *else:*
> *sys.path.append('/srv/django/OnPitch/') # other (unix)*
>
> doing so, looking at the link that you send will not give
> *if sys.platform('win32'):*
> *sys.path.append('c:/Projectos/Test/') # Windows*
> *else:*
> *sys.path.append('/srv/django/OnPitch/') # other (unix)*
>

Both sys.platform and os.name are variables, not functions.
 sys.platform('win32') should be sys.platform == 'win32'

As the documentation says, os.name is another way to distinguish the OS,
but os.name is more coarse.  Use whichever suits you best.


> *
> *
> which is correct?
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic." -- Frank Herbert

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: File wsgi.py identify SO

2013-06-19 Thread Hélio Miranda
I was trying this:
*if os.name == 'nt':*
*sys.path.append('c:/Projectos/Test/') # Windows*
*else:*
*sys.path.append('/srv/django/OnPitch/') # other (unix)*

doing so, looking at the link that you send will not give
*if sys.platform('win32'):*
*sys.path.append('c:/Projectos/Test/') # Windows*
*else:*
*sys.path.append('/srv/django/OnPitch/') # other (unix)*
*
*
which is correct?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Passing parameters via POST in django 1.5

2013-06-19 Thread Anderson
if the parameters are in the URL the correct is request.GET
https://docs.djangoproject.com/en/dev/ref/request-response/


On Wed, Jun 19, 2013 at 8:09 AM, o_r  wrote:

> Hi,
>
> We're upgrading our application from 1.3 to 1.5. We have quite a few rest
> apis in our application. This used to work in 1.3:
>
> Url:
> /path/to/api
>
> Passing parameters in the body like this:
>
> &someParamter=someValue&otherParameter=otherValue
>
> but it doesn't in 1.5, request.POST is empty in the view. I've tried both
> via a restclient and javascript. I can't find any documentation that this
> has changed, so what am I missing?
>
> Thanks!
>
> Odd-R.
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Anderson Dias Borges
Senior Analyst Developer

Tu cumprirás o desejo do meu coração se eu Te buscar...
I can't see but I'll take my chances
To hear You call my name

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Passing parameters via POST in django 1.5

2013-06-19 Thread o_r
Hi,

We're upgrading our application from 1.3 to 1.5. We have quite a few rest 
apis in our application. This used to work in 1.3:

Url:
/path/to/api

Passing parameters in the body like this:

&someParamter=someValue&otherParameter=otherValue

but it doesn't in 1.5, request.POST is empty in the view. I've tried both 
via a restclient and javascript. I can't find any documentation that this 
has changed, so what am I missing?

Thanks!

Odd-R.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Having an issue with Minimal File Upload utility

2013-06-19 Thread Matt Lind
I am trying to get this utility to work within my own Django site:

https://github.com/doph/minimal-django-file-upload-example/tree/master/src/for_django_1-3/myproject

I have copied all the appropriate files to where they need to be.  I am on 
django 1.3.7 on Centos 6.4 64Bit.

When I run the list page I get the error:

Caught ImportError while rendering: No module named urls


When I copy the actual project and run it, it works.  When I attempt to add the 
functionality to my site, I get the above error.


Just wondering why a file copy would produce these different results.


Thanks in advance

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: readonly_fields

2013-06-19 Thread tony gair
Ah thanks that explains that I'll look into changing the readonly
attribute on the widget, is there a list of widgets do you know as some of
these are choice fields i.e. non text and non integer fields


On Wed, Jun 19, 2013 at 1:26 PM, Timster  wrote:

> Where are you setting that? readonly_fields is for ModelAdmin when you are
> working with the admin app.
>
> If you want to do it in a normal form, you will need to set readonly
> attribute on the widget.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/SEWttelj3h0/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: File wsgi.py identify SO

2013-06-19 Thread Gustavo Carneiro
On Wed, Jun 19, 2013 at 2:29 PM, Hélio Miranda  wrote:

> Hi
> I wonder if someone can help me.
> My problem is the following:
> in my file wsgi.py django, I wish I could make a condition if OS is
> windows running sys.path.append (...) if linux runs sys.path.append ('...')
>
> Is this possible?
> How do I identify the OS?
>

http://docs.python.org/2/library/sys.html#sys.platform

>  --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic." -- Frank Herbert

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




File wsgi.py identify SO

2013-06-19 Thread Hélio Miranda
Hi
I wonder if someone can help me.
My problem is the following:
in my file wsgi.py django, I wish I could make a condition if OS is windows 
running sys.path.append (...) if linux runs sys.path.append ('...')

Is this possible?
How do I identify the OS?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: readonly_fields

2013-06-19 Thread Timster
Where are you setting that? readonly_fields is for ModelAdmin when you are 
working with the admin app.

If you want to do it in a normal form, you will need to set readonly 
attribute on the widget.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




readonly_fields

2013-06-19 Thread tony gair

I have tried to use readonly_fields in a form to designate fields that the 
user is not allowed to change.

class Meta 
readonly_fields = [user]
e.g.


However when I show the form the user can edit them.doh, btw I do want 
to display, but not to edit!

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Model Error

2013-06-19 Thread Ange BOUABLE
Hi Legg,

In your TextFile class, the name of your  __unicode__ method is wrong. You
wrote def __unicde__(self): instead of def __unicode__(self):.
I think that's the issue.
 Regards,
**
*Ange Bouablé
06 16 86 92 01*
**
*  *
*"Là où la volonté est grande, les difficultés diminuent"*
*"Le succès c'est d'aller d'échec en échec sans perdre son enthousiasme"*


2013/6/19 Nigel Legg 

> I have been working through the tutorial, "Writing your first Django
> app, part 1", at https://docs.djangoproject.com/en/1.5/intro/tutorial01/.
> I have the following model code:
>
> from django.db import models
> import datetime
> from django.utils import timezone
>
> class TextFile(models.Model):
> tfile = models.CharField(max_length = 50)
> filetype = models.CharField(max_length = 50)
> up_date = models.DateTimeField('date_uploaded')
>
> def __unicde__(self):
> return self.tfile
>
> def was_uploaded_recently(self):
> return self.up_date>= timezone.now() - datetme.timedelta(days=1)
>
> class Bitext_upd(models.Model):
> tFile = models.ForeignKey(TextFile)
> bitext_file = models.CharField(max_length = 50)
> Bit_up_date = models.DateTimeField('date_analysed')
>
> def __unicode__(self):
> return self.bitext_file
>
> However in the shell I am still getting:
> >>> from apilink.models import TextFile
> >>> TextFile.object.all()
> [, ]
>
> ... when there are two files added.
> In the admin interface, I have a list of two "TextFile objects" (see
> image), if I edit them I can see the details.
>
> I am a bit lost as to where the error is, can anyone help?
> Many thanks.
>
>Regards,
> Nigel Legg
> 07914 740972
> http://twitter.com/nigellegg
> http://uk.linkedin.com/in/nigellegg
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problem when creating a form for adding users to groups

2013-06-19 Thread Derek
I think the problem is that you are using queries which are in the form:
(id = some_list_of_items)
and you cannot do that.  Have a look at the "_in" syntax:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#in

(That whole document is very useful one to read and understand; as making 
queries is at the heart of interacting with your data.)

On Tuesday, 18 June 2013 12:56:48 UTC+2, Lucas Lins wrote:
>
> Hi. 
> I ran into a problem and have searched the group, in the official django 
> and the internet and could not solve the problem.
> I created a form that lists all the groups created and all user 
> created and this adds form users within groups.
> Already tried two ways and both give error
>
>
> form.py
>
> class alterar_usuario(forms.Form):
>  Usuario = forms.ModelMultipleChoiceField(queryset= User.objects.all() )
> Grupo = forms.ModelMultipleChoiceField(queryset = Group.objects.all())
>
>
> (way 1)
> view.py
>
> def cadastrarUsuarioGrupo(request):
>
> if request.method == "POST":   
> form = alterar_usuario(request.POST)
> 
> if form.is_valid():
> Usuario = form.cleaned_data['Usuario']
> Grupo = form.cleaned_data['Grupo']
>
> usuarioOb = User.objects.get(id = Usuario)
> groupOb = Group.objects.get(id = Grupo)
> 
> usuarioOb.groups.add(groupOb)
>
> (way 2)
> view.py
>
> def cadastrarUsuarioGrupo(request):
>
> if request.method == "POST":   
> form = alterar_usuario(request.POST)
> 
> if form.is_valid():
> Usuario = form.cleaned_data['Usuario']
> Grupo = form.cleaned_data['Grupo']
> usuarioOb = User.objects.filter(id = Usuario)
> groupOb = Group.objects.filter(id = Grupo)
> for user, group in usuarioOb, groupOb:
>   user = usuarioOb.user
>   group = grupoOb.groups
>   usuer.groups.add(group)
>
> Grateful.
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Django-Tastypie with mongoengine problem in uploading images to GridFS

2013-06-19 Thread Hélio Miranda
Hi!
I have an application (Django-Tastypie-mongoengine) in which I am uploading 
images to GridFS. With the previous version of tastypie and mongoengine was 
working properly. As I was doing the following to upload:
*def upload (request, id):*
* Movie.objects movie = (id = id)*
*   *
* if request.method == 'POST':*
* my_painting = Movie (id = id)*
*   *
* files = []*
* request.FILES.getlist for f in ('file'):*
*mf = mongoengine.fields.GridFSProxy ()*
*mf.put (f, filename = f.name, legend = 'Hi')*
*files.append (mf)*
*my_painting.MovieCover = files*
* my_painting.save ()*
*
*
* return render_to_response ('upload.html', {},*
*   context_instance = RequestContext (request))
*

The problem is that now I updated to the latest versions, and when I upload 
the images, it deletes all my data, leaving only the images.
Does anyone know why?
What I have to change to get working properly?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: export .csv file from database

2013-06-19 Thread Derek
>From just a quick glance, I have probably missed complex here - but one 
option to try is changing the delimiter from a comma to another character 
(e.g. a semi-colon) - see:
http://docs.python.org/2/library/csv.html#dialects-and-formatting-parameters
(But its also possible that in all the encoding/decoding that is going on, 
that something else is going wrong!)

On Monday, 17 June 2013 17:44:39 UTC+2, roopas...@gmail.com wrote:
>
> views.py
>
> @login_requireddef export_csv(request):
> user = request.user
> # heading columns
> headerrow = ['Filename', 'Description','Notes other','Reporter Name']
> allrows = []
> today = datetime.datetime.today() # default to show today
> reports = Report.objects.filter(user=user)
> reports = reports.filter(created_date_time__year=today.year)
> for report in reports:
> row = []
> row.append(report.report_number);
> row.append(report.report_description);
> row.append(report.notes_other);
> row.append(report.reporter_name);
> allrows.append(row)
> # setup CSV export
> response = HttpResponse(mimetype='text/csv')
> filename = "%s-%s.csv" % ('Daily-reports', 
> datetime.datetime.now().strftime('%Y-%m-%d'))
> response['Content-Disposition'] = 'attachment; filename=%s' % filename
> writer = UnicodeWriter(response, encoding='utf-8')
> writer.writerow(headerrow)
> for writerow in allrows:
> writer.writerow(writerow)
> return response
>
> csv_unicode.py
>
> import csv, codecs, cStringIOclass UnicodeWriter:
>def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
> # Redirect output to a queue
> self.queue = cStringIO.StringIO()
> self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
> self.stream = f
> self.encoder = codecs.getincrementalencoder(encoding)()
>
> def writerow(self, row):
> self.writer.writerow([unicode(s).encode("utf-8") for s in row])
> # Fetch UTF-8 output from the queue ...
> data = self.queue.getvalue()
> data = data.decode("utf-8")
> # ... and reencode it into the target encoding
> data = self.encoder.encode(data)
> # write to the target stream
> self.stream.write(data)
> # empty queue
> self.queue.truncate(0)
>
> def writerows(self, rows):
> for row in rows:
> self.writerow(row)
>
> The above code is exporting the database data into .csv file.
>
> Problem i am facing is,the exported data like Filename,Description,Notes 
> Others,Reporter Name are exported in separate cell.Will show the output
>  i am getting and required output.
>
> You can see my existing and required format. 
>
> I had attached two format,file name existing_csv is the output file i ma 
> getting,required_csv is the .csv file i am expecting.
>
> Need some ones 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.
For more options, visit https://groups.google.com/groups/opt_out.