Re: Using class based views.

2015-02-23 Thread James Schneider
Sure, you would just override the get() and post() and possibly dispatch()
methods in your classes as needed.

I always recommend the classy CBV inspector, helps immensely with
understanding the available methods and inheritance in the CBV's.

http://ccbv.co.uk/

Also check out the source code of Django to see how they implement each of
the generic CBV's on GitHub in django.views.generic.

However, if you have working view functions, what is the"need" to switch to
CBV's?

FBV's may be more appropriate if you have a ton of logic to handle various
types of requests via a single view, which sounds like it may be the case
here. CBV'S don't pay out well in that regard from a simplicity standpoint,
although they are more than capable.

-James
Hi all,
I'm on a Django project, and I have written the following functions in my
views.py.

def my_view_function_1(request):
#Some code
return HttpResponse(--)


def my_view_function_2(request):
#Some code
return HttpResponse(--)


def my_view_function_3(request):
#Some code
return HttpResponse(--)


Some of them are POST requests and some of them are GET.
I need to switch to class based views. Is there any ways to include
multiple GET requests and POST requests in class based views?

 --
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/9ea40ca1-387e-4234-be01-504886d7de07%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciU%2B%2BEpZ4wDbmpk6gUCfX5HKK%3D%3DNM-ytoUngS3%2BLPSm4xA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Edx LDAP Auth setting

2015-02-23 Thread 'Yip Terence' via Django users
 

Hi L,

 

Thanks for your reply.

 

I’m through pip to install the django-auth-ldap already.  But there are two 
question here. 

1.   How can I check the django-auth-ldap version?

2.   What do you mean of install via virt env? I’m follow the edX 
Ubuntu 12.04 +64 bit installation guide to install the edX, is that virt 
env? 

*https://github.com/edx/configuration/wiki/edX-Ubuntu-12.04-64-bit-Installation*
 


 

-

root@ethiopia:/edx/app/edxapp/edx-platform/lms/envs# pip install 
django-auth-ldap

Requirement already satisfied (use --upgrade to upgrade): django-auth-ldap 
in /usr/local/lib/python2.7/dist-packages

Requirement already satisfied (use --upgrade to upgrade): django in 
/usr/local/lib/python2.7/dist-packages (from django-auth-ldap)

Requirement already satisfied (use --upgrade to upgrade): python-ldap>=2.0 
in /usr/local/lib/python2.7/dist-packages (from django-auth-ldap)

Requirement already satisfied (use --upgrade to upgrade): setuptools in 
/usr/local/lib/python2.7/dist-packages (from 
python-ldap>=2.0->django-auth-ldap)
 
Cleaning up...
 
 

Thanks and Regards,

Terence Yip

Lachlan Musicman於 2015年2月24日星期二 UTC+8上午7時15分46秒寫道:

> Sorry, I've been organising a conference and have been awol. I'll be 
> able to take a look next week. But quickly: 
>
> I don't understand why you have two versions of Django, I would 
> suggest that is an issue. 
>
> You should be using django-auth-ldap, and that's got Django > 1.3 as a 
> requirement. 
>
> You shouldn't need to create the %user - that is done automatically by 
> the django-auth-ldap 
>
> Finally, please please please use a virtual environment. It makes all 
> of this significantly easier - like finding django-auth-ldap is as 
> easy as "pip install django-auth-ldap". 
>
> It's recommended you don't install via apt-get. While apt-get is easy 
> and centralised, in the case of web apps, I would install via virt env 
> and pip every time. 
>
> cheers 
> L. 
> -- 
> "This is a profound psychological violence here. How can one even 
> begin to speak of dignity in labor when one secretly feels one's job 
> should not exist?" 
>
> On the Phenomenon of Bullshit Jobs, David Graeber 
> http://strikemag.org/bullshit-jobs/ 
>
>
> On 23 February 2015 at 19:09, 'Yip Terence' via Django users 
>  wrote: 
> > Hi L, 
> > 
> > Actually, I has been input the LDAP string in 
> > /edx/app/edxapp/edx-platform/lms/envs/common.py.  But there a two 
> problems 
> > after the configuration. Firstly, the script can't get the %user value I 
> > need to hardcode the username / email in the connection string than I 
> can 
> > login to edx.  Secondly, can't to create an user profile when first 
> login. 
> > 
> > Is it need to modify the views.py and urls.py file for collect the %user 
> > value and create the user profile? 
> > 
> > 
> > I have 2 version django in edx. 
> > 
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.3/django/bin/django-admin.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.2.5/django/bin/django-admin.py
>  
>
> > 
> > 
> > ldap_auth_ldap: 
> > How can I find the version?  I using the apt-get to install the package. 
> > 
> > The search settings.py result. 
> > ---Setttings.py--- 
> > ./edx/app/xqueue/xqueue/xqueue/settings.py 
> > 
> ./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
>  
>
> > 
> ./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
>  
>
> > 
> ./edx/app/edxapp/edx-platform/common/test/acceptance/pages/studio/settings.py 
>
> > 
> ./edx/app/edxapp/edx-platform/lms/djangoapps/django_comment_client/settings.py
>  
>
> > ./edx/app/edxapp/edx-platform/lms/lib/comment_client/settings.py 
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_countries/tests/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/method_override/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/example/settings.py 
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/dealer/contrib/django/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_extensions/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/appconf/tests/settings.py
>  
>
> > 
> ./edx/app/edxapp/venvs/edxapp/src/django-pipeline/pipeline/conf/settings.py 
> > 

Using class based views.

2015-02-23 Thread Ajay M
Hi all,
I'm on a Django project, and I have written the following functions in my 
views.py.

def my_view_function_1(request):
#Some code
return HttpResponse(--)


def my_view_function_2(request):
#Some code
return HttpResponse(--)


def my_view_function_3(request):
#Some code
return HttpResponse(--)


Some of them are POST requests and some of them are GET.
I need to switch to class based views. Is there any ways to include 
multiple GET requests and POST requests in class based views?

-- 
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/9ea40ca1-387e-4234-be01-504886d7de07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Vijay Khemlani
You're welcome, glad I could help :D

On Mon, Feb 23, 2015 at 5:25 PM, Ronaldo Bahia  wrote:

> Awesome! Now it works perfectly.
>
> I'm updating my stackoverflow code for anyone facing the same doubt.
>
> Thanks a lot man
>
>
> Em segunda-feira, 23 de fevereiro de 2015 13:02:06 UTC-3, Vijay Khemlani
> escreveu:
>>
>> Change the declaration of the funciotn
>>
>> def filter_job_candidates(job):
>>
>> to
>>
>> def filter_job_candidates(self, job):
>>
>> And the filtering depends on the particular job being displayed on the
>> view, if you change the line to
>>
>> Job.objects.applied_to.all()
>>
>> Then it would filter the candidates for all the jobs, not the particular
>> one the user is seeing on the view (the one that is passed to the form
>> method).
>>
>>
>>
>>
>> On Mon, Feb 23, 2015 at 12:31 PM, Ronaldo Bahia 
>> wrote:
>>
>>> Oh, I'm feeling stupid right now :D
>>>
>>> now my new error:
>>>
>>> filter_job_candidates() takes exactly 1 argument (2 given)
>>>
>>> in views.py
>>>
>>> job_candidates = form_cand.filter_job_candidates(self.object)
>>>
>>> I've tried to remove the arguments but django says "global name 'self'
>>> not defined"
>>>
>>> I also think that in forms.py the correct way to write is:
>>>
>>> def filter_job_candidates(job):
>>> assert self.is_valid()
>>>  job_candidates = Job.objects.applied_to.all()
>>>
>>> Or am I wrong?
>>>
>>> Sorry for bothering...
>>>
>>>
>>>
>>> Em segunda-feira, 23 de fevereiro de 2015 10:50:49 UTC-3, Vijay Khemlani
>>> escreveu:

 Oh, if it is that line I missed a parenthesis in the my previuos
 snippet in the filter of haircolor

 job_candidates = job_candidates.filter(candidate__candidatelook__
 haircolor=self.cleaned_data['haircolor'])

 You also need to change the other filter

 job_candidates = job_candidates.filter(status=s
 elf.cleaned_data['status'])

 But you should ble able to detect that kind of errors, those are Python
 things, not something specifically about Django.




 On Mon, Feb 23, 2015 at 7:40 AM, Ronaldo Bahia 
 wrote:

> I have just updated my code in stackoverflow:
> http://stackoverflow.com/questions/28637326/how-to-filter-
> results-using-forms-in-django-best-approach
>
> *Ronaldo Bahia *
> Diretor | JobConvo.com
> Tel: 11 3280 6971
>
> 2015-02-22 23:16 GMT-03:00 Vijay Khemlani :
>
>> Well, I think you can continue posting the updated code here or
>> pastebin or in the stackoverflow question, where other people can suggest
>> solutions.
>>
>> What is the complete message you are getting in your syntax error?
>> can you upload your whole forms.py into pastebin or something?
>>
>> Regards
>>
>> On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia 
>> wrote:
>>
>>> Vijay,
>>>
>>> For some reason, I'm getting SyntaxError with self.cleaned_data in
>>> forms.py
>>>
>>> I'd like you to teach me how to make this. I have no problem to
>>> share my project code.
>>>
>>> Do you think we can make it?
>>>
>>> Please, email me so we can discuss about it or add me in skype:
>>> bahiamartins
>>>
>>> Thanks very much
>>>
>>> Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani
>>> escreveu:

 If both forms are used in the same view, I see little reason to
 make them separate and ModelForms, the form class I put above should 
 be a
 better choice.

 In order to do the actual filtering, you can do something like this

 class ScreeningForm(forms.Form):
 haircolor = 
 forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES,
 required=False)
 status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES,
 required=False)

 def filter_job_candidates(job):
 assert self.is_valid()

 job_candidates = job.applied_to.all().order_by('candidate')

 if self.cleaned_data['haircolor']:
 # You need to change the "user" field in CandidateLook
 to a OneToOneField for this to work, which doesn't change anything 
 since
 the field is already a primary key that can't be repeated either way
 job_candidates = job_candidates.filter(candidate__
 candidatelook__haircolor=self.cleaned_data['haircolor']

 if self.cleaned_data['status']:
 job_candidates = job_candidates.filter(status=self.
 cleaned_data['status']

 return job_candidates

 And in your view...

 class Screening(generic.DetailView):

 model = Job
 

modelFormSet and csrf

2015-02-23 Thread joulumaa
Hi,
I just studied and created first modelFormSet, and tried to use it in view.
I have same code in template as is in django documentation.
modelFormset shows data ok, but submit button is missing,why it is not in 
example template in documentation?
ok, I added submit button like I have used with basic forms, it shows up 
but cause csrf error,
then I added csrf tag as in form cases before, but still csrf  error

I am missing some information i guess???, any help for beginner...?

-Vesa
btw, i would like to have that saving button on each row in formset is 
it possible?

-- 
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/ee930575-0a61-4c74-ad34-847df414f59c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Edx LDAP Auth setting

2015-02-23 Thread Lachlan Musicman
Sorry, I've been organising a conference and have been awol. I'll be
able to take a look next week. But quickly:

I don't understand why you have two versions of Django, I would
suggest that is an issue.

You should be using django-auth-ldap, and that's got Django > 1.3 as a
requirement.

You shouldn't need to create the %user - that is done automatically by
the django-auth-ldap

Finally, please please please use a virtual environment. It makes all
of this significantly easier - like finding django-auth-ldap is as
easy as "pip install django-auth-ldap".

It's recommended you don't install via apt-get. While apt-get is easy
and centralised, in the case of web apps, I would install via virt env
and pip every time.

cheers
L.
--
"This is a profound psychological violence here. How can one even
begin to speak of dignity in labor when one secretly feels one's job
should not exist?"

On the Phenomenon of Bullshit Jobs, David Graeber
http://strikemag.org/bullshit-jobs/


On 23 February 2015 at 19:09, 'Yip Terence' via Django users
 wrote:
> Hi L,
>
> Actually, I has been input the LDAP string in
> /edx/app/edxapp/edx-platform/lms/envs/common.py.  But there a two problems
> after the configuration. Firstly, the script can't get the %user value I
> need to hardcode the username / email in the connection string than I can
> login to edx.  Secondly, can't to create an user profile when first login.
>
> Is it need to modify the views.py and urls.py file for collect the %user
> value and create the user profile?
>
>
> I have 2 version django in edx.
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.3/django/bin/django-admin.py
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.2.5/django/bin/django-admin.py
>
>
> ldap_auth_ldap:
> How can I find the version?  I using the apt-get to install the package.
>
> The search settings.py result.
> ---Setttings.py---
> ./edx/app/xqueue/xqueue/xqueue/settings.py
> ./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
> ./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
> ./edx/app/edxapp/edx-platform/common/test/acceptance/pages/studio/settings.py
> ./edx/app/edxapp/edx-platform/lms/djangoapps/django_comment_client/settings.py
> ./edx/app/edxapp/edx-platform/lms/lib/comment_client/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_countries/tests/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/method_override/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/example/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/dealer/contrib/django/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_extensions/settings.py
> ./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/appconf/tests/settings.py
> ./edx/app/edxapp/venvs/edxapp/src/django-pipeline/pipeline/conf/settings.py
> ./edx/app/edxapp/venvs/edxapp/src/django-pipeline/tests/settings.py
> ./edx/app/edxapp/venvs/edxapp/src/edx-val/edxval/settings.py
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.3/django/conf/project_template/settings.py
> ./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.2.5/django/conf/project_template/settings.py
> ./usr/local/lib/python2.7/dist-packages/django/conf/project_template/project_name/settings.py
>
> Thank you very much for your assistance.
>
> Thanks and Regards,
> Terence Yip
>
> Lachlan Musicman於 2015年2月10日星期二 UTC+8下午12時22分50秒寫道:
>>
>> Yip, EDX looks complex - can you search for the settings file and report
>> back?
>>
>> AuthLDAP is annoying, but it does work - I've used it successfully
>> against an AD backend. The error messages are important to read.
>>
>> But first, find your settings file.
>>
>> You will need to provide us with more info too. What's not working?
>> What have you put into the settings file? What version of django is
>> EDX using, and does django_auth_ldap provide support for that django
>> version, what error messages are you getting? Can you attach to the
>> ldap server from just the django shell (ie, are the username and
>> password etc correct)?
>>
>> cheers
>> L.
>> --
>> "This is a profound psychological violence here. How can one even
>> begin to speak of dignity in labor when one secretly feels one's job
>> should not exist?"
>>
>> On the Phenomenon of Bullshit Jobs, David Graeber
>> http://strikemag.org/bullshit-jobs/
>>
>>
>> On 10 February 2015 at 15:00, 'Yip Terence' via Django users
>>  wrote:
>> > Dear All,
>> >
>> > I have been 

Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Ronaldo Bahia
Awesome! Now it works perfectly.

I'm updating my stackoverflow code for anyone facing the same doubt.

Thanks a lot man


Em segunda-feira, 23 de fevereiro de 2015 13:02:06 UTC-3, Vijay Khemlani 
escreveu:
>
> Change the declaration of the funciotn
>
> def filter_job_candidates(job):
>
> to
>
> def filter_job_candidates(self, job):
>
> And the filtering depends on the particular job being displayed on the 
> view, if you change the line to
>
> Job.objects.applied_to.all()
>
> Then it would filter the candidates for all the jobs, not the particular 
> one the user is seeing on the view (the one that is passed to the form 
> method).
>
>
>
>
> On Mon, Feb 23, 2015 at 12:31 PM, Ronaldo Bahia  > wrote:
>
>> Oh, I'm feeling stupid right now :D
>>
>> now my new error:
>>
>> filter_job_candidates() takes exactly 1 argument (2 given)
>>
>> in views.py
>>
>> job_candidates = form_cand.filter_job_candidates(self.object)
>>
>> I've tried to remove the arguments but django says "global name 'self' 
>> not defined"
>>
>> I also think that in forms.py the correct way to write is:
>>
>> def filter_job_candidates(job):
>> assert self.is_valid()
>>  job_candidates = Job.objects.applied_to.all()
>>
>> Or am I wrong?
>>
>> Sorry for bothering...
>>
>>
>>
>> Em segunda-feira, 23 de fevereiro de 2015 10:50:49 UTC-3, Vijay Khemlani 
>> escreveu:
>>>
>>> Oh, if it is that line I missed a parenthesis in the my previuos snippet 
>>> in the filter of haircolor
>>>
>>> job_candidates = job_candidates.filter(candidate__candidatelook__
>>> haircolor=self.cleaned_data['haircolor'])
>>>
>>> You also need to change the other filter
>>>
>>> job_candidates = job_candidates.filter(status=
>>> self.cleaned_data['status'])
>>>
>>> But you should ble able to detect that kind of errors, those are Python 
>>> things, not something specifically about Django.
>>>
>>>
>>>
>>>
>>> On Mon, Feb 23, 2015 at 7:40 AM, Ronaldo Bahia  
>>> wrote:
>>>
 I have just updated my code in stackoverflow:
 http://stackoverflow.com/questions/28637326/how-to-
 filter-results-using-forms-in-django-best-approach

 *Ronaldo Bahia *
 Diretor | JobConvo.com
 Tel: 11 3280 6971

 2015-02-22 23:16 GMT-03:00 Vijay Khemlani :

> Well, I think you can continue posting the updated code here or 
> pastebin or in the stackoverflow question, where other people can suggest 
> solutions.
>
> What is the complete message you are getting in your syntax error? can 
> you upload your whole forms.py into pastebin or something?
>
> Regards
>
> On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia  
> wrote:
>
>> Vijay,
>>
>> For some reason, I'm getting SyntaxError with self.cleaned_data in 
>> forms.py 
>>
>> I'd like you to teach me how to make this. I have no problem to share 
>> my project code.
>>
>> Do you think we can make it?
>>
>> Please, email me so we can discuss about it or add me in skype: 
>> bahiamartins
>>
>> Thanks very much
>>
>> Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani 
>> escreveu:
>>>
>>> If both forms are used in the same view, I see little reason to make 
>>> them separate and ModelForms, the form class I put above should be a 
>>> better 
>>> choice.
>>>
>>> In order to do the actual filtering, you can do something like this
>>>
>>> class ScreeningForm(forms.Form):
>>> haircolor = 
>>> forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES, 
>>> required=False)
>>> status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES, 
>>> required=False)
>>>
>>> def filter_job_candidates(job):
>>> assert self.is_valid()
>>>
>>> job_candidates = job.applied_to.all().order_by('candidate')
>>>
>>> if self.cleaned_data['haircolor']:
>>> # You need to change the "user" field in CandidateLook 
>>> to a OneToOneField for this to work, which doesn't change anything 
>>> since 
>>> the field is already a primary key that can't be repeated either way
>>> job_candidates = job_candidates.filter(candidate__
>>> candidatelook__haircolor=self.cleaned_data['haircolor']
>>>
>>> if self.cleaned_data['status']:
>>> job_candidates = job_candidates.filter(status=self.
>>> cleaned_data['status']
>>>
>>> return job_candidates
>>>
>>> And in your view...
>>>
>>> class Screening(generic.DetailView):
>>>
>>> model = Job
>>> template_name = 'dashboard/screening.html'
>>>
>>> def get_context_data(self, **kwargs):
>>> context = super(Screening, self).get_context_data(**kwargs)
>>>
>>> # Fetch the sender_id for each unread message.
>>>

Does django support hmvc?

2015-02-23 Thread frocco
If so, are there any tutorials?

-- 
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/738b76c8-5f35-42a2-8509-153151d6d437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Vijay Khemlani
Change the declaration of the funciotn

def filter_job_candidates(job):

to

def filter_job_candidates(self, job):

And the filtering depends on the particular job being displayed on the
view, if you change the line to

Job.objects.applied_to.all()

Then it would filter the candidates for all the jobs, not the particular
one the user is seeing on the view (the one that is passed to the form
method).




On Mon, Feb 23, 2015 at 12:31 PM, Ronaldo Bahia 
wrote:

> Oh, I'm feeling stupid right now :D
>
> now my new error:
>
> filter_job_candidates() takes exactly 1 argument (2 given)
>
> in views.py
>
> job_candidates = form_cand.filter_job_candidates(self.object)
>
> I've tried to remove the arguments but django says "global name 'self' not
> defined"
>
> I also think that in forms.py the correct way to write is:
>
> def filter_job_candidates(job):
> assert self.is_valid()
>  job_candidates = Job.objects.applied_to.all()
>
> Or am I wrong?
>
> Sorry for bothering...
>
>
>
> Em segunda-feira, 23 de fevereiro de 2015 10:50:49 UTC-3, Vijay Khemlani
> escreveu:
>>
>> Oh, if it is that line I missed a parenthesis in the my previuos snippet
>> in the filter of haircolor
>>
>> job_candidates = job_candidates.filter(candidate__candidatelook__
>> haircolor=self.cleaned_data['haircolor'])
>>
>> You also need to change the other filter
>>
>> job_candidates = job_candidates.filter(status=
>> self.cleaned_data['status'])
>>
>> But you should ble able to detect that kind of errors, those are Python
>> things, not something specifically about Django.
>>
>>
>>
>>
>> On Mon, Feb 23, 2015 at 7:40 AM, Ronaldo Bahia 
>> wrote:
>>
>>> I have just updated my code in stackoverflow:
>>> http://stackoverflow.com/questions/28637326/how-to-
>>> filter-results-using-forms-in-django-best-approach
>>>
>>> *Ronaldo Bahia *
>>> Diretor | JobConvo.com
>>> Tel: 11 3280 6971
>>>
>>> 2015-02-22 23:16 GMT-03:00 Vijay Khemlani :
>>>
 Well, I think you can continue posting the updated code here or
 pastebin or in the stackoverflow question, where other people can suggest
 solutions.

 What is the complete message you are getting in your syntax error? can
 you upload your whole forms.py into pastebin or something?

 Regards

 On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia 
 wrote:

> Vijay,
>
> For some reason, I'm getting SyntaxError with self.cleaned_data in
> forms.py
>
> I'd like you to teach me how to make this. I have no problem to share
> my project code.
>
> Do you think we can make it?
>
> Please, email me so we can discuss about it or add me in skype:
> bahiamartins
>
> Thanks very much
>
> Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani
> escreveu:
>>
>> If both forms are used in the same view, I see little reason to make
>> them separate and ModelForms, the form class I put above should be a 
>> better
>> choice.
>>
>> In order to do the actual filtering, you can do something like this
>>
>> class ScreeningForm(forms.Form):
>> haircolor = 
>> forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES,
>> required=False)
>> status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES,
>> required=False)
>>
>> def filter_job_candidates(job):
>> assert self.is_valid()
>>
>> job_candidates = job.applied_to.all().order_by('candidate')
>>
>> if self.cleaned_data['haircolor']:
>> # You need to change the "user" field in CandidateLook to
>> a OneToOneField for this to work, which doesn't change anything since the
>> field is already a primary key that can't be repeated either way
>> job_candidates = job_candidates.filter(candidate__
>> candidatelook__haircolor=self.cleaned_data['haircolor']
>>
>> if self.cleaned_data['status']:
>> job_candidates = job_candidates.filter(status=self.
>> cleaned_data['status']
>>
>> return job_candidates
>>
>> And in your view...
>>
>> class Screening(generic.DetailView):
>>
>> model = Job
>> template_name = 'dashboard/screening.html'
>>
>> def get_context_data(self, **kwargs):
>> context = super(Screening, self).get_context_data(**kwargs)
>>
>> # Fetch the sender_id for each unread message.
>> # Count the number of times that the sender_id was included.
>> # Then convert the list of tuples into a dictionary for quick
>> lookup.
>> sent_messages = dict(
>> self.request.user.received_messages.filter(
>> read_at__isnull=True
>> ).values('sender_id').annotate(
>> messages_sent=Count('sender_id')
>>  

Re: RedirectView()

2015-02-23 Thread Brad Rice
OK, thanks. I had added that. I was just putting the url to the particular 
file in place. This is my whole urls.py at the top: So you are saying don't 
add the line that includes the web.urls?

urlpatterns = patterns('',

url(r'^admin/', include(admin.site.urls)),
url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
url(r'^web/', include('web.urls', namespace='web'),
)
)

Then this is the web urls.py

urlpatterns = patterns('',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^gallery', gallery, name='gallery'),
)

On Monday, February 23, 2015 at 10:01:53 AM UTC-5, Andréas Kühne wrote:
>
>
> 2015-02-23 15:30 GMT+01:00 Brad Rice :
>
>> I'm using RedirectView and it is redirecting to my app, but is not 
>> rendering the view in the app I am pointing to.
>>
>> I want to redirect my root / to my app /web
>>
>> I have this in my primary app urls:
>>
>> url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
>>
>> I have this in web.urls.py
>>
>> url(r'^$', IndexView.as_view(), name='index'),
>>
>> I have his in my web.vews.py
>>
>> class Index(View):
>>
>> def get(self, request, *args, **kwargs):
>> return HttpResponse('Hello, World!')
>>
>> when I go to / I do get redirected to /web/ but I get a index.html 
>> template display rather than Hello World. It isn't finding my Index(View) 
>> class for some reason.
>>
>> Can anybody explain to me how this should work?
>>
>> -- 
>> Brad Rice
>> brad...@gmail.com 
>> --
>> To succeed in life, you need two things: ignorance and confidence.
>> -Mark Twain
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> Hi Brad,
>
> You have not correctly written the web.urls.py file. It should be:
>
> url(r'^web/$', IndexView.as_view(), name='index'),
>
> The urls file doesn't know about in which app it resides, så you have to 
> add the complete url yourself. As long as you don't add the web.urls.py 
> into your main urls.py file with:
>
> url(r'^web/', include(web.urls)),
>
> then your code should work ok.
>
> Regards,
>
> Andréas
>

-- 
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/98517b28-588f-4344-a5a3-1f778a154f98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Ronaldo Bahia
Oh, I'm feeling stupid right now :D

now my new error:

filter_job_candidates() takes exactly 1 argument (2 given)

in views.py

job_candidates = form_cand.filter_job_candidates(self.object)

I've tried to remove the arguments but django says "global name 'self' not 
defined"

I also think that in forms.py the correct way to write is:

def filter_job_candidates(job):
assert self.is_valid()
 job_candidates = Job.objects.applied_to.all()

Or am I wrong?

Sorry for bothering...



Em segunda-feira, 23 de fevereiro de 2015 10:50:49 UTC-3, Vijay Khemlani 
escreveu:
>
> Oh, if it is that line I missed a parenthesis in the my previuos snippet 
> in the filter of haircolor
>
> job_candidates = 
> job_candidates.filter(candidate__candidatelook__haircolor=self.cleaned_data['haircolor'])
>
> You also need to change the other filter
>
> job_candidates = job_candidates.filter(status=self.cleaned_data['status'])
>
> But you should ble able to detect that kind of errors, those are Python 
> things, not something specifically about Django.
>
>
>
>
> On Mon, Feb 23, 2015 at 7:40 AM, Ronaldo Bahia  > wrote:
>
>> I have just updated my code in stackoverflow:
>>
>> http://stackoverflow.com/questions/28637326/how-to-filter-results-using-forms-in-django-best-approach
>>
>> *Ronaldo Bahia *
>> Diretor | JobConvo.com
>> Tel: 11 3280 6971
>>
>> 2015-02-22 23:16 GMT-03:00 Vijay Khemlani > >:
>>
>>> Well, I think you can continue posting the updated code here or pastebin 
>>> or in the stackoverflow question, where other people can suggest solutions.
>>>
>>> What is the complete message you are getting in your syntax error? can 
>>> you upload your whole forms.py into pastebin or something?
>>>
>>> Regards
>>>
>>> On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia >> > wrote:
>>>
 Vijay,

 For some reason, I'm getting SyntaxError with self.cleaned_data in 
 forms.py 

 I'd like you to teach me how to make this. I have no problem to share 
 my project code.

 Do you think we can make it?

 Please, email me so we can discuss about it or add me in skype: 
 bahiamartins

 Thanks very much

 Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani 
 escreveu:
>
> If both forms are used in the same view, I see little reason to make 
> them separate and ModelForms, the form class I put above should be a 
> better 
> choice.
>
> In order to do the actual filtering, you can do something like this
>
> class ScreeningForm(forms.Form):
> haircolor = 
> forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES, 
> required=False)
> status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES, 
> required=False)
>
> def filter_job_candidates(job):
> assert self.is_valid()
>
> job_candidates = job.applied_to.all().order_by('candidate')
>
> if self.cleaned_data['haircolor']:
> # You need to change the "user" field in CandidateLook to 
> a OneToOneField for this to work, which doesn't change anything since the 
> field is already a primary key that can't be repeated either way
> job_candidates = job_candidates.filter(candidate__
> candidatelook__haircolor=self.cleaned_data['haircolor']
>
> if self.cleaned_data['status']:
> job_candidates = job_candidates.filter(status=self.
> cleaned_data['status']
>
> return job_candidates
>
> And in your view...
>
> class Screening(generic.DetailView):
>
> model = Job
> template_name = 'dashboard/screening.html'
>
> def get_context_data(self, **kwargs):
> context = super(Screening, self).get_context_data(**kwargs)
>
> # Fetch the sender_id for each unread message.
> # Count the number of times that the sender_id was included.
> # Then convert the list of tuples into a dictionary for quick 
> lookup.
> sent_messages = dict(
> self.request.user.received_messages.filter(
> read_at__isnull=True
> ).values('sender_id').annotate(
> messages_sent=Count('sender_id')
> ).values_list('sender_id', 'messages_sent')
> )
>
> form = ScreeningForm(self.request.GET)
>
> if form.is_valid():
> job_candidates = form.filter_job_candidates(self.object)
> else:
> # Fallback, since the form will always be valid unless 
> someone tampered with the form parameters manually
> job_candidates = self.object.applied_to.all().
> order_by('candidate')
>
> candidates = []
> for candidate in job_candidates:
> candidate.messages_sent = 

Re: RedirectView()

2015-02-23 Thread Andreas Kuhne
2015-02-23 15:30 GMT+01:00 Brad Rice :

> I'm using RedirectView and it is redirecting to my app, but is not
> rendering the view in the app I am pointing to.
>
> I want to redirect my root / to my app /web
>
> I have this in my primary app urls:
>
> url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),
>
> I have this in web.urls.py
>
> url(r'^$', IndexView.as_view(), name='index'),
>
> I have his in my web.vews.py
>
> class Index(View):
>
> def get(self, request, *args, **kwargs):
> return HttpResponse('Hello, World!')
>
> when I go to / I do get redirected to /web/ but I get a index.html
> template display rather than Hello World. It isn't finding my Index(View)
> class for some reason.
>
> Can anybody explain to me how this should work?
>
> --
> Brad Rice
> bradri...@gmail.com
> --
> To succeed in life, you need two things: ignorance and confidence.
> -Mark Twain
>
> --
> 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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

Hi Brad,

You have not correctly written the web.urls.py file. It should be:

url(r'^web/$', IndexView.as_view(), name='index'),

The urls file doesn't know about in which app it resides, så you have to
add the complete url yourself. As long as you don't add the web.urls.py
into your main urls.py file with:

url(r'^web/', include(web.urls)),

then your code should work ok.

Regards,

Andréas

-- 
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/CALXYUb%3DHePP0DAm2Bodmaxt8sSYqo7A2hiNwvtLPRXV7Aarrdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RedirectView()

2015-02-23 Thread Brad Rice
I'm using RedirectView and it is redirecting to my app, but is not
rendering the view in the app I am pointing to.

I want to redirect my root / to my app /web

I have this in my primary app urls:

url(r'^$', RedirectView.as_view(url='/web/', permanent=False)),

I have this in web.urls.py

url(r'^$', IndexView.as_view(), name='index'),

I have his in my web.vews.py

class Index(View):

def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')

when I go to / I do get redirected to /web/ but I get a index.html template
display rather than Hello World. It isn't finding my Index(View) class for
some reason.

Can anybody explain to me how this should work?

-- 
Brad Rice
bradri...@gmail.com
--
To succeed in life, you need two things: ignorance and confidence.
-Mark Twain

-- 
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/CAMqTKp4vQmDez7tJSZ54j96huCfhTiCY3F2-g_Lpgq-8sgPMEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Vijay Khemlani
Oh, if it is that line I missed a parenthesis in the my previuos snippet in
the filter of haircolor

job_candidates =
job_candidates.filter(candidate__candidatelook__haircolor=self.cleaned_data['haircolor'])

You also need to change the other filter

job_candidates = job_candidates.filter(status=self.cleaned_data['status'])

But you should ble able to detect that kind of errors, those are Python
things, not something specifically about Django.




On Mon, Feb 23, 2015 at 7:40 AM, Ronaldo Bahia  wrote:

> I have just updated my code in stackoverflow:
>
> http://stackoverflow.com/questions/28637326/how-to-filter-results-using-forms-in-django-best-approach
>
> *Ronaldo Bahia *
> Diretor | JobConvo.com
> Tel: 11 3280 6971
>
> 2015-02-22 23:16 GMT-03:00 Vijay Khemlani :
>
>> Well, I think you can continue posting the updated code here or pastebin
>> or in the stackoverflow question, where other people can suggest solutions.
>>
>> What is the complete message you are getting in your syntax error? can
>> you upload your whole forms.py into pastebin or something?
>>
>> Regards
>>
>> On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia 
>> wrote:
>>
>>> Vijay,
>>>
>>> For some reason, I'm getting SyntaxError with self.cleaned_data in
>>> forms.py
>>>
>>> I'd like you to teach me how to make this. I have no problem to share my
>>> project code.
>>>
>>> Do you think we can make it?
>>>
>>> Please, email me so we can discuss about it or add me in skype:
>>> bahiamartins
>>>
>>> Thanks very much
>>>
>>> Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani
>>> escreveu:

 If both forms are used in the same view, I see little reason to make
 them separate and ModelForms, the form class I put above should be a better
 choice.

 In order to do the actual filtering, you can do something like this

 class ScreeningForm(forms.Form):
 haircolor = forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES,
 required=False)
 status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES,
 required=False)

 def filter_job_candidates(job):
 assert self.is_valid()

 job_candidates = job.applied_to.all().order_by('candidate')

 if self.cleaned_data['haircolor']:
 # You need to change the "user" field in CandidateLook to a
 OneToOneField for this to work, which doesn't change anything since the
 field is already a primary key that can't be repeated either way
 job_candidates = job_candidates.filter(candidate__
 candidatelook__haircolor=self.cleaned_data['haircolor']

 if self.cleaned_data['status']:
 job_candidates = job_candidates.filter(status=self.
 cleaned_data['status']

 return job_candidates

 And in your view...

 class Screening(generic.DetailView):

 model = Job
 template_name = 'dashboard/screening.html'

 def get_context_data(self, **kwargs):
 context = super(Screening, self).get_context_data(**kwargs)

 # Fetch the sender_id for each unread message.
 # Count the number of times that the sender_id was included.
 # Then convert the list of tuples into a dictionary for quick
 lookup.
 sent_messages = dict(
 self.request.user.received_messages.filter(
 read_at__isnull=True
 ).values('sender_id').annotate(
 messages_sent=Count('sender_id')
 ).values_list('sender_id', 'messages_sent')
 )

 form = ScreeningForm(self.request.GET)

 if form.is_valid():
 job_candidates = form.filter_job_candidates(self.object)
 else:
 # Fallback, since the form will always be valid unless
 someone tampered with the form parameters manually
 job_candidates = self.object.applied_to.all().
 order_by('candidate')

 candidates = []
 for candidate in job_candidates:
 candidate.messages_sent = sent_messages.get(candidate.
 candidate.user.id)
 candidates.append(candidate)
 context['candidate_list'] = candidates
 context['form'] = form

 return context


 On Sat, Feb 21, 2015 at 9:57 AM, Ronaldo Bahia 
 wrote:

> Hi Vijay,
>
> Thanks for your response.
> I've just updated my question in stackoverflow 'cause I forgot to show
> my forms.
>
> What I need is to enable a user (company) to filter results
> (candidates) based on forms selection (candidates' status and candidates'
> haircolors)
>
> And I don't know how to make this in my detailview.
>
> See the link: 

Re: Django App DB replicas - call for suggestions

2015-02-23 Thread Cal Leeming
>From what I can tell, you want to run a copy of the database on
multiple mini devices and have replication between them? If so, this
isn't really a good use case for replication, and adds several
unnecessary layers of complexity. So lets look at the end goal, you
want multiple clients to have read/write access to the same data, with
the constraint that the internet connection will be unreliable, but
you still want the data to be accessible, and possibly, editable.

This can be easily achieved by implementing good development
practises, similar to that of SPAs [1] or any "properly written"
mobile application. The application would maintain its own database,
for SPAs you'd probably use local storage [2] (assuming you didn't
need to support ancient browsers), and for mobile apps you can use an
embedded copy of SQLite3 [4] for relational structures, or couchbase
mobile [3] for document store. These databases would sync using your
"central" server, and your API design would depend on exactly what you
are trying to do, for example for simple requirements you could use
REST, but in others you may want to consider an RPC style, or you
might want to have the best of both worlds. There are some frameworks
out there which handle things like this, emberjs, angularjs etc,
though personally I am yet to find a decent, simple and clean
implementation of such a structure.

To achieve this, you also have to consider conflict handling, for
example if both users are offline and they edit a model, how would you
handle the conflict? If you automatically handle merge conflicts then
you also have to notify the affected users, and reflecting this in
your UX is *hard*. The theory of distributed systems are actually
quite simple, at least once you get past all the academic stuff, the
hard part is exposing it to the user in a friendly way.

You can get around many of these problems by disabling edits unless
there is an internet connection, allowing only read access in the
event of a connection drop out, then using model caching on the client
side (along with a bulk retrieve request). However both approaches
come with the same problem of delta changes, if a model changes then
each app will need to be notified about this, ideally via a push
mechanism. Designing an events system around this can be quite
challenging, for even the most seasoned developers.

If you have enough time/resources then it could be a fantastic
learning experience for you, but if this is a quick/dirty project
primarily lead by billable hours, then you probably don't want to
follow this route. If someone sent me a spec like this, I'd say it
would *easily* be 300+ hours work.

Hope this helps, if I have misunderstood, let me know.

Cal

[1]: http://en.wikipedia.org/wiki/Single-page_application
[2]: http://diveintohtml5.info/storage.html
[3]: http://www.couchbase.com/nosql-databases/couchbase-mobile
[4]: http://www.appcoda.com/sqlite-database-ios-app-tutorial/


On Sat, Feb 21, 2015 at 2:45 PM, Blazor  wrote:
> Hi all,
>
> I was asked to design a new django app by a client whose needs are a little
> bit context-specific.
>
> The purpose of this app is to introduce computer-assisted technologies in a
> paper-based environment, in the e-Health domain. This client would like to
> access a central server with a few mobile clients with the constraint of a
> non-permanent internet connection, because the location of the mobile
> clients is continuously changing and an internet connection might not always
> be available.
>
> My current idea is based on a portable small server (a nettop, or even a
> raspberry pi, as the computing power is not a problem for this app) with a
> django app on it and a wireless access point for providing mobile clients
> with an always-on portable server reachability. At the same time, I'd like
> other clients around the world (a very little number, though) to still be
> able to access a central remote version of the same service, so I'd still
> deploy the same app (with its own DB replica) within a remote server.
>
> I hope I made my client's requirements clear: how would you manage the
> synchronization between the two DBs, given that both DBs need a write access
> and that the only relaxation of this constraint is that when the portable
> server is on, the remote DB might work in a read-only mode (but this is not
> required).
>
> Thanks in advance for any suggestions you'll provide me with.
> B.
>
> --
> 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/bb65e66c-4788-4010-9bfe-b8f20e41e5d1%40googlegroups.com.
> For more 

Re: Django App DB replicas - call for suggestions

2015-02-23 Thread Derek
I recently came across this article:
https://www.clairereynaud.net/blog/adding-offline-mode-to-your-mobile-app/
May be of interest as it deals with versions and revisions to track 
conflict between changes...

On Saturday, 21 February 2015 16:45:40 UTC+2, Blazor wrote:
>
> Hi all,
>
> I was asked to design a new django app by a client whose needs are a 
> little bit context-specific.
>
> The purpose of this app is to introduce computer-assisted technologies in 
> a paper-based environment, in the e-Health domain. This client would like 
> to access a central server with a few mobile clients with the constraint of 
> a non-permanent internet connection, because the location of the mobile 
> clients is continuously changing and an internet connection might not 
> always be available.
>
> My current idea is based on a portable small server (a nettop, or even a 
> raspberry pi, as the computing power is not a problem for this app) with a 
> django app on it and a wireless access point for providing mobile clients 
> with an always-on portable server reachability. At the same time, I'd like 
> other clients around the world (a very little number, though) to still be 
> able to access a central remote version of the same service, so I'd still 
> deploy the same app (with its own DB replica) within a remote server.
>
> I hope I made my client's requirements clear: how would you manage the 
> synchronization between the two DBs, given that both DBs need a write 
> access and that the only relaxation of this constraint is that when the 
> portable server is on, the remote DB might work in a read-only mode (but 
> this is not required).
>
> Thanks in advance for any suggestions you'll provide me with.
> B.
>

-- 
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/0c2ce9d3-0c99-40c6-877f-51aba502a9e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle model constants

2015-02-23 Thread James Schneider
>>> In my case, a Task can have one or more TaskStatus. I do not wish to
store
>>> the TaskStatus in the database since they are simply constants.
>>>
>>> Does anyone have a better way of how I can approach this?
>>>

I just read this a bit closer. I think what you mean is that you don't want
a separate enumeration DB table that lists all of your choices with their
integer codes and then your statuses link to it via FK's, etc. That's
perfectly fine, and that should be how it works since you have enumerated
all of the possible outcomes in your tuples. Since you have provided a list
of choices to Django, it will validate that only those choices are allowed
when forms are submitted, etc. as a bonus.

TL;DR; Unless you've hit a specific problem, it looks like you are doing it
right.

https://docs.djangoproject.com/en/1.7/ref/models/fields/#choices

-James

-- 
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%2Be%2BciW6Nk076DGurtJQ6t9gFj%2BsLgKkAdwtEJdYcvxRwq9wrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to handle model constants

2015-02-23 Thread Frankline
The reason for my strategy here is because I will need to have a
multi-select instead of a single select for choosing the TaskStatus in the
form i.e. A *Task* can have one or more *TaskStatus*.

Moreover, I will again have to create another class, *SomeClass*, which has
a direct relation to the *Task* model, but can only be associated with only
one *TaskStatus *available from the pool of *TaskStatus*' that were
selected for that *Task*. (Not sure I'm making sense here)

So, YES, the class will be used to compute values based on the stored
constants.

On Mon, Feb 23, 2015 at 2:11 PM, James Schneider 
wrote:

> For global constants, I would second the strategy that Mike outlined, and
> rename your constants in a more specific way, such as TASK_CANCELLED,
> TASK_COMPLETE, etc. unless of course CANCELLED can apply to more than just
> tasks.
>
> The use of a separate class to store such constants is of course viable,
> but seems like a bit of unnecessary complication if all it does is hold
> values. I wouldn't recommend it unless the class had other purposes such as
> returning computed values based on those stored constants.
>
> I usually store model choices directly in the model, since they don't
> generally apply anywhere else.
>
> Whatever you do, try to keep it consistent.
>
> -James
> On Feb 23, 2015 12:07 AM, "Mike Dewhirst"  wrote:
>
>> On 23/02/2015 5:23 PM, Frankline wrote:
>>
>>> Hi all,
>>>
>>> I am getting confused regarding the use of constants and would be keen to
>>> know how the rest of you handle constants in your models. Ofcourse I
>>> could
>>> handle it easily similar to how it has been handled here:
>>> https://docs.djangoproject.com/en/1.7/ref/models/fields/#
>>> django.db.models.Field.choices
>>>
>>>
>> I have many many constants which are used across a number of modules and
>> apps.
>>
>> I store them in the __init__.py file of the namespace in which they are
>> used. Sensible naming of constants is vital of course and I'm careful to
>> store them alphabetically so I can find them easily enough scrolling
>> quickly through the file.
>>
>> At the top of my modules I say ...
>>
>> from  import CONST1, CONST2 etc
>>
>> Works for me
>>
>> Mike
>>
>>  But I wanted to put the constants in a separate class on their own. This
>>> is
>>> what I hav so far:
>>>
>>> models.py
>>>
>>> class TaskStatus(models.Model):
>>>
>>>  CANCELLED = 0
>>>  REQUIRES_ATTENTION = 1
>>>  WORK_IN_PROGRESS = 2
>>>  COMPLETE = 3
>>>
>>>  STATUS_TYPES = (
>>>  (CANCELLED, 'Cancelled'),
>>>  (REQUIRES_ATTENTION, 'Requires attention'),
>>>  (WORK_IN_PROGRESS, 'Work in progress'),
>>>  (COMPLETE, 'Complete'),
>>>  )
>>>
>>>  status = models.IntegerField(choices=STATUS_TYPES,
>>> default=REQUIRES_ATTENTION)
>>>  class Task(models.Model):
>>>  status = models.ManyToManyField(TaskStatus,
>>> default=TaskStatus.REQUIRES_ATTENTION)
>>>
>>>
>>> In my case, a Task can have one or more TaskStatus. I do not wish to
>>> store
>>> the TaskStatus in the database since they are simply constants.
>>>
>>> Does anyone have a better way of how I can approach this?
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/54EADFC3.3020301%40dewhirst.com.au.
>> 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%2Be%2BciVgDVT2vreL41GjKBUV5MmxDWhwMWSM8Pg92-YCeNMrng%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 

Re: How to handle model constants

2015-02-23 Thread James Schneider
For global constants, I would second the strategy that Mike outlined, and
rename your constants in a more specific way, such as TASK_CANCELLED,
TASK_COMPLETE, etc. unless of course CANCELLED can apply to more than just
tasks.

The use of a separate class to store such constants is of course viable,
but seems like a bit of unnecessary complication if all it does is hold
values. I wouldn't recommend it unless the class had other purposes such as
returning computed values based on those stored constants.

I usually store model choices directly in the model, since they don't
generally apply anywhere else.

Whatever you do, try to keep it consistent.

-James
On Feb 23, 2015 12:07 AM, "Mike Dewhirst"  wrote:

> On 23/02/2015 5:23 PM, Frankline wrote:
>
>> Hi all,
>>
>> I am getting confused regarding the use of constants and would be keen to
>> know how the rest of you handle constants in your models. Ofcourse I could
>> handle it easily similar to how it has been handled here:
>> https://docs.djangoproject.com/en/1.7/ref/models/fields/#
>> django.db.models.Field.choices
>>
>>
> I have many many constants which are used across a number of modules and
> apps.
>
> I store them in the __init__.py file of the namespace in which they are
> used. Sensible naming of constants is vital of course and I'm careful to
> store them alphabetically so I can find them easily enough scrolling
> quickly through the file.
>
> At the top of my modules I say ...
>
> from  import CONST1, CONST2 etc
>
> Works for me
>
> Mike
>
>  But I wanted to put the constants in a separate class on their own. This
>> is
>> what I hav so far:
>>
>> models.py
>>
>> class TaskStatus(models.Model):
>>
>>  CANCELLED = 0
>>  REQUIRES_ATTENTION = 1
>>  WORK_IN_PROGRESS = 2
>>  COMPLETE = 3
>>
>>  STATUS_TYPES = (
>>  (CANCELLED, 'Cancelled'),
>>  (REQUIRES_ATTENTION, 'Requires attention'),
>>  (WORK_IN_PROGRESS, 'Work in progress'),
>>  (COMPLETE, 'Complete'),
>>  )
>>
>>  status = models.IntegerField(choices=STATUS_TYPES,
>> default=REQUIRES_ATTENTION)
>>  class Task(models.Model):
>>  status = models.ManyToManyField(TaskStatus,
>> default=TaskStatus.REQUIRES_ATTENTION)
>>
>>
>> In my case, a Task can have one or more TaskStatus. I do not wish to store
>> the TaskStatus in the database since they are simply constants.
>>
>> Does anyone have a better way of how I can approach this?
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/54EADFC3.3020301%40dewhirst.com.au.
> 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%2Be%2BciVgDVT2vreL41GjKBUV5MmxDWhwMWSM8Pg92-YCeNMrng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to filter results using forms in Django/Python (best approach) ?

2015-02-23 Thread Ronaldo Bahia
I have just updated my code in stackoverflow:
http://stackoverflow.com/questions/28637326/how-to-filter-results-using-forms-in-django-best-approach

*Ronaldo Bahia *
Diretor | JobConvo.com
Tel: 11 3280 6971

2015-02-22 23:16 GMT-03:00 Vijay Khemlani :

> Well, I think you can continue posting the updated code here or pastebin
> or in the stackoverflow question, where other people can suggest solutions.
>
> What is the complete message you are getting in your syntax error? can you
> upload your whole forms.py into pastebin or something?
>
> Regards
>
> On Sun, Feb 22, 2015 at 10:53 PM, Ronaldo Bahia 
> wrote:
>
>> Vijay,
>>
>> For some reason, I'm getting SyntaxError with self.cleaned_data in
>> forms.py
>>
>> I'd like you to teach me how to make this. I have no problem to share my
>> project code.
>>
>> Do you think we can make it?
>>
>> Please, email me so we can discuss about it or add me in skype:
>> bahiamartins
>>
>> Thanks very much
>>
>> Em sábado, 21 de fevereiro de 2015 20:49:21 UTC-2, Vijay Khemlani
>> escreveu:
>>>
>>> If both forms are used in the same view, I see little reason to make
>>> them separate and ModelForms, the form class I put above should be a better
>>> choice.
>>>
>>> In order to do the actual filtering, you can do something like this
>>>
>>> class ScreeningForm(forms.Form):
>>> haircolor = forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_CHOICES,
>>> required=False)
>>> status = forms.ChoiceField(choices=CandidateToJob.STATUS_CHOICES,
>>> required=False)
>>>
>>> def filter_job_candidates(job):
>>> assert self.is_valid()
>>>
>>> job_candidates = job.applied_to.all().order_by('candidate')
>>>
>>> if self.cleaned_data['haircolor']:
>>> # You need to change the "user" field in CandidateLook to a
>>> OneToOneField for this to work, which doesn't change anything since the
>>> field is already a primary key that can't be repeated either way
>>> job_candidates = job_candidates.filter(candidate__
>>> candidatelook__haircolor=self.cleaned_data['haircolor']
>>>
>>> if self.cleaned_data['status']:
>>> job_candidates = job_candidates.filter(status=self.
>>> cleaned_data['status']
>>>
>>> return job_candidates
>>>
>>> And in your view...
>>>
>>> class Screening(generic.DetailView):
>>>
>>> model = Job
>>> template_name = 'dashboard/screening.html'
>>>
>>> def get_context_data(self, **kwargs):
>>> context = super(Screening, self).get_context_data(**kwargs)
>>>
>>> # Fetch the sender_id for each unread message.
>>> # Count the number of times that the sender_id was included.
>>> # Then convert the list of tuples into a dictionary for quick
>>> lookup.
>>> sent_messages = dict(
>>> self.request.user.received_messages.filter(
>>> read_at__isnull=True
>>> ).values('sender_id').annotate(
>>> messages_sent=Count('sender_id')
>>> ).values_list('sender_id', 'messages_sent')
>>> )
>>>
>>> form = ScreeningForm(self.request.GET)
>>>
>>> if form.is_valid():
>>> job_candidates = form.filter_job_candidates(self.object)
>>> else:
>>> # Fallback, since the form will always be valid unless
>>> someone tampered with the form parameters manually
>>> job_candidates = self.object.applied_to.all().
>>> order_by('candidate')
>>>
>>> candidates = []
>>> for candidate in job_candidates:
>>> candidate.messages_sent = sent_messages.get(candidate.
>>> candidate.user.id)
>>> candidates.append(candidate)
>>> context['candidate_list'] = candidates
>>> context['form'] = form
>>>
>>> return context
>>>
>>>
>>> On Sat, Feb 21, 2015 at 9:57 AM, Ronaldo Bahia 
>>> wrote:
>>>
 Hi Vijay,

 Thanks for your response.
 I've just updated my question in stackoverflow 'cause I forgot to show
 my forms.

 What I need is to enable a user (company) to filter results
 (candidates) based on forms selection (candidates' status and candidates'
 haircolors)

 And I don't know how to make this in my detailview.

 See the link: http://stackoverflow.com/questions/28637326/how-to-
 filter-results-using-forms-in-django-best-approach

 Thanks

 Em sábado, 21 de fevereiro de 2015 00:33:34 UTC-2, Vijay Khemlani
 escreveu:
>
> It's not clear what's the purpose of the view you are showing. ¿Is it
> supposed to display a form with "haircolor" and "status" fields and filter
> the results it displays based on that?
>
> In that case you can declare a form:
>
> from django import forms
>
> class ScreeningForm(forms.Form):
> haircolor = forms.ChoiceField(choices=CandidateLook.HAIRCOLOR_
> CHOICES)
> status = 

Re: Edx LDAP Auth setting

2015-02-23 Thread 'Yip Terence' via Django users
Hi L,
 
Actually, I has been input the LDAP string in 
/edx/app/edxapp/edx-platform/lms/envs/common.py.  But there a two 
problems after the configuration. Firstly, the script can't get the 
%user value I need to hardcode the username / email in the connection 
string than I can login to edx.  Secondly, can't to create an user profile 
when first login.
 
Is it need to modify the views.py and urls.py file for collect the %user 
value and create the user profile?
 
 
I have 2 version django in edx.
./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.3/django/bin/django-admin.py
./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.2.5/django/bin/django-admin.py
 
 
ldap_auth_ldap:
How can I find the version?  I using the apt-get to install the package.
 
The search settings.py result.
---Setttings.py---
./edx/app/xqueue/xqueue/xqueue/settings.py
./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
./edx/app/xqueue/venvs/xqueue/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
./edx/app/edxapp/edx-platform/common/test/acceptance/pages/studio/settings.py
./edx/app/edxapp/edx-platform/lms/djangoapps/django_comment_client/settings.py
./edx/app/edxapp/edx-platform/lms/lib/comment_client/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_countries/tests/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/method_override/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/example/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django/conf/project_template/project_name/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/dealer/contrib/django/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/api/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/django_extensions/settings.py
./edx/app/edxapp/venvs/edxapp/lib/python2.7/site-packages/appconf/tests/settings.py
./edx/app/edxapp/venvs/edxapp/src/django-pipeline/pipeline/conf/settings.py
./edx/app/edxapp/venvs/edxapp/src/django-pipeline/tests/settings.py
./edx/app/edxapp/venvs/edxapp/src/edx-val/edxval/settings.py
./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.3/django/conf/project_template/settings.py
./edx/app/edxapp/venvs/edxapp/src/lettuce/tests/integration/lib/Django-1.2.5/django/conf/project_template/settings.py
./usr/local/lib/python2.7/dist-packages/django/conf/project_template/project_name/settings.py
 
Thank you very much for your assistance.
 
Thanks and Regards,
Terence Yip

Lachlan Musicman於 2015年2月10日星期二 UTC+8下午12時22分50秒寫道:

> Yip, EDX looks complex - can you search for the settings file and report 
> back? 
>
> AuthLDAP is annoying, but it does work - I've used it successfully 
> against an AD backend. The error messages are important to read. 
>
> But first, find your settings file. 
>
> You will need to provide us with more info too. What's not working? 
> What have you put into the settings file? What version of django is 
> EDX using, and does django_auth_ldap provide support for that django 
> version, what error messages are you getting? Can you attach to the 
> ldap server from just the django shell (ie, are the username and 
> password etc correct)? 
>
> cheers 
> L. 
> -- 
> "This is a profound psychological violence here. How can one even 
> begin to speak of dignity in labor when one secretly feels one's job 
> should not exist?" 
>
> On the Phenomenon of Bullshit Jobs, David Graeber 
> http://strikemag.org/bullshit-jobs/ 
>
>
> On 10 February 2015 at 15:00, 'Yip Terence' via Django users 
>  wrote: 
> > Dear All, 
> > 
> > I have been installed the open edx and django_auth_ldap package 
> > (http://code.edx.org/) in our environment.  However, I'm not successful 
> to 
> > config the Auth with LDAP.  Could anyone could provide the guide to me? 
>  I 
> > don't know where is the settings.py file path in open edx. 
> > 
> > Please help. 
> > 
> > Thanks and Regards, 
> > Terence Yip 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/65f0df30-c315-401c-9711-9228779a65ed%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 

Re: How to handle model constants

2015-02-23 Thread Mike Dewhirst

On 23/02/2015 5:23 PM, Frankline wrote:

Hi all,

I am getting confused regarding the use of constants and would be keen to
know how the rest of you handle constants in your models. Ofcourse I could
handle it easily similar to how it has been handled here:
https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.Field.choices



I have many many constants which are used across a number of modules and 
apps.


I store them in the __init__.py file of the namespace in which they are 
used. Sensible naming of constants is vital of course and I'm careful to 
store them alphabetically so I can find them easily enough scrolling 
quickly through the file.


At the top of my modules I say ...

from  import CONST1, CONST2 etc

Works for me

Mike


But I wanted to put the constants in a separate class on their own. This is
what I hav so far:

models.py

class TaskStatus(models.Model):

 CANCELLED = 0
 REQUIRES_ATTENTION = 1
 WORK_IN_PROGRESS = 2
 COMPLETE = 3

 STATUS_TYPES = (
 (CANCELLED, 'Cancelled'),
 (REQUIRES_ATTENTION, 'Requires attention'),
 (WORK_IN_PROGRESS, 'Work in progress'),
 (COMPLETE, 'Complete'),
 )

 status = models.IntegerField(choices=STATUS_TYPES,
default=REQUIRES_ATTENTION)
 class Task(models.Model):
 status = models.ManyToManyField(TaskStatus,
default=TaskStatus.REQUIRES_ATTENTION)


In my case, a Task can have one or more TaskStatus. I do not wish to store
the TaskStatus in the database since they are simply constants.

Does anyone have a better way of how I can approach this?



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