Re: Question has mediated relation to the Django.

2016-07-22 Thread Derek
I don't know how to do this in "raw" Python; but my view is that the Python 
universe is full of very smart programmers who have wrapped their knowledge 
into libraries for you to use - so why not make use of them, rather than 
reinventing the wheel yourself?

In short:

https://pythonhosted.org/PyPDF2/PdfFileReader.html#PyPDF2.PdfFileReader.getNumPage


On Thursday, 21 July 2016 16:14:00 UTC+2, Seti Volkylany wrote:
>
> How get a total count pages in PDF file, created with using ReportLab, 
> without third-party apps and hardcode (or violation DRY)?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/721e0ed2-ac13-4a56-9c4a-7ecffa966ba3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate django user queryset with group names

2016-07-22 Thread Todor Velichkov
This is actually a pretty good solution and I totally forgot about it! 

It will help people for sure!

On Saturday, July 23, 2016 at 1:29:42 AM UTC+3, mishbah wrote:
>
> While I was waiting for suggestions, I did some more research learnt about 
> django Conditional Expressions.
>
> Docs: 
> https://docs.djangoproject.com/en/1.9/ref/models/conditional-expressions/
>
> from django.contrib.auth.models import User
> from django.db.models import BooleanField
> from django.db.models import When, Case, Value
>
>
> query = When(groups__name__in=[CUSTOMER_GROUP_NAME, ], then=Value(1))
> qs2 = User.objects.annotate(
> is_customer=Case(query, default=Value(0), 
> output_field=BooleanField()))
>
>
> Posting it here.. someone else may find it helpful. 
>
> On Friday, 22 July 2016 22:02:09 UTC+1, mishbah wrote:
>>
>> You are awesome! Thank you!
>>
>> On Friday, 22 July 2016 21:41:58 UTC+1, Todor Velichkov wrote:
>>>
>>> Hello, I don't think sub-classing `Func` would be appropriate here. A 
>>> much easier way would be to use `RawSQL 
>>> 
>>> `
>>>
>>> since you want to dynamically check for different group you could write 
>>> a factory method to build `RawSQLs` for you, something like:
>>>
>>> from django.db.models import BooleanField
>>> from django.db.models.expressions import RawSQL
>>>
>>> def build_has_group_raw_sql(group_name):
>>> return RawSQL("""EXISTS(
>>> SELECT 1 FROM `auth_group` 
>>> WHERE `auth_group`.`name` = %s 
>>> AND `auth_group`.`id` IN (
>>> SELECT `auth_user_groups`.`group_id` 
>>> FROM `auth_user_groups` 
>>> WHERE `auth_user_groups`.`user_id` = `auth_user`.`id`
>>> )
>>> )""", (group_name,), output_field=BooleanField())
>>>
>>> Now you can use this function as follows:
>>>
>>> User.objects.all().annotate(is_customer=build_has_group_raw_sql(
>>> 'customer'))
>>>
>>>
>>> On Friday, July 22, 2016 at 7:01:08 PM UTC+3, mishbah wrote:

 Given that I have a django model that has a ForeignKey that is linked 
 to itself.

 class DjangoModel():
 
 [...]

 successor = models.ForeignKey('self', null=True)

 I was able to write a custom django database function like this:

 from django.db.models import BooleanField
 from django.db.models import Func


 class IsNull(Func):
 """
 See docs: 
 https://docs.djangoproject.com/en/1.8/ref/models/database-functions/
 """
 template = '%(expressions)s IS NULL'

 def __init__(self, *args, **kwargs):
 kwargs['output_field'] = BooleanField()
 super(IsNull, self).__init__(*args, **kwargs)

 So I can do this:

 queryset = DjangoModel.objects.all()
 queryset = queryset.annotate(**{'is_latest': IsNull('successor')})

 and if use `queryset.values()` .. I get

 [{'pk': 1, is_latest': True}, {'pk': 2, 'is_latest': False}, ]

 where `is_latest == True` when `successor` field is NULL for an object.

 Now I want to do something similar, but have no idea where to start!

 The bundled `django.contrib.auth.models.User` has a ManyToMany 
 relations to `django.contrib.auth.models.Group` model

 For my project, there are multiple user group types, e.g customer / 
 marketing / finance etc

 What I want to do.. is annotate a `User` queryset with `is_FOO` field 
 where `FOO` is a group name. e.g `is_customer` or `is_marketing`

 So if I use `.values()` on a queryset, I should get something like this:

 [{'pk': 1, 'is_customer': True, 'is_marketing': False }, {'pk': 1, 
 'is_customer': True, 'is_marketing': True }]

 The group name could be hardcoded, e.g

 queryset.annotate(**{'is_customer': IsGroupMember('customer')}) 

 I just need help with the `IsGroupMember` database function!

 Is that even possible? Any hints or tips to get me started?

 Any help will be genuinely appreciated.  Many 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c05e64d-6d00-4bdc-8d8e-c9dbf340e38c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate django user queryset with group names

2016-07-22 Thread mishbah
While I was waiting for suggestions, I did some more research learnt about 
django Conditional Expressions.

Docs: 
https://docs.djangoproject.com/en/1.9/ref/models/conditional-expressions/

from django.contrib.auth.models import User
from django.db.models import BooleanField
from django.db.models import When, Case, Value


query = When(groups__name__in=[CUSTOMER_GROUP_NAME, ], then=Value(1))
qs2 = User.objects.annotate(
is_customer=Case(query, default=Value(0), 
output_field=BooleanField()))


Posting it here.. someone else may find it helpful. 

On Friday, 22 July 2016 22:02:09 UTC+1, mishbah wrote:
>
> You are awesome! Thank you!
>
> On Friday, 22 July 2016 21:41:58 UTC+1, Todor Velichkov wrote:
>>
>> Hello, I don't think sub-classing `Func` would be appropriate here. A 
>> much easier way would be to use `RawSQL 
>> 
>> `
>>
>> since you want to dynamically check for different group you could write a 
>> factory method to build `RawSQLs` for you, something like:
>>
>> from django.db.models import BooleanField
>> from django.db.models.expressions import RawSQL
>>
>> def build_has_group_raw_sql(group_name):
>> return RawSQL("""EXISTS(
>> SELECT 1 FROM `auth_group` 
>> WHERE `auth_group`.`name` = %s 
>> AND `auth_group`.`id` IN (
>> SELECT `auth_user_groups`.`group_id` 
>> FROM `auth_user_groups` 
>> WHERE `auth_user_groups`.`user_id` = `auth_user`.`id`
>> )
>> )""", (group_name,), output_field=BooleanField())
>>
>> Now you can use this function as follows:
>>
>> User.objects.all().annotate(is_customer=build_has_group_raw_sql(
>> 'customer'))
>>
>>
>> On Friday, July 22, 2016 at 7:01:08 PM UTC+3, mishbah wrote:
>>>
>>> Given that I have a django model that has a ForeignKey that is linked to 
>>> itself.
>>>
>>> class DjangoModel():
>>> 
>>> [...]
>>>
>>> successor = models.ForeignKey('self', null=True)
>>>
>>> I was able to write a custom django database function like this:
>>>
>>> from django.db.models import BooleanField
>>> from django.db.models import Func
>>>
>>>
>>> class IsNull(Func):
>>> """
>>> See docs: 
>>> https://docs.djangoproject.com/en/1.8/ref/models/database-functions/
>>> """
>>> template = '%(expressions)s IS NULL'
>>>
>>> def __init__(self, *args, **kwargs):
>>> kwargs['output_field'] = BooleanField()
>>> super(IsNull, self).__init__(*args, **kwargs)
>>>
>>> So I can do this:
>>>
>>> queryset = DjangoModel.objects.all()
>>> queryset = queryset.annotate(**{'is_latest': IsNull('successor')})
>>>
>>> and if use `queryset.values()` .. I get
>>>
>>> [{'pk': 1, is_latest': True}, {'pk': 2, 'is_latest': False}, ]
>>>
>>> where `is_latest == True` when `successor` field is NULL for an object.
>>>
>>> Now I want to do something similar, but have no idea where to start!
>>>
>>> The bundled `django.contrib.auth.models.User` has a ManyToMany relations 
>>> to `django.contrib.auth.models.Group` model
>>>
>>> For my project, there are multiple user group types, e.g customer / 
>>> marketing / finance etc
>>>
>>> What I want to do.. is annotate a `User` queryset with `is_FOO` field 
>>> where `FOO` is a group name. e.g `is_customer` or `is_marketing`
>>>
>>> So if I use `.values()` on a queryset, I should get something like this:
>>>
>>> [{'pk': 1, 'is_customer': True, 'is_marketing': False }, {'pk': 1, 
>>> 'is_customer': True, 'is_marketing': True }]
>>>
>>> The group name could be hardcoded, e.g
>>>
>>> queryset.annotate(**{'is_customer': IsGroupMember('customer')}) 
>>>
>>> I just need help with the `IsGroupMember` database function!
>>>
>>> Is that even possible? Any hints or tips to get me started?
>>>
>>> Any help will be genuinely appreciated.  Many 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9573f60e-08e0-4c4b-a8e4-0fd7453cfb8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate on related field

2016-07-22 Thread Todor Velichkov
By "retrieving the matching tags" you mean fetching `Tag` objects?

Well I guess what you can do is to use `prefetch_related 
` 
with custom `Prefetch 
`
 
object.

blogs = Blog.objects.prefetch_related(
models.Prefetch('tags',
queryset=Tag.objects.filter(name__in=['python', 'java'])
to_attr='my_tags' 
)
)

#usage
for blog in blogs:
print blog.my_tags



On Tuesday, July 12, 2016 at 2:28:30 PM UTC+3, Ramashish Baranwal wrote:
>
> Hi,
>
> I have the following model definitions:
>
> class Tag(models.Model):
> name = models.CharField(max_length=16)
>
> class Blog(models.Model):
> name = models.CharField(max_length=16)
> tags = models.ManyToManyField(Tag, blank=True)
>
>
>
> I want to select blogs with more than one tags. Here is what I am doing 
> (for two tags)-
>
> # select blogs for python and java
> blogs = Blog.objects.filter(tags__name='python').filter(tags__name='java')
>
>
>
> This INNER joins Tag with Blog twice, each time filtering on the given 
> name. This works well. Now I want to retrieve the matching tags. If it were 
> a single join, I would have done-
>
> blogs = blogs.annotate(tag=F('tags__name'))
>
> Doing this still works, but only retrieves the last tag. How do I retrieve 
> the tag name for each join, giving them different names? Something like-
>
> # Below should give tag1 = 'python', tag2 = 'java'
> blogs = blogs.annotate(tag1=?, tag2=?)
>
> Thanks,
> Ramashish
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e148c289-6f10-4f6d-a892-8b31f85a3887%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate django user queryset with group names

2016-07-22 Thread mishbah
You are awesome! Thank you!

On Friday, 22 July 2016 21:41:58 UTC+1, Todor Velichkov wrote:
>
> Hello, I don't think sub-classing `Func` would be appropriate here. A much 
> easier way would be to use `RawSQL 
> 
> `
>
> since you want to dynamically check for different group you could write a 
> factory method to build `RawSQLs` for you, something like:
>
> from django.db.models import BooleanField
> from django.db.models.expressions import RawSQL
>
> def build_has_group_raw_sql(group_name):
> return RawSQL("""EXISTS(
> SELECT 1 FROM `auth_group` 
> WHERE `auth_group`.`name` = %s 
> AND `auth_group`.`id` IN (
> SELECT `auth_user_groups`.`group_id` 
> FROM `auth_user_groups` 
> WHERE `auth_user_groups`.`user_id` = `auth_user`.`id`
> )
> )""", (group_name,), output_field=BooleanField())
>
> Now you can use this function as follows:
>
> User.objects.all().annotate(is_customer=build_has_group_raw_sql('customer'
> ))
>
>
> On Friday, July 22, 2016 at 7:01:08 PM UTC+3, mishbah wrote:
>>
>> Given that I have a django model that has a ForeignKey that is linked to 
>> itself.
>>
>> class DjangoModel():
>> 
>> [...]
>>
>> successor = models.ForeignKey('self', null=True)
>>
>> I was able to write a custom django database function like this:
>>
>> from django.db.models import BooleanField
>> from django.db.models import Func
>>
>>
>> class IsNull(Func):
>> """
>> See docs: 
>> https://docs.djangoproject.com/en/1.8/ref/models/database-functions/
>> """
>> template = '%(expressions)s IS NULL'
>>
>> def __init__(self, *args, **kwargs):
>> kwargs['output_field'] = BooleanField()
>> super(IsNull, self).__init__(*args, **kwargs)
>>
>> So I can do this:
>>
>> queryset = DjangoModel.objects.all()
>> queryset = queryset.annotate(**{'is_latest': IsNull('successor')})
>>
>> and if use `queryset.values()` .. I get
>>
>> [{'pk': 1, is_latest': True}, {'pk': 2, 'is_latest': False}, ]
>>
>> where `is_latest == True` when `successor` field is NULL for an object.
>>
>> Now I want to do something similar, but have no idea where to start!
>>
>> The bundled `django.contrib.auth.models.User` has a ManyToMany relations 
>> to `django.contrib.auth.models.Group` model
>>
>> For my project, there are multiple user group types, e.g customer / 
>> marketing / finance etc
>>
>> What I want to do.. is annotate a `User` queryset with `is_FOO` field 
>> where `FOO` is a group name. e.g `is_customer` or `is_marketing`
>>
>> So if I use `.values()` on a queryset, I should get something like this:
>>
>> [{'pk': 1, 'is_customer': True, 'is_marketing': False }, {'pk': 1, 
>> 'is_customer': True, 'is_marketing': True }]
>>
>> The group name could be hardcoded, e.g
>>
>> queryset.annotate(**{'is_customer': IsGroupMember('customer')}) 
>>
>> I just need help with the `IsGroupMember` database function!
>>
>> Is that even possible? Any hints or tips to get me started?
>>
>> Any help will be genuinely appreciated.  Many 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eacf185a-b1ed-4e05-af84-1bd58626c775%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Annotate django user queryset with group names

2016-07-22 Thread Todor Velichkov
Hello, I don't think sub-classing `Func` would be appropriate here. A much 
easier way would be to use `RawSQL 

`

since you want to dynamically check for different group you could write a 
factory method to build `RawSQLs` for you, something like:

from django.db.models import BooleanField
from django.db.models.expressions import RawSQL

def build_has_group_raw_sql(group_name):
return RawSQL("""EXISTS(
SELECT 1 FROM `auth_group` 
WHERE `auth_group`.`name` = %s 
AND `auth_group`.`id` IN (
SELECT `auth_user_groups`.`group_id` 
FROM `auth_user_groups` 
WHERE `auth_user_groups`.`user_id` = `auth_user`.`id`
)
)""", (group_name,), output_field=BooleanField())

Now you can use this function as follows:

User.objects.all().annotate(is_customer=build_has_group_raw_sql('customer'))


On Friday, July 22, 2016 at 7:01:08 PM UTC+3, mishbah wrote:
>
> Given that I have a django model that has a ForeignKey that is linked to 
> itself.
>
> class DjangoModel():
> 
> [...]
>
> successor = models.ForeignKey('self', null=True)
>
> I was able to write a custom django database function like this:
>
> from django.db.models import BooleanField
> from django.db.models import Func
>
>
> class IsNull(Func):
> """
> See docs: 
> https://docs.djangoproject.com/en/1.8/ref/models/database-functions/
> """
> template = '%(expressions)s IS NULL'
>
> def __init__(self, *args, **kwargs):
> kwargs['output_field'] = BooleanField()
> super(IsNull, self).__init__(*args, **kwargs)
>
> So I can do this:
>
> queryset = DjangoModel.objects.all()
> queryset = queryset.annotate(**{'is_latest': IsNull('successor')})
>
> and if use `queryset.values()` .. I get
>
> [{'pk': 1, is_latest': True}, {'pk': 2, 'is_latest': False}, ]
>
> where `is_latest == True` when `successor` field is NULL for an object.
>
> Now I want to do something similar, but have no idea where to start!
>
> The bundled `django.contrib.auth.models.User` has a ManyToMany relations 
> to `django.contrib.auth.models.Group` model
>
> For my project, there are multiple user group types, e.g customer / 
> marketing / finance etc
>
> What I want to do.. is annotate a `User` queryset with `is_FOO` field 
> where `FOO` is a group name. e.g `is_customer` or `is_marketing`
>
> So if I use `.values()` on a queryset, I should get something like this:
>
> [{'pk': 1, 'is_customer': True, 'is_marketing': False }, {'pk': 1, 
> 'is_customer': True, 'is_marketing': True }]
>
> The group name could be hardcoded, e.g
>
> queryset.annotate(**{'is_customer': IsGroupMember('customer')}) 
>
> I just need help with the `IsGroupMember` database function!
>
> Is that even possible? Any hints or tips to get me started?
>
> Any help will be genuinely appreciated.  Many 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d07808b2-8cd3-4d02-b07c-ec6545437154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to set up celery in supervisord

2016-07-22 Thread Ankush Thakur
Yes, I guess that's good enough. Thanks for helping out! :-)


Regards,
Ankush Thakur

On Fri, Jul 22, 2016 at 10:54 PM, George Silva 
wrote:

> I'm familiar with the two ways I've explained to you. I'm not sure if
> there are others.
>
> Actually, it's a single place where you have to define the variables (the
> supervisor conf) so I don't think it's that bad.
>
>
>
> On Fri, Jul 22, 2016 at 2:18 PM, Ankush Thakur 
> wrote:
>
>> Unfortunately the docs are anything but beginner-friendly on Celery +
>> Supervisor:
>> http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#supervisord
>> If you follow the link, you land on a GitHub page with three files and no
>> explanations. :(
>>
>> Besides, if you see
>> https://github.com/celery/celery/blob/3.1/extra/supervisord/celeryd.conf,
>> there's no mention of environment variables.
>>
>>
>> Regards,
>> Ankush Thakur
>>
>> On Fri, Jul 22, 2016 at 10:34 PM, George Silva 
>> wrote:
>>
>>> Check the docs. There's plenty of information regarding this.
>>>
>>> It's probably a bad formatted character, misplaced comma or whatever.
>>>
>>> On Fri, Jul 22, 2016 at 1:49 PM, Ankush Thakur <
>>> ankush.thaku...@gmail.com> wrote:
>>>
 Well, setting up the line this way gives me the following error:

 Starting supervisor: Error: Format string
 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
 for 'environment' is badly formatted

 What do you think is badly formatted here?

 Best,
 Ankush


 On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>
> If you are getting variables from the environment, supervisor that
> special environment directive. The variables need to specified in the
> supervisor conf file, such as:
>
> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
> worker --loglevel=INFO
> environment=PYTHONPATH=/home/ankush/jremind/jremind,
> *SECRET_KEY="foo",VARIABLE_A="a"*
> directory=/home/ankush/jremind/jremind
> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
> autostart=true
> autorestart=true
> startsecs=10
> stopwaitsecs=600
>
> Supervisor won't be able to read them otherwise. There are other
> alternatives, for example, if you are using a crafted command, using bash:
>
> command=/home/foo/command.sh
> environment=PYTHONPATH=/home/ankush/jremind/jremind
> directory=/home/ankush/jremind/jremind
> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
> autostart=true
> autorestart=true
> startsecs=10
> stopwaitsecs=600
>
>
> command.sh
>
> !#/bin/bash
>
> export SECRET_KEY="foo"
> export VARIABLE_A="a"
>
> echo $SECRET_KEY
> echo $VARIABLE_A
>
>
> --
> George R. C. Silva
> Sigma Geosistemas LTDA
> 
> http://www.sigmageosistemas.com.br/
>
 --
 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 https://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
 
 .

 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>>>
>>> --
>>> George R. C. Silva
>>> Sigma Geosistemas LTDA
>>> 
>>> http://www.sigmageosistemas.com.br/
>>>
>>> --
>>> 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/0yxoRdSyctA/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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAGyPVTv7X_9Waim0BU7uknipwPAujp5ik7AHSCBmqksRNKaszg%40mail.gmail.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com

Re: Unable to set up celery in supervisord

2016-07-22 Thread George Silva
I'm familiar with the two ways I've explained to you. I'm not sure if there
are others.

Actually, it's a single place where you have to define the variables (the
supervisor conf) so I don't think it's that bad.



On Fri, Jul 22, 2016 at 2:18 PM, Ankush Thakur 
wrote:

> Unfortunately the docs are anything but beginner-friendly on Celery +
> Supervisor:
> http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#supervisord
> If you follow the link, you land on a GitHub page with three files and no
> explanations. :(
>
> Besides, if you see
> https://github.com/celery/celery/blob/3.1/extra/supervisord/celeryd.conf,
> there's no mention of environment variables.
>
>
> Regards,
> Ankush Thakur
>
> On Fri, Jul 22, 2016 at 10:34 PM, George Silva 
> wrote:
>
>> Check the docs. There's plenty of information regarding this.
>>
>> It's probably a bad formatted character, misplaced comma or whatever.
>>
>> On Fri, Jul 22, 2016 at 1:49 PM, Ankush Thakur > > wrote:
>>
>>> Well, setting up the line this way gives me the following error:
>>>
>>> Starting supervisor: Error: Format string
>>> 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
>>> for 'environment' is badly formatted
>>>
>>> What do you think is badly formatted here?
>>>
>>> Best,
>>> Ankush
>>>
>>>
>>> On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:

 If you are getting variables from the environment, supervisor that
 special environment directive. The variables need to specified in the
 supervisor conf file, such as:

 command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
 worker --loglevel=INFO
 environment=PYTHONPATH=/home/ankush/jremind/jremind,
 *SECRET_KEY="foo",VARIABLE_A="a"*
 directory=/home/ankush/jremind/jremind
 stdout_logfile=/home/ankush/jremind/logs/celeryd.log
 stderr_logfile=/home/ankush/jremind/logs/celeryd.log
 autostart=true
 autorestart=true
 startsecs=10
 stopwaitsecs=600

 Supervisor won't be able to read them otherwise. There are other
 alternatives, for example, if you are using a crafted command, using bash:

 command=/home/foo/command.sh
 environment=PYTHONPATH=/home/ankush/jremind/jremind
 directory=/home/ankush/jremind/jremind
 stdout_logfile=/home/ankush/jremind/logs/celeryd.log
 stderr_logfile=/home/ankush/jremind/logs/celeryd.log
 autostart=true
 autorestart=true
 startsecs=10
 stopwaitsecs=600


 command.sh

 !#/bin/bash

 export SECRET_KEY="foo"
 export VARIABLE_A="a"

 echo $SECRET_KEY
 echo $VARIABLE_A


 --
 George R. C. Silva
 Sigma Geosistemas LTDA
 
 http://www.sigmageosistemas.com.br/

>>> --
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> George R. C. Silva
>> Sigma Geosistemas LTDA
>> 
>> http://www.sigmageosistemas.com.br/
>>
>> --
>> 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/0yxoRdSyctA/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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAGyPVTv7X_9Waim0BU7uknipwPAujp5ik7AHSCBmqksRNKaszg%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@googlegr

Re: Unable to set up celery in supervisord

2016-07-22 Thread Ankush Thakur
Unfortunately the docs are anything but beginner-friendly on Celery +
Supervisor:
http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#supervisord
If you follow the link, you land on a GitHub page with three files and no
explanations. :(

Besides, if you see
https://github.com/celery/celery/blob/3.1/extra/supervisord/celeryd.conf,
there's no mention of environment variables.


Regards,
Ankush Thakur

On Fri, Jul 22, 2016 at 10:34 PM, George Silva 
wrote:

> Check the docs. There's plenty of information regarding this.
>
> It's probably a bad formatted character, misplaced comma or whatever.
>
> On Fri, Jul 22, 2016 at 1:49 PM, Ankush Thakur 
> wrote:
>
>> Well, setting up the line this way gives me the following error:
>>
>> Starting supervisor: Error: Format string
>> 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
>> for 'environment' is badly formatted
>>
>> What do you think is badly formatted here?
>>
>> Best,
>> Ankush
>>
>>
>> On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>>>
>>> If you are getting variables from the environment, supervisor that
>>> special environment directive. The variables need to specified in the
>>> supervisor conf file, such as:
>>>
>>> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
>>> worker --loglevel=INFO
>>> environment=PYTHONPATH=/home/ankush/jremind/jremind,
>>> *SECRET_KEY="foo",VARIABLE_A="a"*
>>> directory=/home/ankush/jremind/jremind
>>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>>> autostart=true
>>> autorestart=true
>>> startsecs=10
>>> stopwaitsecs=600
>>>
>>> Supervisor won't be able to read them otherwise. There are other
>>> alternatives, for example, if you are using a crafted command, using bash:
>>>
>>> command=/home/foo/command.sh
>>> environment=PYTHONPATH=/home/ankush/jremind/jremind
>>> directory=/home/ankush/jremind/jremind
>>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>>> autostart=true
>>> autorestart=true
>>> startsecs=10
>>> stopwaitsecs=600
>>>
>>>
>>> command.sh
>>>
>>> !#/bin/bash
>>>
>>> export SECRET_KEY="foo"
>>> export VARIABLE_A="a"
>>>
>>> echo $SECRET_KEY
>>> echo $VARIABLE_A
>>>
>>>
>>> --
>>> George R. C. Silva
>>> Sigma Geosistemas LTDA
>>> 
>>> http://www.sigmageosistemas.com.br/
>>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> George R. C. Silva
> Sigma Geosistemas LTDA
> 
> http://www.sigmageosistemas.com.br/
>
> --
> 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/0yxoRdSyctA/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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGyPVTv7X_9Waim0BU7uknipwPAujp5ik7AHSCBmqksRNKaszg%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALX%3DrK%2BtutoBh3pDMLaH7Xm8MVDf%3DxXgArY7ESWrvniUgsL66w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to set up celery in supervisord

2016-07-22 Thread Ankush Thakur
Wooohooo! That did it. Many thanks! :-) :-) :-)

Umm, but, say, isn't kind of clunky, that I have to copy all the variables
over to the supervisor config? Isn't there a neater way to do it?


Regards,
Ankush Thakur

On Fri, Jul 22, 2016 at 10:21 PM, George Silva 
wrote:

> The secret key contains % chars. Chance them to something else or escape
> them.
>
> Em 22/07/2016 13:49, "Ankush Thakur"  escreveu:
>
>> Well, setting up the line this way gives me the following error:
>>
>> Starting supervisor: Error: Format string
>> 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
>> for 'environment' is badly formatted
>>
>> What do you think is badly formatted here?
>>
>> Best,
>> Ankush
>>
>> On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>>>
>>> If you are getting variables from the environment, supervisor that
>>> special environment directive. The variables need to specified in the
>>> supervisor conf file, such as:
>>>
>>> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
>>> worker --loglevel=INFO
>>> environment=PYTHONPATH=/home/ankush/jremind/jremind,
>>> *SECRET_KEY="foo",VARIABLE_A="a"*
>>> directory=/home/ankush/jremind/jremind
>>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>>> autostart=true
>>> autorestart=true
>>> startsecs=10
>>> stopwaitsecs=600
>>>
>>> Supervisor won't be able to read them otherwise. There are other
>>> alternatives, for example, if you are using a crafted command, using bash:
>>>
>>> command=/home/foo/command.sh
>>> environment=PYTHONPATH=/home/ankush/jremind/jremind
>>> directory=/home/ankush/jremind/jremind
>>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>>> autostart=true
>>> autorestart=true
>>> startsecs=10
>>> stopwaitsecs=600
>>>
>>>
>>> command.sh
>>>
>>> !#/bin/bash
>>>
>>> export SECRET_KEY="foo"
>>> export VARIABLE_A="a"
>>>
>>> echo $SECRET_KEY
>>> echo $VARIABLE_A
>>>
>>>
>>> --
>>> George R. C. Silva
>>> Sigma Geosistemas LTDA
>>> 
>>> http://www.sigmageosistemas.com.br/
>>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/0yxoRdSyctA/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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGyPVTvOfBvbh_Cpz3ZgRb%3DcfQ3K8FuoS5Xi57FjTdO9aCyQ4g%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALX%3DrKLWr%3Dc2X_DEo44na6d7GraVve-6qdAWiP2RrdKOC_idJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to set up celery in supervisord

2016-07-22 Thread George Silva
Check the docs. There's plenty of information regarding this.

It's probably a bad formatted character, misplaced comma or whatever.

On Fri, Jul 22, 2016 at 1:49 PM, Ankush Thakur 
wrote:

> Well, setting up the line this way gives me the following error:
>
> Starting supervisor: Error: Format string
> 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
> for 'environment' is badly formatted
>
> What do you think is badly formatted here?
>
> Best,
> Ankush
>
>
> On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>>
>> If you are getting variables from the environment, supervisor that
>> special environment directive. The variables need to specified in the
>> supervisor conf file, such as:
>>
>> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
>> worker --loglevel=INFO
>> environment=PYTHONPATH=/home/ankush/jremind/jremind,
>> *SECRET_KEY="foo",VARIABLE_A="a"*
>> directory=/home/ankush/jremind/jremind
>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>> autostart=true
>> autorestart=true
>> startsecs=10
>> stopwaitsecs=600
>>
>> Supervisor won't be able to read them otherwise. There are other
>> alternatives, for example, if you are using a crafted command, using bash:
>>
>> command=/home/foo/command.sh
>> environment=PYTHONPATH=/home/ankush/jremind/jremind
>> directory=/home/ankush/jremind/jremind
>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>> autostart=true
>> autorestart=true
>> startsecs=10
>> stopwaitsecs=600
>>
>>
>> command.sh
>>
>> !#/bin/bash
>>
>> export SECRET_KEY="foo"
>> export VARIABLE_A="a"
>>
>> echo $SECRET_KEY
>> echo $VARIABLE_A
>>
>>
>> --
>> George R. C. Silva
>> Sigma Geosistemas LTDA
>> 
>> http://www.sigmageosistemas.com.br/
>>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
George R. C. Silva
Sigma Geosistemas LTDA

http://www.sigmageosistemas.com.br/

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGyPVTv7X_9Waim0BU7uknipwPAujp5ik7AHSCBmqksRNKaszg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to set up celery in supervisord

2016-07-22 Thread George Silva
The secret key contains % chars. Chance them to something else or escape
them.

Em 22/07/2016 13:49, "Ankush Thakur"  escreveu:

> Well, setting up the line this way gives me the following error:
>
> Starting supervisor: Error: Format string
> 'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
> for 'environment' is badly formatted
>
> What do you think is badly formatted here?
>
> Best,
> Ankush
>
> On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>>
>> If you are getting variables from the environment, supervisor that
>> special environment directive. The variables need to specified in the
>> supervisor conf file, such as:
>>
>> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app
>> worker --loglevel=INFO
>> environment=PYTHONPATH=/home/ankush/jremind/jremind,
>> *SECRET_KEY="foo",VARIABLE_A="a"*
>> directory=/home/ankush/jremind/jremind
>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>> autostart=true
>> autorestart=true
>> startsecs=10
>> stopwaitsecs=600
>>
>> Supervisor won't be able to read them otherwise. There are other
>> alternatives, for example, if you are using a crafted command, using bash:
>>
>> command=/home/foo/command.sh
>> environment=PYTHONPATH=/home/ankush/jremind/jremind
>> directory=/home/ankush/jremind/jremind
>> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
>> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
>> autostart=true
>> autorestart=true
>> startsecs=10
>> stopwaitsecs=600
>>
>>
>> command.sh
>>
>> !#/bin/bash
>>
>> export SECRET_KEY="foo"
>> export VARIABLE_A="a"
>>
>> echo $SECRET_KEY
>> echo $VARIABLE_A
>>
>>
>> --
>> George R. C. Silva
>> Sigma Geosistemas LTDA
>> 
>> http://www.sigmageosistemas.com.br/
>>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Unable to set up celery in supervisord

2016-07-22 Thread Ankush Thakur
Well, setting up the line this way gives me the following error:

Starting supervisor: Error: Format string 
'PYTHONPATH=/home/ankush/jremind/jremind,JREMIND_SECRET_KEY="SDFDSF@$%#$%$#TWFDFGFG%^$%ewrw$#%TFRETERTERT$^",JREMIND_DATABASE="jremind",JREMIND_USERNAME="root",JREMIND_PASSWORD="root"'
 
for 'environment' is badly formatted

What do you think is badly formatted here?

Best,
Ankush

On Thursday, July 21, 2016 at 11:51:19 PM UTC+5:30, george wrote:
>
> If you are getting variables from the environment, supervisor that special 
> environment directive. The variables need to specified in the supervisor 
> conf file, such as:
>
> command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app 
> worker --loglevel=INFO
> environment=PYTHONPATH=/home/ankush/jremind/jremind,
> *SECRET_KEY="foo",VARIABLE_A="a"*
> directory=/home/ankush/jremind/jremind
> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
> autostart=true
> autorestart=true
> startsecs=10
> stopwaitsecs=600
>
> Supervisor won't be able to read them otherwise. There are other 
> alternatives, for example, if you are using a crafted command, using bash:
>
> command=/home/foo/command.sh
> environment=PYTHONPATH=/home/ankush/jremind/jremind
> directory=/home/ankush/jremind/jremind
> stdout_logfile=/home/ankush/jremind/logs/celeryd.log
> stderr_logfile=/home/ankush/jremind/logs/celeryd.log
> autostart=true
> autorestart=true
> startsecs=10
> stopwaitsecs=600
>
>
> command.sh
>
> !#/bin/bash
>
> export SECRET_KEY="foo"
> export VARIABLE_A="a"
>
> echo $SECRET_KEY
> echo $VARIABLE_A
>
>
> -- 
> George R. C. Silva
> Sigma Geosistemas LTDA
> 
> http://www.sigmageosistemas.com.br/
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f9639cef-0a04-4982-92b4-9c8a9c5a1158%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Annotate django user queryset with group names

2016-07-22 Thread Mishbah Razzaque
Given that I have a django model that has a ForeignKey that is linked to 
itself.

class DjangoModel():

[...]

successor = models.ForeignKey('self', null=True)

I was able to write a custom django database function like this:

from django.db.models import BooleanField
from django.db.models import Func


class IsNull(Func):
"""
See docs: 
https://docs.djangoproject.com/en/1.8/ref/models/database-functions/
"""
template = '%(expressions)s IS NULL'

def __init__(self, *args, **kwargs):
kwargs['output_field'] = BooleanField()
super(IsNull, self).__init__(*args, **kwargs)

So I can do this:

queryset = DjangoModel.objects.all()
queryset = queryset.annotate(**{'is_latest': IsNull('successor')})

and if use `queryset.values()` .. I get

[{'pk': 1, is_latest': True}, {'pk': 2, 'is_latest': False}, ]

where `is_latest == True` when `successor` field is NULL for an object.

Now I want to do something similar, but have no idea where to start!

The bundled `django.contrib.auth.models.User` has a ManyToMany relations to 
`django.contrib.auth.models.Group` model

For my project, there are multiple user group types, e.g customer / 
marketing / finance etc

What I want to do.. is annotate a `User` queryset with `is_FOO` field where 
`FOO` is a group name. e.g `is_customer` or `is_marketing`

So if I use `.values()` on a queryset, I should get something like this:

[{'pk': 1, 'is_customer': True, 'is_marketing': False }, {'pk': 1, 
'is_customer': True, 'is_marketing': True }]

The group name could be hardcoded, e.g

queryset.annotate(**{'is_customer': IsGroupMember('customer')}) 

I just need help with the `IsGroupMember` database function!

Is that even possible? Any hints or tips to get me started?

Any help will be genuinely appreciated.  Many 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d3fe90a-a4ca-4156-a786-b0a957a48668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic ModelAdmin Field

2016-07-22 Thread Bernat Bonet


El jueves, 14 de julio de 2016, 17:29:38 (UTC+2), Bernat Bonet escribió:
>
> I need to add dynamic fields to ModelAdmin that are not part of the Model.
>
> Models:
>
> product: cod, des
> product_categories: cat, val
>
> I want to add val1, val2 in ProductAdmin
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3f832300-33aa-4b99-8e6c-8ff82550dd59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add a custom language for internationalization/localization

2016-07-22 Thread Sonu Kumar
After lots of debug and digging inside local middleware I have fixed this. 
To solve this I had to add LOCALE_PATH in settings file.

On Friday, July 22, 2016 at 6:41:44 PM UTC+5:30, Sonu Kumar wrote:
>
> Hi there, 
> I would like to add a custom language to support for i18n. You can check 
>  my question here 
> http://stackoverflow.com/questions/38511925/add-custom-language-for-localization-in-django-app.
>  
> I have followed all the steps mentioned here 
> http://stackoverflow.com/questions/19267886/adding-a-custom-language-to-django
> . 
>
> In short, the steps are as follows
> 1. add a custom language(NEW) dictionary to settings file and update 
> LANG_INFO dictionary 
> 2. add new language to LANGUAGES as well for i18n to detect 
> 3. compile message for the new language 
>
> Problem is that when I visit the home page with new language code then it 
> redirects to /en/NEW
>
> Can somebody point out the error or make it working?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62765b9d-8e24-4758-ae11-e8f73b330940%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help debugging static files issue

2016-07-22 Thread 'Ajay M' via Django users
Dear developer,
Please try to setup static files directory in your settings.py file.
It should be a list, like below

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static', 'app'),
os.path.join(BASE_DIR, 'static')
]
Please let me know if you still face this issue.

On Friday, July 22, 2016 at 5:58:57 PM UTC+5:30, jasonwo...@gmail.com wrote:
>
> Hey there!
> Sorry for the bother, but I'm running into some issues dealing with static 
> files for a new site I'm building with Django. I'm new to django, but I 
> swear I went through at least 5 hours of StackOverflow comments and other 
> guides before hitting up this group. Anyway:
>
> # The issue:
> Static files are not being served correctly, even though they are 
> correctly being collected using the `./manage.py collectstatic`, and placed 
> in a `static/` directory under the project root.
>
> # Debugging information
> OS: Ubuntu 16.04 (4.4.0-31-generic)
> Nginx (reverse proxy and serving static file): 1.11.2
> uWSGI (application server): 2.0.13.1
> Django: 1.9.8
>
> # Where my debugging left me
> In my nginx logs I'm finding requests that correctly get through to uWSGI 
> (page returns fine, though without static assets), where going manually to 
> the URI (www.example.com/static/home/global.css) returns a 404 error.
>
> The nginx error log for the request in question:
>
>> [date_stuff] [error] [log_stuff]: *1 open() 
>> "/server/website//static/home/global.css" failed (2: No such 
>> file or directory), client: [redacted], server: [redacted], request: "GET 
>> /static/home/global.css HTTP/2.0", host: "[redacted]", referrer: "
>> https://www.[redacted]";
>>
>
> Some things that I noticed:
> I don't know how, but the request sent to nginx for the global.css asset 
> is trying to get it from 
> `/server/website//static/home/global.css`, instead of 
> `/server/website/static/home/global.css`.
>
> I'm not sure at that point whether it's an nginx problem or a django one, 
> but for some reason the `` is being added, and nginx is 
> trying to fetch the static files from the wrong place.
>
> # Project overview
> Server/<- Located at the root of the machine 
> at /server
>  Vagrantfile
>  db/
>  letsencrypt/
>  nginx/
>  uwsgi/
>  website/<--- Project root
>  /
>  home/   <--- home app
>  manage.py/
>  
>
>  templates/
>  static/
>  admin/
>  home/
>  global.css   <--- collected from the 
> static dir in the `home` app
>
> # /settings.py config:
>
>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>>
>
>> INSTALLED_APPS = [
>> 'django.contrib.admin',
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> 'home',
>> ]
>>
>  
>>
> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': ['templates'],
>> 'APP_DIRS': True,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> 'django.template.context_processors.static',
>> ],
>> },
>> },
>> ]
>>
>  
>>
> STATIC_URL = '/static/'
>> # STATIC_ROOT = os.path.join(BASE_DIR, 'static/')   <-- I've tried 
>> this and just hardcoding
>>
> STATIC_ROOT = '/server/website/static/' 
>>
>
>> # Nginx server config:
>>
> location /static {
> alias /server/website/static; < I've tried this and setting 
> `root /server/website`
>
>
> Cheers and thanks for any help guys (and sorry for the bother on such a 
> beginner question),
> Jason
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f959216-6d33-405a-b3e9-c0de03b602a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Add a custom language for internationalization/localization

2016-07-22 Thread Sonu Kumar
Hi there, 
I would like to add a custom language to support for i18n. You can check 
 my question 
here 
http://stackoverflow.com/questions/38511925/add-custom-language-for-localization-in-django-app.
 
I have followed all the steps mentioned 
here 
http://stackoverflow.com/questions/19267886/adding-a-custom-language-to-django. 

In short, the steps are as follows
1. add a custom language(NEW) dictionary to settings file and update 
LANG_INFO dictionary 
2. add new language to LANGUAGES as well for i18n to detect 
3. compile message for the new language 

Problem is that when I visit the home page with new language code then it 
redirects to /en/NEW

Can somebody point out the error or make it working?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ac797860-0882-4cae-9064-f1e07e60a9c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Help debugging static files issue

2016-07-22 Thread jasonworkchina
Hey there!
Sorry for the bother, but I'm running into some issues dealing with static 
files for a new site I'm building with Django. I'm new to django, but I 
swear I went through at least 5 hours of StackOverflow comments and other 
guides before hitting up this group. Anyway:

# The issue:
Static files are not being served correctly, even though they are correctly 
being collected using the `./manage.py collectstatic`, and placed in a 
`static/` directory under the project root.

# Debugging information
OS: Ubuntu 16.04 (4.4.0-31-generic)
Nginx (reverse proxy and serving static file): 1.11.2
uWSGI (application server): 2.0.13.1
Django: 1.9.8

# Where my debugging left me
In my nginx logs I'm finding requests that correctly get through to uWSGI 
(page returns fine, though without static assets), where going manually to 
the URI (www.example.com/static/home/global.css) returns a 404 error.

The nginx error log for the request in question:

> [date_stuff] [error] [log_stuff]: *1 open() 
> "/server/website//static/home/global.css" failed (2: No such 
> file or directory), client: [redacted], server: [redacted], request: "GET 
> /static/home/global.css HTTP/2.0", host: "[redacted]", referrer: "
> https://www.[redacted]";
>

Some things that I noticed:
I don't know how, but the request sent to nginx for the global.css asset is 
trying to get it from 
`/server/website//static/home/global.css`, instead of 
`/server/website/static/home/global.css`.

I'm not sure at that point whether it's an nginx problem or a django one, 
but for some reason the `` is being added, and nginx is 
trying to fetch the static files from the wrong place.

# Project overview
Server/<- Located at the root of the machine at 
/server
 Vagrantfile
 db/
 letsencrypt/
 nginx/
 uwsgi/
 website/<--- Project root
 /
 home/   <--- home app
 manage.py/
 

 templates/
 static/
 admin/
 home/
 global.css   <--- collected from the 
static dir in the `home` app

# /settings.py config:

> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>

> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'home',
> ]
>
 
>
TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': ['templates'],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> 'django.template.context_processors.static',
> ],
> },
> },
> ]
>
 
>
STATIC_URL = '/static/'
> # STATIC_ROOT = os.path.join(BASE_DIR, 'static/')   <-- I've tried 
> this and just hardcoding
>
STATIC_ROOT = '/server/website/static/' 
>

> # Nginx server config:
>
location /static {
alias /server/website/static; < I've tried this and setting 
`root /server/website`


Cheers and thanks for any help guys (and sorry for the bother on such a 
beginner question),
Jason

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/162af149-2e2b-42f2-a4ee-67dcb7a74da2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django-filer FilerImageField how to use widget outside admin

2016-07-22 Thread Patricia Santos


I want to use the FilerImageFieldin one of my model field and want the user 
to edit outside the admin area but when I try to load it, the widget 
doesn't work correctly and in the browser console I get and error in the 
javascript generated:


Uncaught TypeError: Cannot read property 'jQuery' of undefined


In here:



django.jQuery(document).ready(function(){
var plus = django.jQuery('#add_id_featured_image');
if (plus.length){
plus.remove();
}
// Delete this javascript once loaded to avoid the "add 
new" link duplicates it
django.jQuery('#id_featured_image_javascript').remove();
});



The field in my model is defined like this:


featured_image = FilerImageField(db_column="FEATURED_IMAGE",
 verbose_name=_('Featured Image'),
 related_name='IPP_ARTICLE_FEATURED_IMAGE')


Do you have any idea why I can't use this field widget outside the admin? 
Do I need to set some configuration for this?


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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/684a52b7-276d-49d2-a2f8-9f5b50072f9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is it possible to the ReportLab applying the Django utils function's "localtime" to an all date/datetime objects?

2016-07-22 Thread Seti Volkylany
The ReportLab does not have a support for a current timezone, as usual 
internal Django`s objects.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/309ae27a-945f-447f-b86d-bf145fc75596%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How reconcile date/datetime`s formats the Python and the Django?

2016-07-22 Thread Seti Volkylany
The Python has next formaters for a date/datetime objects 
https://docs.python.org/3.0/library/datetime.html#id1
The Django has next 
- https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#date.
As you can see it has many differences and it is a problem.

Question is next. How to reconcile date/datetime`s formats the Python and 
the Django without manually processing?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/813f922a-e7ee-4155-a599-0c5b7a7e5150%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to set up celery in supervisord

2016-07-22 Thread monoBOT
2016-07-21 19:20 GMT+01:00 George Silva :

> If you are getting variables from the environment, supervisor that special
> environment directive. The variables need to specified in the supervisor
> conf file, such as:


​I totally recomend this tutorial about that ... its very well detailed, so
you can modify to your own specifications
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
​



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BxOsGDD78FZBO17MEyYTopJQYu%2Bx%2BAr%3D8CEHS-FEJO%2B364sWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.