Duplicate rows with same key in DB?

2012-06-21 Thread ydjango
I have code as

view_a(request):
   Populate my_a, my_b and my_c...
  try:
  tp = TP.objects.get(a__exact = my_a, b__exact = my_b)
  except TP.DoesNotExist, e:
 tp = TP()
 tp.a = my_a
 tp.b = my_b
 tp.c = my_c
 tp.save()
  else:
 tp.c = my_c
 tp.save()

This view is called by ajax calls. TP is a django model and mysql db. 
I am using django 1.1.4/ python2.5/mod_wsgi2.5,

I find that in, one case, two rows with same value of  a and b has been 
created in DB. ( value of c was different)
What could have caused it? 

Any clues or hints on how to track down this problem or what to look for 
will be appreciated.

-- 
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/-/Epx7ZLCqsFgJ.
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: New to DJANGO

2012-06-21 Thread Thomas Lockhart

On 12-06-21 9:37 PM, LJ wrote:
I started out learning Django using the "Writing your first Django 
app" article:

https://docs.djangoproject.com/en/dev/intro/tutorial01/
This is a very well-written tutorial that goes through each part in 
detail.
+1 anyone starting with Django is wasting time if they do not go through 
the tutorial as a first step. They will end up there anyway sooner or 
later...


   - Tom

--
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: New to DJANGO

2012-06-21 Thread LJ
I started out learning Django using the "Writing your first Django app" 
article:
https://docs.djangoproject.com/en/dev/intro/tutorial01/
This is a very well-written tutorial that goes through each part in detail.
Please note, at the bottom of each section there is a link to the next 
section.  There are 3 parts.
Part 2 shows how to create the urls.py.
Part 3 shows how to create the views.py.
I'm sure there are other tutorials out there, but I haven't seen any that 
are better for getting started.
There are also some good books out there that have examples.  You could get 
used books for pretty cheap on Amazon, or even get a free trial to use 
Safari for 30 days:
http://my.safaribooksonline.com/

On Thursday, June 21, 2012 5:52:52 PM UTC-6, Jeff Silverman wrote:
>
> I am new to Django.  I am trying to get the Class version of hello_world 
> to work.  I cannot find a good full example of the code that works.  I have 
> made multiple view.py files and urls.py files trying to get it to work.  I 
> cannot seem to come up with the right url to pass the variables name and 
> times in.  I am using soaplib among other libraries.  Pretty much trying 
> anything I find.
>
> Can anyone point out a full urls.py, views.py and url combination that 
> works?  Ultimately, I want to use the wsdl to expose the funtions to NINTEX 
> workflows.
>
> Any thing will be helpful.
>

-- 
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/-/q__g7pPSgZ8J.
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.



New to DJANGO

2012-06-21 Thread Jeff Silverman
I am new to Django.  I am trying to get the Class version of hello_world to 
work.  I cannot find a good full example of the code that works.  I have 
made multiple view.py files and urls.py files trying to get it to work.  I 
cannot seem to come up with the right url to pass the variables name and 
times in.  I am using soaplib among other libraries.  Pretty much trying 
anything I find.

Can anyone point out a full urls.py, views.py and url combination that 
works?  Ultimately, I want to use the wsdl to expose the funtions to NINTEX 
workflows.

Any thing will be helpful.

-- 
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/-/PwzmG27ruy8J.
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: Returning JSON error when catching Django exception

2012-06-21 Thread Oleg Korsak
I'm not sure, but there must be a 404 template :)
22.06.2012 0:24 пользователь "Taras_96"  написал:

> Ok - I'm pretty sure that I should be returning 500s. Is there any way of
> catching 404s and returning a JSON response for them as well?
>
>
> On Friday, 22 June 2012 00:08:39 UTC+10, Kurtis wrote:
>>
>> I'm not sure if returning a response is any different in middleware than
>> it would be in a normal view. In that case:
>>
>> return HttpResponse(json_data, mimetype="application/json")
>>
>>
>> On Thu, Jun 21, 2012 at 6:54 AM, Taras_96  wrote:
>>
>>> Does anyone have opinions on the best way of having middleware catch
>>> exceptions, and instead of rendering the error into a HTML template, to
>>> return a JSON object? Currently I have the middleware below that catches
>>> exceptions, and if it can find an extra user error message, puts that onto
>>> the request (that the template then picks up).
>>>
>>> class ExceptionUserErrorMessageMiddl**eware(object):
>>> def process_exception(self, request, exception):
>>> """ if the exception has information relevant to the user, then
>>> tack that onto the request object"""
>>>
>>> theFormat = djrequest.get_getvar(request, settings.FORMAT_PARAM, "")
>>> msg = getMessage(exception)
>>> if msg:
>>> setattr(request, USER_ERROR_MESSAGE_ATTR, msg)
>>>
>>> if theFormat == "json":
>>> print "do something"
>>>
>>> What's the best way of returning a json object here? Should I set any
>>> additional headers?
>>>
>>> Is there a way of doing the same for exceptional circumstances that
>>> don't pass through middleware (I'm pretty sure 404 doesn't, are there any
>>> others)?
>>>
>>> --
>>> 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/-/**EtPHiu7SIB8J
>>> .
>>> 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 view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/UCB_k6uqsMcJ.
> 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.



What happens underneath when I save to a model with ManyToMany relationships?

2012-06-21 Thread LJ
I have a Python script that will be called daily from a scheduled service 
or daemon.
The script uses MySQLdb to read a csv file and import data into a MySQL 
database that is used in my Django application.
Some of the models contain ManyToMany relationships.  I am directly 
inserting the relationships.
I thought that this was working great until I tried to query the models 
from my Django view.
For example, I have a list of students, and each student has one or more 
parents.  Even though the students_student_parents table that stores the 
student/parent relationship is updated by the script, when I run the query 
to get a list of parents, the list is empty.

importedStudent = get_object_or_404(Student, pk=studentId)
logger.info(importedStudent)
the_parents = importedStudent.parents.all().values_list('id', 
flat=True)

It appears that I have one of two choices:
1) Figure out what really happens under the covers when I add a parent to a 
student in a Django form and call save() or save_m2m().
2) Instead of inserting data into my tables using MySQLdb cursor execute 
methods, would it be better for me to create a service in my Django 
application that my script can call?

Any suggestions?  

-- 
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/-/mjJFBffN-ZcJ.
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: I need something to help with.

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Hi Oladipupo,

It's always great to see people wanting to get involved.

There are plenty of 'easy pickings' tickets on the Django tickets queue..
or if you don't have enough time/energy to do code contributions, then you
could assist users with problems on the mailing list, or contribute to
discussions on django-developers.

I also suffered from the same problem for the last year, lack of time meant
I was unable to contribute much.. so now I've put some time aside each day
to just help people out on the mailing lists.. it's not much, but every
little helps!

Cal

On Wed, Jun 20, 2012 at 1:48 PM, Oladipupo Elegbede <
dipo.elegb...@dipoelegbede.com> wrote:

> Hello everyone,
>
> I have been away from the group for sometime now. This is due to the
> nature of my current job sadly.
>
> My first love is programming and it is in Python and by extension, django.
>
> While it is true that my current engagement takes almost all of my time, I
> have a strong feeling that my coding abilities are dying off; if this
> happens, I am as good as dead.
>
> By this mail, I am appealing to you all in whatever way to help keep me
> alive.
>
> Kindly help with some tasks here and there as a way of helping me get back
> on track. I would be available atleast 2 hours everyday to attend to tasks
> as this would avail me a learning opportunity and maybe help someone too.
>
> I am not a professional but can work my way around pythonic stuff even if
> it is not the most elegant solution.
>
> I look forward to getting responses.
>
> Thanks for keeping the oxygen mask glued to my face.
>
> --
> 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: Monitoring cache usage?

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Oh also - I'm not entire sure it's possible to break down hits based on key
prefix, at least easily.

You might be able to analyse each one of the data slabs/pages/chunks, see
which keys are inside, and relate that back to the number of hits against
it.

The following article goes into more detail:
http://www.mikeperham.com/2009/06/22/slabs-pages-chunks-and-memcached/

On Wed, Jun 20, 2012 at 4:53 PM, Roy Smith  wrote:

> What tools exist to monitor django's cache usage?  I'd like to see things
> like number of keys stored, total amount of memory used, hit rates broken
> down by key prefix, that sort of thing.
>
> We're using django.core.cache.backends.memcached.MemcachedCache.
>
> ---
> Roy Smith
> r...@panix.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: Monitoring cache usage?

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
A quick search on Google found the following:

https://github.com/dlrust/python-memcached-stats
https://developers.google.com/appengine/docs/python/memcache/clientclass
http://code.google.com/p/memcache-top/
http://www.mysqlperformanceblog.com/2008/11/26/a-quick-way-to-get-memcached-status/


If you use Cacti, you could also use this:

http://forums.cacti.net/about14605.html

There are also other commercial services that will monitor this for you,
such as Server Density.

Cal

On Wed, Jun 20, 2012 at 4:53 PM, Roy Smith  wrote:

> What tools exist to monitor django's cache usage?  I'd like to see things
> like number of keys stored, total amount of memory used, hit rates broken
> down by key prefix, that sort of thing.
>
> We're using django.core.cache.backends.memcached.MemcachedCache.
>
> ---
> Roy Smith
> r...@panix.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: Monitoring memory usage of an external component

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Depending on the web application server you use, this can usually restrict
the memory limit for you - uWSGI is a fine example of this.

You can also use the 'poor mans' memory checks by checking the resident
memory usage (not sure what that func is in Java), and checking if its over
a certain limit.. if it is, then you execute some code. This is a pretty
ghetto approach though ;/

You can also do it externally with a process checker, but again that's
really designed for shared hosting providers to stop abuse and run away
threads.

Hope this helps

Cal

On Wed, Jun 20, 2012 at 5:00 PM, Marcin Tustin wrote:

> Not strictly a django question, but one I hope someone else here might
> have faced.
>
> I have an a site which depends on a java web service (of my own creation).
> This seems to leak memory like a sieve, because of the various libraries
> involved. This is a problem because my host sets a limit on the total usage
> of memory by all of my processes.
>
> *Does anyone here use a tool to monitor memory usage by individual
> processes (or groups thereof), and run commands when certain levels are met?
> * I'd like to kill and restart my java service (through supervisor) when
> it gets above a certain size.
>
> (I know about JVM memory options. These are not really effective for my
> needs).
>
> --
> Marcin Tustin
> Tel: 07773 787 105
>
>  --
> 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: strftime

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Hi Armagan,

I would suggest investigating what the 'date' variable contains..

You can do this by doing:
print type(date)
print dir(date)
print date

I'd also recommend going back through your code and seeing how the date
object is instantiated.

For future reference, you do really need to provide more info in the future
to get any sort of assistance.

There's some great tips and advice on what information is useful to provide
here:
https://code.djangoproject.com/wiki/UsingTheMailingList

Cal

On Thu, Jun 21, 2012 at 9:47 AM, armagan  wrote:

> Hi,
>
> I'm trying to show the date in rss with this function
>
> def item_pubdate(self, item):
>
> date = item.delivery_date
>
> return date.strftime("%d/%m/%y")
>
> But I have an error  'str' object has no attribute 'tzinfo'.
>
> Can you help me? How I code the function?
>
> --
> 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/-/xE87Vj40cLQJ.
> 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: New to Django, need help starting

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
+1

Personally, I'd really recommend having virtualbox/vmware instance running
the same stack as your production environment (i.e. the env where you are
going to deploy code to) so you can ensure no horrible sys lib bugs kick in
(lxml is a pain for this!!). But if this is too much to start with, then a
virtualenv alone is still sufficient.

And like Kurtis mentioned - having a clear separation between your host
machine and your dev environment really is going to save you a lot of
headaches.

On Wed, Jun 20, 2012 at 4:07 PM, Kurtis Mullins wrote:

> Try "easy_install django" or "pip install django".
>
> Really, though -- I recommend going with a combination of Mac Brew (or
> ports or whatever third-party distribution) to install Python and pip then
> install virtualenv and virtualenvwrapper to create a virtual environment,
> then inside of the virtual environment, install Django and your
> MySQL-Python (or whatever database driver you need)
>
> It *sounds* like a lot of work but it will make things considerably easier
> for you in the long run.
>
> If not, just download django (from git) and then run its setup.py and you
> should be all good to go with runserver and sqlite
>
>
> On Wed, Jun 20, 2012 at 9:19 AM, Harjot Mann wrote:
>
>> do one thing open ur terminal and run the following command
>> python
>> then u will get
>> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
>> [GCC 4.5.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> then type
>> >>> import  django
>> >>> print django.get_version()
>> if you have version 1.4 then it will print 1.4
>> It is just a verification that ur django is installed or not.
>>
>>
>> On Wed, Jun 20, 2012 at 5:23 PM, Diego pascual lopez 
>> wrote:
>>
>>>
>>>
>>> On Wed, Jun 20, 2012 at 1:49 PM, kenneth gonsalves <
>>> law...@thenilgiris.com> wrote:
>>>
 On Wed, 2012-06-20 at 13:15 +0200, Diego pascual lopez wrote:
 > > try typing /path_to_django/bin/django-admin.py startproject
 > >
 >
 > If you don't know the path of the django-admin.py, you can type
 >
 > #which django-admin.py

 it will say 'no django-admin.py'

>>>
>>> Yes, you have reason.
>>>
>>> Sorry.
>>>
>>> --
 regards
 Kenneth Gonsalves

 --
 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 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 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: Installing Django @ Shared Host

2012-06-21 Thread Cal Leeming [Simplicity Media Ltd]
Unless they provide some sort of SaaS service where they take care of
deployment for you, then you need shell access. There are plenty of Django
friendly shared hosts if you are not comfortable deploying your own stack
on a dedi/colo/IaaS cloud - see previous threads on this topic.

Personal advice - don't go with dreamhost... we had the misfortune of
migrating our legacy customer apps from one of their crashed slices.. and
the stupidly random timeouts and stack problems that were intermittent and
impossible to debug.. not a fun experience.

Also, Python 2.5 is almost 6 years old now, and Django doesn't officially
even support 2.5 any more.. you should consider moving to 2.6.6 as a
minimum.

Hope this helps

Cal

On Thu, Jun 21, 2012 at 10:51 PM, Miguel Guirao  wrote:

> Hi all,
>
> I have a hosting service from ApolloHosting.com. I don't have SSH access
> neither unsecure telnet to my account.
> I can FTP into my account. I have Python 2.5.
> I'm under Linux.
>
> Is there a way I could install django under these circunstances??
>
> Best Regards,
>
> Miguel Guirao
>
> --
> 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/-/EyZwRUMFIy8J.
> 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.



Installing Django @ Shared Host

2012-06-21 Thread Miguel Guirao
Hi all,

I have a hosting service from ApolloHosting.com. I don't have SSH access 
neither unsecure telnet to my account.
I can FTP into my account. I have Python 2.5.
I'm under Linux.

Is there a way I could install django under these circunstances??

Best Regards,

Miguel Guirao

-- 
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/-/EyZwRUMFIy8J.
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 the last modified datetime from a DateTimeField

2012-06-21 Thread Jesus Noland
I was always getting the date when the model was last modified when using 
'm.date'

On Thursday, June 21, 2012 2:35:02 PM UTC-7, Jesus Noland wrote:
>
> Thank you very much. I am understand now. Sorry it took so long to reply 
> back.
>

-- 
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/-/d2WWYjd36joJ.
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 the last modified datetime from a DateTimeField

2012-06-21 Thread Jesus Noland
Thank you very much. I am understand now. Sorry it took so long to reply 
back.

-- 
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/-/7l1BiweMkwUJ.
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: Returning JSON error when catching Django exception

2012-06-21 Thread Taras_96
Ok - I'm pretty sure that I should be returning 500s. Is there any way of 
catching 404s and returning a JSON response for them as well?


On Friday, 22 June 2012 00:08:39 UTC+10, Kurtis wrote:
>
> I'm not sure if returning a response is any different in middleware than 
> it would be in a normal view. In that case:
>
> return HttpResponse(json_data, mimetype="application/json")
>
>
> On Thu, Jun 21, 2012 at 6:54 AM, Taras_96  wrote:
>
>> Does anyone have opinions on the best way of having middleware catch 
>> exceptions, and instead of rendering the error into a HTML template, to 
>> return a JSON object? Currently I have the middleware below that catches 
>> exceptions, and if it can find an extra user error message, puts that onto 
>> the request (that the template then picks up).
>>
>> class ExceptionUserErrorMessageMiddleware(object):
>> def process_exception(self, request, exception):
>> """ if the exception has information relevant to the user, then 
>> tack that onto the request object"""
>>
>> theFormat = djrequest.get_getvar(request, settings.FORMAT_PARAM, "")
>> msg = getMessage(exception)
>> if msg:
>> setattr(request, USER_ERROR_MESSAGE_ATTR, msg)
>>
>> if theFormat == "json":
>> print "do something"
>>
>> What's the best way of returning a json object here? Should I set any 
>> additional headers?
>>
>> Is there a way of doing the same for exceptional circumstances that don't 
>> pass through middleware (I'm pretty sure 404 doesn't, are there any others)?
>>  
>> -- 
>> 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/-/EtPHiu7SIB8J.
>> 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/-/UCB_k6uqsMcJ.
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.



Messages framework not including tags

2012-06-21 Thread bax...@gretschpages.com
I've read the 
docs: https://docs.djangoproject.com/en/1.3/ref/contrib/messages/

I have the MessageMiddleware in place.

I have the SessionMiddleware in place (before MessageMiddleware)

django.contrib.messages.context_processors.messages in in the context 
processors

django.contrib.messages in in installed apps.

Template has the standard messages code:

{% if messages %}

{% for message in messages %}
{{ message 
}}
{% endfor %}

{% endif %}


I'm getting the message(s), but there is no tag associated. What am I missing?

-- 
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/-/9pd8I94-CYMJ.
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.



Saving ManyToMany models

2012-06-21 Thread LJ
I am having trouble saving entities to my models that have ManyToMany 
relationships.
I have a Student object that inherits from a Person:

class Person(models.Model):
first_name = models.CharField(max_length=30)
middle_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30)
...

class Student(Person):
parents = models.ManyToManyField('parents.Parent', blank=True, 
null=True)
...

class Parent(Person):
occupation = models.CharField(max_length=128, blank=True)

In my view, I create a new Student:

newStudent = Student(first_name='Donald',
middle_name='R', last_name='Duck')
newStudent.save()

I also create a Parent and add the new parent to the list of parents for 
the student:

newParent = Parent(first_name='Ronald',
middle_name='T', last_name='Duck')
newParent.save()
newStudent.parents.add(newParent)

However, when I call save_m2m(), it throws an error:
newStudent.save_m2m()

Perhaps I do not need to call save_m2m().  Does the relationship get saved 
to the database when I call the add() method?

LJ



-- 
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/-/JmC8fj_cvtQJ.
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: New to Django, need help starting

2012-06-21 Thread Christopher Downard
It's useful to use virtualenv despite a slight learning curve. I didn't do
that at first and now I'm going back and using virtualenv now because I've
learned that the version of Django does matter depending on what you want
to do and it's easier to be able to isolate versions.

i.e. Django1.4 doesn't play nicely with Django-CMS.

On Wed, Jun 20, 2012 at 9:07 AM, Kurtis Mullins wrote:

> Try "easy_install django" or "pip install django".
>
> Really, though -- I recommend going with a combination of Mac Brew (or
> ports or whatever third-party distribution) to install Python and pip then
> install virtualenv and virtualenvwrapper to create a virtual environment,
> then inside of the virtual environment, install Django and your
> MySQL-Python (or whatever database driver you need)
>
> It *sounds* like a lot of work but it will make things considerably easier
> for you in the long run.
>
> If not, just download django (from git) and then run its setup.py and you
> should be all good to go with runserver and sqlite
>
>
> On Wed, Jun 20, 2012 at 9:19 AM, Harjot Mann wrote:
>
>> do one thing open ur terminal and run the following command
>> python
>> then u will get
>> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
>> [GCC 4.5.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> then type
>> >>> import  django
>> >>> print django.get_version()
>> if you have version 1.4 then it will print 1.4
>> It is just a verification that ur django is installed or not.
>>
>>
>> On Wed, Jun 20, 2012 at 5:23 PM, Diego pascual lopez 
>> wrote:
>>
>>>
>>>
>>> On Wed, Jun 20, 2012 at 1:49 PM, kenneth gonsalves <
>>> law...@thenilgiris.com> wrote:
>>>
 On Wed, 2012-06-20 at 13:15 +0200, Diego pascual lopez wrote:
 > > try typing /path_to_django/bin/django-admin.py startproject
 > >
 >
 > If you don't know the path of the django-admin.py, you can type
 >
 > #which django-admin.py

 it will say 'no django-admin.py'

>>>
>>> Yes, you have reason.
>>>
>>> Sorry.
>>>
>>> --
 regards
 Kenneth Gonsalves

 --
 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 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.
>



-- 

Christopher Downard

**

*Software Engineer*

Blue Sun Technologies

E-Mail: ch...@bluesuntechnologies.com

Mobile: 720-434-9792

www.bluesuntechnologies.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.



Re: Oracle: blank, null, and empty_strings_allowed

2012-06-21 Thread Ian
On Thursday, June 21, 2012 4:37:35 AM UTC-6, Melvyn Sopacua wrote:
>
> Which is /exactly/ why I mention it. If the default value is inserted 
> instead of an empty string, you can pre-insert the default value and 
> have it linked to an invalid entry. Any attempts to insert the default 
> value on the primary key of the linked model will trigger an integrity 
> error. Any models referencing the pre-inserted "invalid key" can now be 
> identified and relinked properly. 
>

Then all your application logic and views have to be written to ignore the 
invalid entry.  It seems a lot simpler and less error-prone to just tweak 
the DDL to add a "NOT NULL" constraint.

-- 
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/-/9dWmb4ori3EJ.
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: Oracle: blank, null, and empty_strings_allowed

2012-06-21 Thread Ian
On Wednesday, June 20, 2012 1:38:45 PM UTC-6, André Pang wrote:
>
> 1. In Oracle's case, what if you have a model with a primary key that's 
> a CharField?  I suspect that Oracle backend will coerce that to be 
> null=True, so now you have a primary key field that could have NULL. 
>

Primary keys are an exceptions.  The backend doesn't try to make them 
nullable, and the database wouldn't accept that as valid DDL anyway. 

-- 
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/-/iw79PrC-CZsJ.
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: Custom model field as foreign key

2012-06-21 Thread Melvyn Sopacua
On 20-6-2012 19:38, Melvyn Sopacua wrote:
> On 19-6-2012 17:02, Kurtis Mullins wrote:
>> hmm, maybe you need a custom Select Widget for your custom field? Or check
>> out the select widget and see if it's looking for any _meta information on
>> the field that determines how the widget is displayed.
> 
> I traced this down to the ModelForm() getting passed an 'instance' dict
> that has the database representation for the primary key stored as the
> value. And now trying to figure out where that dictionary gets made.

Ok, found the issue, ticket created:
https://code.djangoproject.com/ticket/18501

-- 
Melvyn Sopacua

-- 
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: Returning JSON error when catching Django exception

2012-06-21 Thread Kurtis Mullins
I'm not sure if returning a response is any different in middleware than it
would be in a normal view. In that case:

return HttpResponse(json_data, mimetype="application/json")


On Thu, Jun 21, 2012 at 6:54 AM, Taras_96  wrote:

> Does anyone have opinions on the best way of having middleware catch
> exceptions, and instead of rendering the error into a HTML template, to
> return a JSON object? Currently I have the middleware below that catches
> exceptions, and if it can find an extra user error message, puts that onto
> the request (that the template then picks up).
>
> class ExceptionUserErrorMessageMiddleware(object):
> def process_exception(self, request, exception):
> """ if the exception has information relevant to the user, then
> tack that onto the request object"""
>
> theFormat = djrequest.get_getvar(request, settings.FORMAT_PARAM, "")
> msg = getMessage(exception)
> if msg:
> setattr(request, USER_ERROR_MESSAGE_ATTR, msg)
>
> if theFormat == "json":
> print "do something"
>
> What's the best way of returning a json object here? Should I set any
> additional headers?
>
> Is there a way of doing the same for exceptional circumstances that don't
> pass through middleware (I'm pretty sure 404 doesn't, are there any others)?
>
> --
> 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/-/EtPHiu7SIB8J.
> 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: Our thanks/acknowledgments for Django

2012-06-21 Thread Kurtis Mullins
Very nice Cal!

On Wed, Jun 20, 2012 at 9:59 PM, Daniel Sokolowski wrote:

>  Impressive and it more than does satisfy my curiosity; in this industry I
> find the moment you start doing custom code it's hard to estimate -
> especially on the larger projects.  Super thanks
>
>
> On 20/06/2012 20:11, Cal Leeming [Simplicity Media Ltd] wrote:
>
> Sure - I've no problem sharing!
>
>  The majority of the work went into building the billing system, customer
> control panel, integrating into our interconnect providers API, storing
> CDRs, call rate groups etc - this was around 80-100 hours.
>
>  However the front end (which you can see) took around 40-50 hours - all
> content is generated from an inventory database which maintains the costs
> for line items (such as extensions), call rates, handsets and package
> costs, this means no template changes are required if there is a pricing
> change.
>
>  The handsets page was done from scratch (although the content was
> copied) - which took a total of approx 5 hours. This involved finding good
> high res/clear pictures of each handset, and doing custom slicing for each
> one - so you have that nice zoom effect when you view the item. It could be
> made better with animation, but it's a good start.
>
>  There is also a nice little rates look up tool which is able to do
> partial prefix matching, and a markup system which lets you apply global
> markup rates, and individual rate markups (this means you don't have to
> spend 937549554 hours manually maintaining rates tables - very handy) -
> that took about 5 hours to get completely integrated.
>
>  I should also note that we have lots of existing code snippets and
> libraries that we'd collected and tweaked over the years, so we saved about
> 30 hours in re-using code.
>
>  I'll probably do a full write up sometime during the year and go into
> more detail, but hope this satisfies curiosity!
>
>  Cal
>
> On Thu, Jun 21, 2012 at 12:20 AM, Daniel Sokolowski wrote:
>
>>  Hi Cal, thank you for sharing and congratulations, I do something very
>> similar on my sites but call it a credits page - it is a great place to be
>> putting SEO backlinks. On related note would you be willing to share total
>> turn around time / hour spent for the site you launched ? And would you
>> classify the project as small, medium, or large.
>>
>>
>>
>> On 20/06/2012 17:14, Cal Leeming [Simplicity Media Ltd] wrote:
>>
>>  Hi all,
>>
>>  Last week we released a new site into the wild - sadly I haven't had
>> much time to contribute to tickets, or even support on the mailing list -
>> so felt it was about time I started showing our appreciation for Django and
>> its community.
>>
>>  Therefore we created an acknowledgements section on the site - with the
>> following:
>>
>>  ---
>> Django Framework is a high-level Python Web framework that encourages
>> rapid development and clean, pragmatic design. With highly skilled core
>> developers, an amazing community of contributors, and more features than
>> you can shake a stick at - Django makes the impossible, possible.
>>
>> We cannot stress enough how thankful we are to everyone involved with the
>> on-going development and support of Django Framework - we would not be here
>> if it wasn't for the hard work put in by the community.
>> ---
>>
>> We also added a little bit on Roberto at uWSGI, as he's really doing a
>> great job:
>>
>> ---
>> uWSGI is a high performance web application server that really is a work
>> of art. Our thanks and appreciation goes out to Roberto at unbit.it for
>> single-handedly keeping the project alive and kicking - and for providing
>> emergency support in our times of need.
>> ---
>>
>> I wanted to be a bit more creative and make something really special,
>> like a hand drawn picture of our logo, a heart and the Django/uwsgi logo -
>> but sadly ran out of time at the weekend :/ I'm going to see about getting
>> this same thing done on all our client sites too, but need to wait for
>> approval.
>>
>>  Either way - I think it would be great to see more people doing the
>> same thing.
>>
>>  Snippet taken from: http://www.voiceflare.co.uk/ack
>>
>>  Cal
>>  --
>> 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.
>>
>>
>>
>> --
>> Daniel Sokolowski
>> Web Engineer
>> Danols Web Engineeringhttp://webdesign.danols.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

Stuck with a dynamic form within formwizard

2012-06-21 Thread het.oosten
On Django 1.2.3 i am trying to get a dynamic form working. On the
first page a user have to give their address/client id and on the
second page customers can order dishes for catering.

To dynamically add forms on the second page i use
http://code.google.com/p/django-dynamic-formset/

Here is my models.py:

*
class Catering(models.Model):
customer_id = models.CharField(max_length=20)
company = models.CharField(max_length=40)

class DishesForm(forms.Form):
gerecht = fields.CharField(max_length=200)
aantal = fields.IntegerField(required=False)

DishesFormset = formsets.formset_factory(DishesForm)

class TestWizard(FormWizard):
def done(self, request, form_list):
return render_to_response('testwizard', {
'form_data': [form.cleaned_data for form in
form_list],
})
*

urls.py:

*
(r'^testwizard/$', TestWizard([CateringForm, DishesFormset])),
*

The problem i have is that in the template I can only call the
complete form with {{form}} . In order to get the javascript working
properly I need to call the fields seperately like {{form.gerecht}}


When i test the dynamic form (DishesFormset) seperately without the
formwizard everything works fine.

How do i call the seperate formfields within the formwizard?


-- 
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: cad application

2012-06-21 Thread Jani Tiainen

21.6.2012 14:40, Satvir Toor kirjoitti:

can we make cad applications through the django??? If any one know
about a link  where i can find such information just tell me.  I could
not find any information regarding it.



Of course it is possible, though it all depends what you mean by "cad 
application" and what's your goal.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

--
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: cad application

2012-06-21 Thread Marcin Tustin
Which parts of a CAD application, exactly, do you think Django might be
helpful with? It could certainly provide an interface to a storage backend.

On Thu, Jun 21, 2012 at 7:40 AM, Satvir Toor wrote:

> can we make cad applications through the django??? If any one know
> about a link  where i can find such information just tell me.  I could
> not find any information regarding it.
>
> --
> Satvir Kaur
> satveerkaur.blogspot.in
>
> --
> 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.
>
>


-- 
Marcin Tustin
Tel: 07773 787 105

-- 
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.



cad application

2012-06-21 Thread Satvir Toor
can we make cad applications through the django??? If any one know
about a link  where i can find such information just tell me.  I could
not find any information regarding it.

-- 
Satvir Kaur
satveerkaur.blogspot.in

-- 
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: Time zone (Django 1.4) questions

2012-06-21 Thread Aymeric Augustin
Hi Klaas,

Le mardi 12 juin 2012 13:13:14 UTC+2, Klaas van Schelven a écrit :
>
> 1] Migration of non-UTC to UTC: is there any script / best practice 
> available? 
>
Django's documentation mentions that all data should be converted to UTC 
> when switching to USE_TZ=True. See: 
> https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#other-databases
> This is a rather concise remark. Are there any scripts/tricks available to 
> do this in "one go", and to be able to easily do the same conversion in 
> development and production.
>

I assume it's possible to walk through all models and look for 
DateTimeFields, then perform the conversion. However performance must be 
taken into account — your database may not like large updates, and handling 
of special cases too. As you know, conversions from naive local time to UTC 
may fail (during the autumn DST transition).

I haven't written that script and I don't know anyone else who has. No 
promises, but since you need it, I may find the motivation to write it.

2] The meaning of Queryset filtering: am I correct to understand that 
> operations on the DB are now always interpreted in UTC?
> I.e. any direct comparisons to datetime? But also the __month __year 
> quasi-fields?
> This does not appear to be documented explicitly anywhere, at least not in 
> the queryset documentation itself.
> And should we not consider this a bug since a naive use of these is 
> explained in almost every single Django beginners toturial?
>

Yes, operations performed within the DB itself are in UTC, and as a 
consequence __day, __month, __year probably don't do what you expect when 
USE_TZ = True.

The most recent state of my thoughts on this problem is here: 
https://code.djangoproject.com/ticket/17260#comment:14
 

> 3] Since date and datetime are radically different concepts (respectively 
> a point in time and a calendaring concept) what is the meaning of
> auto_now and auto_now_add on a DateField? Is the current Timezone or the 
> default Timezone used? Should this not be documented?
>

The behavior hasn't changed, which means the default time zone is used.

Specifically, the implementation calls `datetime.date.today()`, which 
relies on the process' time zone. Under Linux it's defined by the TZ 
environment variable, which is set to settings.TIME_ZONE. Under Windows I 
think it's always the system time zone.

Generally speaking, the current implementation of auto_now and auto_now_add 
has some issues. For instance QuerySet.update() won't change the value of a 
field with auto_now=True. Therefore, I strongly recommend using 
`default=timezone.now` or a custom save() function, as it is more 
predictable.

Best regards,

-- 
Aymeric.

-- 
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/-/9PufMWWjvhwJ.
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: django.test HTTP/XMLRPC Testing with use of settings.TEST_DATABASE_NAME

2012-06-21 Thread Елена Платонова
Hello. Perhaps you need to use LiveServerTestCase, but it appears only in 
Django 1.4. 
https://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#django.test.LiveServerTestCase

четверг, 26 февраля 2009 г., 17:54:25 UTC+4 пользователь x_O написал:
>
> Hi 
>
> Recently I'm trying to write tests for almost every thing in my code. 
> Including HTTP and XMLRPC requests. 
>
> from django.test import TestCase 
>
> class XmlRpcCase(TestCase): 
> def setUp(self): 
> self.xmlrpc = xmlrpclib.ServerProxy("http://127.0.0.1:8000/ 
> store/xmlrpc ") 
>
> def testCreate(self): 
> case = dict(name='case_name') 
>  self.xmlrpc.Case.create(case) 
> self.assertEquals(Case.objects.count(), 1) 
>
> Right now test will use a DATABASE_NAME to create a case object by 
> XMLRPC request, and after that will use in assertion 
> TEST_DATABASE_NAME. So the result will be always failed. 
>
> Any ideas for some smart solution for this kind of cases. 
>
> x_O 
>

-- 
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/-/MIDIf3XIzlAJ.
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.



Returning JSON error when catching Django exception

2012-06-21 Thread Taras_96


Does anyone have opinions on the best way of having middleware catch 
exceptions, and instead of rendering the error into a HTML template, to 
return a JSON object? Currently I have the middleware below that catches 
exceptions, and if it can find an extra user error message, puts that onto 
the request (that the template then picks up).

class ExceptionUserErrorMessageMiddleware(object):
def process_exception(self, request, exception):
""" if the exception has information relevant to the user, then 
tack that onto the request object"""

theFormat = djrequest.get_getvar(request, settings.FORMAT_PARAM, "")
msg = getMessage(exception)
if msg:
setattr(request, USER_ERROR_MESSAGE_ATTR, msg)

if theFormat == "json":
print "do something"

What's the best way of returning a json object here? Should I set any 
additional headers?

Is there a way of doing the same for exceptional circumstances that don't 
pass through middleware (I'm pretty sure 404 doesn't, are there any others)?

-- 
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/-/EtPHiu7SIB8J.
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: Oracle: blank, null, and empty_strings_allowed

2012-06-21 Thread Melvyn Sopacua
On 20-6-2012 21:38, André Pang wrote:
> On 6/20/2012 11:46 AM, Melvyn Sopacua wrote:
> 
>> On 20-6-2012 20:31, André Pang wrote:
>>> Right. There's currently no way to enforce required=True at the database
>>> level.
>>
>> So, your model clearly defines that it doesn't allow empty values, yet
>> some were inserted? Can you pull this out of the abstract with an
>> example?
> 
> There's no way for a model to disallow empty values, AFAIK.  The example
> I have resembles this:
> 
>   class Foo(models.Model):
>   my_field = models.CharField(null=False, blank=True)
> 
> In Oracle's case, the null=False (which is the default) is ignored and
> always coerced to null=True, which means that empty strings are allowed.
>  (I'm not sure what the behavior is for other databases; I guess it
> depends on whether the backend regards NULL == '' or not.)

Isn't your problem here that Blank=True? It should be False if you don't
want empty strings.
Also, it don't matter for the application for this example, since the
difference between NULL and '' is only valid for unique keys, since NULL
values are not subject to constraints.

> Since blank=True is an admin thing only, and required=True is an
> attribute of a form and not a model, any non-form or non-admin code that
> creates a model can insert an empty string into the database.

Isn't this what you're looking for?


This isn't tied to forms, you just need to call the validation methods
and though I'm not in a position to check it right now, I'm pretty sure
that when blank=False is set on the model, validation will fail.

>> I think a more worthwhile solution is to have the default value for a
>> field be propagated to the database as default value. In that case,
>> empty strings on NOT NULL columns will be consistent.
> 
> In our case, there is no sensible default value for the field; e.g. what
> if the field's a ForeignKey or a primary key[1]?

Which is /exactly/ why I mention it. If the default value is inserted
instead of an empty string, you can pre-insert the default value and
have it linked to an invalid entry. Any attempts to insert the default
value on the primary key of the linked model will trigger an integrity
error. Any models referencing the pre-inserted "invalid key" can now be
identified and relinked properly.
-- 
Melvyn Sopacua

-- 
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: strftime

2012-06-21 Thread robin nanola
i think i would be better if you  read python datetime docs

http://docs.python.org/library/datetime.html#datetime.date.strftime

On Thu, Jun 21, 2012 at 4:47 PM, armagan  wrote:

> Hi,
>
> I'm trying to show the date in rss with this function
>
> def item_pubdate(self, item):
>
> date = item.delivery_date
>
> return date.strftime("%d/%m/%y")
>
> But I have an error  'str' object has no attribute 'tzinfo'.
>
> Can you help me? How I code the function?
>
> --
> 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/-/xE87Vj40cLQJ.
> 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: setting up new django project

2012-06-21 Thread Harjot Mann
you can use both methods.If you are getting a permission denied error by
giving full path,
then you have to change the permissions by using following command:

sudo chmod +x /usr/local/bin/django-admin.py

but its not necessary to give the whole path, infact the alternate method
is easier.

In most unix-like systems django is found in site packages
but in python2.6 and python2.7 django is found in dist packages
On Thu, Jun 21, 2012 at 2:26 PM, Gelonida N  wrote:

> On 05/28/2012 04:53 AM, xaegis wrote:
>
>> Hello, this is my first time posting to a list!
>>  I am running python 2.7 with django 1.4 installed on Ubuntu 12.04
>> I am having trouble creating new projects with django. Whenever I use
>> the command:
>> Code:
>>
>> sudo /usr/local/lib/python2.7/dist-**packages/django/bin/django-**
>> admin.py
>> startproject cms
>>
>> I get errors or permission denied messages but if I use:
>> Code:
>>
>>
> Just one other comment.
>
> Are you really sure, that you want to create a Django project with root
> privileges?
>
> This is rather unusual.
>
> Why do you want to do this?
>
>
> --
> 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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: setting up new django project

2012-06-21 Thread Gelonida N

On 05/28/2012 04:53 AM, xaegis wrote:

Hello, this is my first time posting to a list!
  I am running python 2.7 with django 1.4 installed on Ubuntu 12.04
I am having trouble creating new projects with django. Whenever I use
the command:
Code:

sudo /usr/local/lib/python2.7/dist-packages/django/bin/django-admin.py
startproject cms

I get errors or permission denied messages but if I use:
Code:



Just one other comment.

Are you really sure, that you want to create a Django project with root 
privileges?


This is rather unusual.

Why do you want to do this?

--
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.



strftime

2012-06-21 Thread armagan
Hi,

I'm trying to show the date in rss with this function

def item_pubdate(self, item):

date = item.delivery_date

return date.strftime("%d/%m/%y")

But I have an error  'str' object has no attribute 'tzinfo'.

Can you help me? How I code the function?

-- 
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/-/xE87Vj40cLQJ.
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.