Re: run manage.py commands within app

2014-03-23 Thread Lachlan Musicman
I use cron and a script - but would love to hear other methods as well.

Notes: Need to add virtualenv to PATH:

crontab -e

SHELL=/bin/bash
PATH=/home/erp/.virtualenvs/prod/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

#
# m h  dom mon dow   command
0 * * * * cd /home/www/prod/erp/ && python manage.py update_index
--settings=erp.settings.production >> /tmp/cronupdate.log 2>&1 &&
python manage.py build_solr_schema --filename=schema.xml
--settings=erp.settings.production >> /tmp/cronbuild.log 2>&1 && cp
schema.xml /opt/solr/erp/conf/



On 24 March 2014 10:46, judy wawira  wrote:
> Hello I have a django app using haystack and a solr backend to power
> searches
>
> There is dynamic addition of data and wonder if there are other ways to
> automatically rebuild the solr index without manually going to the command
> line to run manage.py rebuild_index
>
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7a8c9a7f-b15c-4d4e-9b43-cc54c977f125%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
>From this perspective it is natural that anarchism be marked by
spontaneity, differentiation, and experimentation that it be marked by
an expressed affinity with chaos, if chaos is understood to be what
lies outside or beyond the dominant game or system. Because of the
resistance to definition and categorisation, the anarchist principle
has been variously interpreted as, rather than an articulated
position, “a moral attitude, an emotional climate, or even a mood”.
This mood hangs in dramatic tension between utopian hope or dystopian
nihilism...
-
http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiN%2B-N-gjbZU37pRZK719cuABHqtBS7w-805FGa4T7Q3cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


run manage.py commands within app

2014-03-23 Thread judy wawira
Hello I have a django app using haystack and a solr backend to power 
searches

There is dynamic addition of data and wonder if there are other ways to 
automatically rebuild the solr index without manually going to the command 
line to run manage.py rebuild_index

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a8c9a7f-b15c-4d4e-9b43-cc54c977f125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model validation across relationships

2014-03-23 Thread Simon Charette
I'd say that's exactly what you should use `Model.clean()` for. In this 
case you're *doing validation that requires access to more than a single 
field.*

What sounds vague to you in the documentation?

Le vendredi 21 mars 2014 19:43:07 UTC-4, Joshua Pokotilow a écrit :
>
> Given these models, would UserProfile.clean() make sense as written?
>
> class PhoneNumber(models.Model):
> user = models.ForeignKey(User, related_name='phone_numbers')
> phone_number = models.CharField(max_length=20)
>
> class UserProfile(models.Model):
> user = models.OneToOneField(User)
> sms_notifications_enabled = models.BooleanField(default=False)
>
> # Given these models / fields, does this implementation make sense?
> def clean(self):
> if self.sms_notifications_enabled:
> if not self.user.phone_numbers.exists():
> raise ValidationError("SMS notifications cannot be enabled 
> because this user has no phone number")
>
> I *think* it’s OK, but the documentation for Model.clean() seems somewhat 
> vague about what sorts of checks one may implement. Specifically, it says, 
> “This method should be used to provide custom model validation, and to 
> modify attributes on your model if desired. For instance, you could use it 
> to automatically provide a value for a field, or to do validation that 
> requires access to more than a single field.”
>
> Is the above code in line with best practices?
>

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


[OT] How to get rid of caching completely

2014-03-23 Thread Mrinmoy Das
Hi,

This is a totally off topic question but is there a way to stop caching at
all level?

I have added

*expires -1;*
*add_header Cache-Control "private, must-revalidate, max-age=0";*
*add_header Last-Modified "";*

this on my nginx server block, but there are still some caching are
happening.  Any way to get rid of that completely. :)

Mrinmoy Das
http://goromlagche.in/

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


Re: Django and Long Polling

2014-03-23 Thread Kakar Nyori
You mean requesting db in the given time?


On Sun, Mar 23, 2014 at 8:50 AM, Venkatraman S  wrote:

> Why not use (async)callbacks?
>
> -V
>
>
> On Sun, Mar 23, 2014 at 1:11 AM, Robin Lery  wrote:
>
>> Hello,
>> I need to implement long polling in my application to retrieve the
>> events. But I have no idea how to do it. I know the concept of long
>> polling, i.e to leave the connection open, until an event occurs. But how
>> do I do implement this in my project. If you could give me a simple long
>> polling example of client side and the views i guess, I would really
>> appreciate.
>>
>> Thank you!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2B4-nGpvKHcMg-mMRbf7%2BVceCAkRwipt_8NvojEw43ALhC2YBw%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAN7tdFQKUvNQ69NA_K58R1tz2R_HW2eE%2BvwrFr-7hqVRUDO8tg%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B8oko%2Bc2VGkb4Wu%2Bd-ko2_ROyD1xROjvUyYWW_QHKMNK9K_AQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: loaddata not looking for natural keys

2014-03-23 Thread bobhaugen
Ok, now I am really confused.

Here's the code where the error originates in 
django/core/serializers/python.py:

   # Handle FK fields
elif field.rel and isinstance(field.rel, models.ManyToOneRel):
if field_value is not None:
import pdb; pdb.set_trace()
if hasattr(field.rel.to._default_manager, 
'get_by_natural_key'):
if hasattr(field_value, '__iter__'):
obj = 
field.rel.to._default_manager.db_manager(db).get_by_natural_key(*field_value)
value = getattr(obj, field.rel.field_name)
# If this is a natural foreign key to an object 
that
# has a FK/O2O as the foreign key, use the FK 
value
if field.rel.to._meta.pk.rel:
value = value.pk
else:
value = 
field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
data[field.attname] = value
else:
data[field.attname] = 
field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
else:
data[field.attname] = None



Here's what pdb says:

(Pdb) p field

(Pdb) p field_value
u'Cash Contribution'
(Pdb) p hasattr(field.rel.to._default_manager, 'get_by_natural_key')
True
(Pdb) n
> 
/home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/core/serializers/python.py(109)Deserializer()
-> if hasattr(field_value, '__iter__'):
(Pdb) p hasattr(field_value, '__iter__')
False
(Pdb) p field_value
u'Cash Contribution'
(Pdb) p type(field_value)

(Pdb) n
> 
/home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/core/serializers/python.py(117)Deserializer()
-> value = 
field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
(Pdb) n
ValidationError: Validati...teger."])
> 
/home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/core/serializers/python.py(117)Deserializer()
-> value = 
field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)


I thought unicode fields had iterators? But here's one in ipython:

In [15]: field_value = u'Cash Contribution'

In [16]: field_value.__iter__()
---
AttributeErrorTraceback (most recent call last)

/home/bob/.virtualenvs/vn2/valuenetwork/ in ()

AttributeError: 'unicode' object has no attribute '__iter__'







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