Re: Generate different querysets depending of the website language

2016-03-26 Thread Daniel Chimeno
Hello,

If you are able to change the schema I would suggest you to use 
modeltranslation [https://github.com/deschler/django-modeltranslation],
also the source code of that app can help you in order to take an specific 
approach to your project.

About the URL's, if you use i18urls, it has priority over the http headers 
[https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#module-django.conf.urls.i18n]
 
(Not confirmed, but was true last time I checked it)


Hope it helps.

El sábado, 26 de marzo de 2016, 20:43:09 (UTC+1), Mathieu Poussin escribió:
>
> Hello,
>
> I have an issue, I am creating a website that will be available in many 
> languages, sharing the same database.
> Most models have a "language" attribute that is the 2 letters from the 
> language code (en, es, fr, etc.).
>
> I am trying to find a way to show the correct content per language.
>
> I tried many things, creating a custom manager :
>
> from django.utils.translation import get_language, get_language_info
> from django.db import models
>
> class PerLanguageManager(models.Manager):
> def get_queryset(self):
> if get_language():
> return super(PerLanguageManager, self).get_queryset().filter(
> language=get_language_info(get_language())['code'])
> else:
> return super(PerLanguageManager, self).get_queryset()
>
>
> Or overriding get_queryset using another method : (The language is always 
> present in the url as /en/ or /es/) 
>
> class RecipeIndexView(generic.ListView):
> paginate_by = 10
>
> def get_queryset(self):
> return 
> Recipe.objects.filter(language=get_language_from_request(self.request, 
> check_path=False))
>
> But nothing work, I always get the default configured language (even if 
> with the debug toolbar tell me the site is in another language, and all the 
> translations are correctly done in the language specified in the URL, I 
> always get the default language from the queries...)
>
> I'm using a specific middleware to ignore the language specified in the 
> browser to only use the language specified in the URL :
> class ForceDefaultLanguageMiddleware(object):
> """
> Ignore Accept-Language HTTP headers
>
> This will force the I18N machinery to always choose 
> settings.LANGUAGE_CODE
> as the default initial language, unless another one is set via 
> sessions or cookies
>
> Should be installed *before* any middleware that checks 
> request.META['HTTP_ACCEPT_LANGUAGE'],
> namely django.middleware.locale.LocaleMiddleware
> """
> def process_request(self, request):
> if 'HTTP_ACCEPT_LANGUAGE' in request.META:
> del request.META['HTTP_ACCEPT_LANGUAGE']
>
>
> Any idea of how to make this work ? What is the good way to do this ?
>
> Thank you.
> Mathieu
>
>

-- 
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/d6c35903-a95b-4117-bd75-30966ed56fd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django tutorial part 3 - question_id vs question.id

2016-03-26 Thread Acetone
Cool, I can try those to see how it works.  Thank you.

On Saturday, March 26, 2016 at 7:04:13 AM UTC-7, jorr...@gmail.com wrote:
>
> I believe Django lets you access the pk field of a table (which is created 
> automatically unless you define it explicitly on your model) in multiple 
> ways: self.pk, self.id, and self._id. Someone correct me if 
> I'm wrong.

-- 
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/109039dc-8dac-41a3-8519-f433e812d7ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Deploy Django to Heroku - Push rejected

2016-03-26 Thread Bernardo Garcia


I am trying deploy my Django application to heroku and I get an error when 
I perform git push heroku master command


My structure directory is the following





And the content of requirements/production.txt is:

-r base.txt
gunicorn==19.4.5
dj-database-url==0.4.0


requirements/base.txt have this content:


Django==1.9.2
djangorestframework==3.3.2
Pillow==3.1.1
psycopg2==2.6.1
Markdown==2.6.5
django-filter==0.12.0
django-storages-redux==1.3
django-suit==0.2.16
django-boto==0.3.9
django-multiselectfield==0.1.3


The process that I am perform for deploy to my app to heroku is the 
following and the error is push rejected:


(uleague) ➜  pickapp git:(master) ✗ heroku create fuupbol --buildpack 
heroku/python
Creating fuupbol... done, stack is cedar-14
Setting buildpack to heroku/python... done
https://fuupbol.herokuapp.com/ | https://git.heroku.com/fuupbol.git
(uleague) ➜  pickapp git:(master) ✗ git remote -v
heroku  https://git.heroku.com/fuupbol.git (fetch)
heroku  https://git.heroku.com/fuupbol.git (push)
origin  https://bgarc...@bitbucket.org/bgarcial/pickapp.git (fetch)
origin  https://bgarc...@bitbucket.org/bgarcial/pickapp.git (push)
(uleague) ➜  pickapp git:(master) ✗ git push heroku master
Counting objects: 195, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (92/92), done.
Writing objects: 100% (195/195), 516.34 KiB | 0 bytes/s, done.
Total 195 (delta 93), reused 195 (delta 93)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -> Using set buildpack heroku/python
remote: 
remote:  ! Push rejected, failed to detect set buildpack heroku/python
remote: More info: 
https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote: 
remote: Verifying deploy
remote: 
remote: !   Push rejected to fuupbol.
remote: 
To https://git.heroku.com/fuupbol.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/fuupbol.git'
(uleague) ➜  pickapp git:(master) ✗


I follow the getting started tutorial for deploy in heroku web page 

 and 
in their samples, the requirements.txt and the settings.py were as a 
isolated files in the root project and not nested under folders as a 
settings/ folder or a requirements /folder

This have related for my error of push rejected ?



-- 
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/5d683621-9fb3-4ddc-8f5a-58297350b4f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Generate different querysets depending of the website language

2016-03-26 Thread Mathieu Poussin
Hello,

I have an issue, I am creating a website that will be available in many 
languages, sharing the same database.
Most models have a "language" attribute that is the 2 letters from the 
language code (en, es, fr, etc.).

I am trying to find a way to show the correct content per language.

I tried many things, creating a custom manager :

from django.utils.translation import get_language, get_language_info
from django.db import models

class PerLanguageManager(models.Manager):
def get_queryset(self):
if get_language():
return super(PerLanguageManager, self).get_queryset().filter(
language=get_language_info(get_language())['code'])
else:
return super(PerLanguageManager, self).get_queryset()


Or overriding get_queryset using another method : (The language is always 
present in the url as /en/ or /es/) 

class RecipeIndexView(generic.ListView):
paginate_by = 10

def get_queryset(self):
return 
Recipe.objects.filter(language=get_language_from_request(self.request, 
check_path=False))

But nothing work, I always get the default configured language (even if 
with the debug toolbar tell me the site is in another language, and all the 
translations are correctly done in the language specified in the URL, I 
always get the default language from the queries...)

I'm using a specific middleware to ignore the language specified in the 
browser to only use the language specified in the URL :
class ForceDefaultLanguageMiddleware(object):
"""
Ignore Accept-Language HTTP headers

This will force the I18N machinery to always choose 
settings.LANGUAGE_CODE
as the default initial language, unless another one is set via sessions 
or cookies

Should be installed *before* any middleware that checks 
request.META['HTTP_ACCEPT_LANGUAGE'],
namely django.middleware.locale.LocaleMiddleware
"""
def process_request(self, request):
if 'HTTP_ACCEPT_LANGUAGE' in request.META:
del request.META['HTTP_ACCEPT_LANGUAGE']


Any idea of how to make this work ? What is the good way to do this ?

Thank you.
Mathieu

-- 
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/5988f3dc-1a46-4638-bee8-ab367e9eed33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django python devs hang out @HanaHaus Palo Alto CA

2016-03-26 Thread Leandro Barbosa
Do you need help with any project?


Em sexta-feira, 25 de março de 2016 20:25:52 UTC-3, Manfred Neustifter 
escreveu:
>
> any django python devs wanna hang out @HanaHaus Palo Alto CA
> shoot us a msg
>

-- 
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/9f5aa11a-5ade-4c15-b5b7-54be4ba690cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django tutorial part 3 - question_id vs question.id

2016-03-26 Thread jorrit787
I believe Django lets you access the pk field of a table (which is created 
automatically unless you define it explicitly on your model) in multiple ways: 
self.pk, self.id, and self._id. Someone correct me if I'm wrong.

-- 
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/53611858-55d3-4159-9f76-118af5b919df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django tutorial part 3 - question_id vs question.id

2016-03-26 Thread Acetone
Hello,

In trying to update my templates after I successfully finished part 3 of 
the tutorial, I found that I could write something like
You're looking at the results of question {{ question.id }}: "{{ 
question.question_text }}"
and get: You're looking at the results of question 1: "What's up?"

However, if I write
You're looking at the results of question {{ question.question_id }}: 
"{{ question.question_text }}"
I get: You're looking at the results of question : "What's up?"

I think the answer is that "The template system uses dot-lookup syntax to 
access variable attributes. In the example of {{ question.question_text }}, 
first Django does a dictionary lookup on the object question."  And "id" is 
an attribute of the question object.  But if that's the case, then why is 
"question_id" used everywhere else (views.py, urls.py)?  Is it because we 
*define* the question_id parameter by the pattern of the incoming request 
in views.py?  In other words, if we changed ?P to 
?P, then we would be writing our views like this:
def detail(request, my_favorite_number):
question = get_object_or_404(Question, pk=my_favorite_number)
but still referencing the id as {{ question.id }} in our templates?

Hmm, I think I might have answered my own question, but I definitely 
thought I had exhausted my resources before deciding to write this post. ; )

Thank you,

Kurt



-- 
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/5a9ecd2b-5c6c-46d5-8cfe-46206126c6c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Forms vs Angularjs

2016-03-26 Thread Daniel Hepper
Fabio,

if you are using Django 1.9, you can use the newly introduced disabled 
attribute on forms.Field, see 
https://docs.djangoproject.com/ja/1.9/ref/forms/fields/#disabled

On Tuesday, March 22, 2016 at 3:36:34 PM UTC+1, Fabio Caritas Barrionuevo 
da Luz wrote:
>
>
> self.fields[name].widget.attrs['disabled'] = 'disabled'
> self.fields[name].widget.attrs['readonly']=True
>
> is not make real readonly to field, because if user can edit the html on 
> client side, and remove disabled="disabled" and readonly input atributtes
>
> to problem of readonly fields, i currently use this:
>
>
> https://github.com/luzfcb/django-simple-history/blob/wip-generic-views2/simple_history/forms.py
>
>
> I prevent it here 
> https://github.com/luzfcb/django-simple-history/blob/wip-generic-views2/simple_history/forms.py#L24
>
> Usage:
>
> class FooBar(models.Model):
> foo = models.TextField(blank=True)
> bar = models.TextField(blank=True)
>
> class MyFooBarForm(forms.ModelForm):
> class Meta:
> object = FooBar
> fields = ('foo', 'bar')
>
> class MyReadOnlyBarForm(ReadOnlyFieldsMixin, forms.ModelForm):
> readonly_fields = ('bar')
> class Meta:
> object = FooBar
> fields = ('foo', 'bar')
>
> my_all_field_readonly_foobarForm = new_readonly_form_class(MyFooBarForm)
>
> my_foo_field_readonly_foobarForm = new_readonly_form_class(MyFooBarForm, 
> readonly_fields=('foo',))
>
>
> I do not know if this is the best approach, but it was what I got so far.
>
>
>
>
>
> On Tue, Mar 22, 2016 at 10:57 AM, Gorkem Tolan  > wrote:
>
>> Actually I do to set permission to each field. A field in the form can be 
>> viewable and editable, only viewable, or hidden.  So if user has a 
>> permission to see the form, but edit some fields in the form, it gets very 
>> tricky especially for validation.
>> For example I used these statements to make readonly field :
>> self.fields[name].widget.attrs['disabled'] = 'disabled'
>> self.fields[name].widget.attrs['readonly']=True
>> Then the problem rises not to be able send disabled fields in the post. 
>>
>> On Tuesday, March 22, 2016 at 9:31:43 AM UTC-4, bobhaugen wrote:
>>>
>>> Maybe you already know this, but you can do a lot of form tinkering in 
>>> __init__, like so:
>>>
>>> def __init__(self, permissions_parameter=None, *args, **kwargs):
>>> super(FormName, self).__init__(*args, **kwargs)
>>> if permissions_parameter:
>>> #do a bunch of form tinkering
>>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/877bb8f8-4b59-4353-a0e5-99e95f55811b%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Fábio C. Barrionuevo da Luz
> Palmas - Tocantins - Brasil - América do Sul
>
> http://pythonclub.com.br/
>
> Blog colaborativo sobre Python e tecnologias Relacionadas, mantido 
> totalmente no https://github.com/pythonclub/pythonclub.github.io .
>
> Todos são livres para publicar. É só fazer fork, escrever sua postagem e 
> mandar o pull-request. Leia mais sobre como publicar em README.md e 
> contributing.md.
> Regra básica de postagem:
> "Você" acha interessante? É útil para "você"? Pode ser utilizado com 
> Python ou é útil para quem usa Python? Está esperando o que? Publica logo, 
> que estou louco para ler...
>
>

-- 
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/0fb74827-9766-49d4-bc14-57b5e7150162%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple subprocess help

2016-03-26 Thread Daniel Hepper
If I understand you correctly, you want to pipe the value of 
request.POST['post'] to the program run_pipeline.sh and store the output in 
a field of your instance.


You are calling subprocess.Popen incorrectly. It should be:

p = subprocess.Popen(['/path/to/run_pipeline.sh'], stdin=subprocess.PIPE, 
stdout=subprocess.PIPE)


Then pass in the input and read the output

(stdoutdata, stderrdata) = p.communicate()


Then save the data, e.g. in a field of your instance

instance.processed_data = stdoutdata

I suggest you first make sure to get the call to the subprocess working in 
a Python shell and then integrate it in your Django app.
Please note that creating a (potentially long-running) subprocess in a 
request is really bad practice and can lead to a lot of problems. The best 
practice is to delegate long-running tasks to a job queue. For Django, 
Celery  is probably most commonly used. 
There is a bit of setup involved, though.


Cheers,
Daniel

P.S.: I just answered this question on StackOverflow. I'm reposting my 
answer here hoping that it might help anyone else.

On Friday, March 25, 2016 at 7:03:10 PM UTC+1, Joshua Valdez wrote:
>
> Okay, so I have figured out that the subprocess is the module that I want 
> to use in this context and I have tried implementing some simple code based 
> on the documentation but I am getting an
>
> Exception Type: OSErrorException Value: [Errno 2] No such file or 
> directoryException Location: 
> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py
>  in _execute_child, line 1335.  
>
> A brief overview of what I'm trying to do:
>
> This is the code I have in views. Its intent is to take text input from 
> the model form, POST that to the DB and then pass that input into my script 
> which produces an XML file which is stored in another column in the DB. I'm 
> very new to django so I'm sorry if this is an simple fix, but I couldn't 
> find any documentation relating django to subprocess that was helpful.
>
> def queries_create(request):
> if not request.user.is_authenticated():
>return render(request, 'login_error.html')
>
>
> form = QueryForm(request.POST or None)
> if form.is_valid():
>   instance = form.save(commit=False)
>   instance.save()
>   p=subprocess.Popen([request.POST['post'], './path/to/run_pipeline.sh'])
>   p.save()
>
> context = {
>
>   "title":"Create",
>   "form": form,
>
> }
> return render(request, "query_form.html", context) 
>
> Model code snippet:
>
> class Query(models.Model):
>   problem/intervention = models.TextField()
>
>   updated = models.DateTimeField(auto_now=True, auto_now_add=False)
>   timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
>
>

-- 
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/c4f0fda6-beb5-41b6-8513-dd515677f0fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.