Saturday, May 31, 2014

Re: prevent from backward in form

Hi Russ,
thank you so much for reply.
But I tested ago the form with  HTTPResponseRedirect and this don't work for me.
I decide to save csrf token in my models and check it in view and this solution work for me.
Best Regards,
Hallaji


On Sun, Jun 1, 2014 at 5:24 AM, Russell Keith-Magee <russell@keith-magee.com> wrote:
Hi Ali,

If you follow the pattern laid out in Django's documentation, you'll avoid the problem:

https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

The key part is that on success, the form processing issues a HTTPResponseRedirect. This prevents the back button from repopulating the form - even if it redirects to the same URL that you used to submit the form in the first place.

Yours,
Russ Magee %-)


On Sun, Jun 1, 2014 at 12:23 AM, Ali hallaji <ali.hallaji1@gmail.com> wrote:
I submit the form and when I resend or backward the my webpage, my form dose appear again and save data in duplicate.
please help me for solving this issue.

--
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+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/KoackP6Jeaw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/CAJxq84_WHOYvREdAzPhfznu2nxNR0u9xJJbGzhqsTwP-aW6Fbg%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+unsubscribe@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/CAP0yp48ohEa6wEustBpmTsycDEjQS10KE1ej3pc1BCVUitWOtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: prevent from backward in form

Hi Ali,

If you follow the pattern laid out in Django's documentation, you'll avoid the problem:

https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view

The key part is that on success, the form processing issues a HTTPResponseRedirect. This prevents the back button from repopulating the form - even if it redirects to the same URL that you used to submit the form in the first place.

Yours,
Russ Magee %-)


On Sun, Jun 1, 2014 at 12:23 AM, Ali hallaji <ali.hallaji1@gmail.com> wrote:
I submit the form and when I resend or backward the my webpage, my form dose appear again and save data in duplicate.
please help me for solving this issue.

--
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+unsubscribe@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/7841d7d1-f282-4530-9516-bf019c6a067f%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+unsubscribe@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/CAJxq84_WHOYvREdAzPhfznu2nxNR0u9xJJbGzhqsTwP-aW6Fbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Seems to be a bug in makemessages management command

Hi Андрей,

Unless you can reproduce this with Django's own template language -- which *doesn't* support multiline content, it's not a bug. However, Jinja2 use is common in the community, so if we can apply a patch that improves Jinja2 support, then we'd certainly consider that patch.

Yours,
Russ Magee %-)

On Sat, May 31, 2014 at 11:46 PM, Андрей Меньков <nothingelsematters7@gmail.com> wrote:
I'm using Jinja2. There _() construct is equivalent to ugettext().
I tried 'blocktrans' tag - it really works, that right).

But what to do with Jinja2 templates? Or may be this is not a bug but some sort of improvement for compatibility with Jinja2?


On 31 May 2014 15:20, Ramiro Morales <cramm0@gmail.com> wrote:
On Sat, May 31, 2014 at 7:50 AM, Андрей Меньков
<nothingelsematters7@gmail.com> wrote:
>
> I thing the problem is in function django.utils.translation.templatize. It's
> implementation could be found in django.utils.translation.trans_real module.
>
> From docstring for it:
>
> Turns a Django template into something that is understood by xgettext. It
>     does so by translating the Django translation tags into standard gettext
>     function invocations.
>
> Function calling results:
>>> templatize(" {{ _('kfhdsajfkh') }} ")
>>> ('kfhdsajfkh')
>
>>> templatize(""" {{ _(''' abcdefg
>                             hhjkfhsdajfk
>                             fsdauyuirywer
>                        ''') }}
>
>               """)
>>>  XX XXXXX XXXXXXX
>                          XXXXXXXXXXXX
>                          XXXXXXXXXXXXX
>                      XXXX XX
>
>
> So it can be seen that templatize function marks multiline strings as not
> needed to translate.

As Russ says, it's not clear to me if the _() template construct you
are using is from Django i18n or from Jinja.

Django template tags (including trans) aren't multi-line. There is a
ongoing discussion about this.

If you use the Django blocktrans template tag, multi-line literals are
perfectly suported by templatize():

In [1]: from django.utils.translation import templatize

In [2]: templatize("""{% blocktrans %}foo
bar
baz
{% endblocktrans %}""")
Out[2]: " gettext(u'foo\\nbar\\nbaz\\n') SSS\nSSS\nSSS\n"

In [3]:

--
Ramiro Morales
@ramiromorales

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/q2KNl0Bha6o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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.

--
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+unsubscribe@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/CAL40Fptj%3DuHZ9qOdCgRpLBdsJw93%3DVEX7JCBO2BFzQuh_DV3NA%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+unsubscribe@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/CAJxq849_v0RPySp77j1k9cKHea5gTpp1Qwhq8Addxj0Y6BFxNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Save django queries for reuse

In my application a user can generate reports on multiple models using multiple criteria. I want to let the user save the queries(with the criteria). What is a good approach?

--
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+unsubscribe@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/112fdc6c-3707-4c96-87ff-6983bbd608f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django auth customing error

In your helpdesk app you have leftover references to auth.User. Replace all of them with something like this:

user = models.ForeignKey(settings.AUTH_USER_MODEL)

K


On Saturday, May 31, 2014 6:25:28 AM UTC-7, Jackie wrote:
I want to custom the django auth app, since the default auth app can not meet our project's requierment. Then I figure it out on my own by checking the django document at here.https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#a-full-example. I tried to do that example exactly. Finally, I added AUTH_USER_MODEL = "intelic_auth.MyUser" setting in my settings.py. But I got this error below when I tried to run "python manage.py syncdb". I don't know why. I would be very appreciated if someone can help me figure it out.

CommandError: One or more models did not validate:    helpdesk.ticket: 'assigned_to' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.followup: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.savedsearch: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.usersettings: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.ticketcc: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

--
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+unsubscribe@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/d8408fff-38e1-4ed7-9c85-5e8d3ee610f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

UnboundLocalError - How do I convert my pandas DataFrame into a list that Django can work with?

Exception Type: UnboundLocalError
Exception Value:
local variable 'list' referenced before assignment


Hi, I'm trying to convert my pandas DataFrame into a simple list in Views.py and send it to template.  But Django complains and I don't know how to make it happy.  Because when I do "global list" then I get the below error instead which says that I cannot use variable list when I google for it.  How do I convert my DataFrame into a list that Django can work with?


Exception Type: TypeError
Exception Value:
'list' object is not callable

#_______________________________________________________________________________
...
...
from django.db.models import Count

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
pd.set_option('max_columns', 50)

from magazine.models import Publication, Article
#_______________________________________________________________________________

def index(request):

    # Publication list
    publications = Publication.objects.all()

    # Articles list with Many-to-many relationship to Publication table
    # for counting how many publications each article was in.
    articles = Article.objects.all().annotate(num_publications=Count('publications'))

    # There is a total of 5 Publications in the database.
    total_publicists = Publication.objects.all().count()

#--------------------------------------------
### Leo magic
    articles_list = [(article, float(article.num_publications)/total_publicists*100) for article in articles]
#--------------------------------------------

    articles_list3 = [(article.id, article, float(article.num_publications)/total_publicists*100) for article in articles]

    df = pd.DataFrame(articles_list3)

    df['FRACTION'] = df[2]-df[0]

    #global list
    b = map(list, df.values)


...
...

    context = {'articles_list':articles_list, 'publications':publications,
               'total_publicists':total_publicists, 'articles':articles,
               'uncommented_publications':uncommented_publications,
               'articles_list2':articles_list2, 'b':b}
    return render(request, 'magazine/index.html', context)
#_______________________________________________________________________________



--
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+unsubscribe@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/202816f5-3039-4386-90a3-5e82ec1a5108%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Enumerating objects in foreign key in the admin

Brilliant, thank you!

On May 30, 2014, at 10:23 PM, Russell Keith-Magee <russell@keith-magee.com> wrote:

> Hi Christophe,
>
> The built-in way to handle this is to add a `raw_id_fields` declaration to your ModelAdmin or Inline definition. This will replace the pulldown select widget (populated with every possible value) with a single text input that stores the primary key of the related object, plus a popup that makes it easy (well... easier) to find the right PK.
>
> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields
>
> Of course, a custom widget might give you a better UI, but if you're just looking to make it work and not drag the rendering of the admin UI page to a crawl, it works.
>
> Yours,
> Russ Magee %-)
>
> On Sat, May 31, 2014 at 1:17 PM, Christophe Pettus <xof@thebuild.com> wrote:
> Right now, when one has a foreign key field in a detail page in the admin, it appears to enumerate the objects (one at a time) in order to build the pop-up. Obviously, if the other side of the foreign key relationship has a lot of entries, this can be a problem. Short of doing a different, custom widget, is there a way to avoid this?
> --
> -- Christophe Pettus
> xof@thebuild.com
>
> --
> 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+unsubscribe@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/DBC6EF68-4DE3-432B-9237-D3973D80825F%40thebuild.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+unsubscribe@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/CAJxq84-ZxjTnJD%2B0jVGkYstK%3DeHV-nbj0gXYOmkCE_%2B7VnHgeQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--
-- Christophe Pettus
xof@thebuild.com

--
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+unsubscribe@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/0DBAA859-A9B9-4BCA-B8A5-B5B60EB0F911%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.

Re: Django Template - problema

It worked. Thank you very much


2014-05-31 4:33 GMT-03:00 Kelvin Wong <wongo888@gmail.com>:
At the very top of the models.py file add:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

I'm not sure this will work, but it might.

K



On Friday, May 30, 2014 8:35:58 PM UTC-7, ebrockes wrote:
Problem solved by replacing on models.py:

TIPO_CONJUGE = (
        ('CA', _('Casados')),
        ('UE', _('União estável')),
        ('OU', _('Outros')),
    )

by

TIPO_CONJUGE = (
        ('CA', _('Casados')),
        ('UE', _('Uniao estavel')),
        ('OU', _('Outros')),
    )

I'll see how to solve this issue. Any clues?


2014-05-31 0:11 GMT-03:00 Erick Brockes <ebro...@gmail.com>:
Kevin, Thank you.

If you don't mind, I'm kind of new in django.

I've got the following response in the browser:

{'tipo_conjuge': <django.forms.fields.TypedChoiceField object at 0xb4dcb7ec>}

Could you help me out on how to proceed?


2014-05-30 18:45 GMT-03:00 Kelvin Wong <wong...@gmail.com>:

In relacaoconjugetipouniao_form.html

Add this tag...then refresh...

{{ form.fields }}

Should give you more info about what fields are in the form and what widget they are using.

ie. 'tipo_conjuge': django.forms.fields.TypedChoiceField object

Also check your html source in a browser. Sometimes CSS mistakes hide things.

K


On Friday, May 30, 2014 7:40:01 AM UTC-7, ebrockes wrote:
I have the following problem. The field "tipo_conjuge" is not showing as I wanted. Could somebody tell me what is the problem?

Best regards,
Erick


url. py

...
url(r'relacao/(?P<conjuge>\d+)/$', login_required(CreateTipoRelacaoView.as_view()), name='cadastrarRelacaoTipo'),
...


views.py

...
class CreateTipoRelacaoView(CreateView):
    model = RelacaoConjugeTipoUniao
    fields = ['tipo_conjuge','data_inicio','data_fim']

    def form_valid(self, form):
        relacao = get_object_or_404(RelacaoConjuge, id=self.kwargs['relacao'])
        form.instance.relacao = relacao
        return super(CreateTipoRelacaoView, self).form_valid(form)


models.py

class RelacaoConjugeTipoUniao(models.Model):

    TIPO_CONJUGE = (
        ('CA', _('Casados')),
        ('UE', _('União estável')),
        ('OU', _('Outros')),
    )

    tipo_conjuge = models.CharField(_('Tipo'), max_length=2, choices=TIPO_CONJUGE, blank=False, null=False)
    data_inicio = models.DateField(_('Data de início'))
    data_fim = models.DateField(_('Data de término'))
   ...


relacaoconjugetipouniao_form.html

{% extends 'pessoa/base_voltar.html' %}
{% block content %}
    <form id="formulario" action="" method="POST">{% csrf_token %}
        {{ form.non_field_errors }}
            <div class="fieldWrapper">
            {{ form.tipo_conjuge.errors }}
            <label for="tipo_conjuge">Tipo de União:</label><br/>
            {{ form.tipo_conjuge }}
        </div><br/>
        <div class="fieldWrapper">
            {{ form.data_inicio.errors }}
            <label for="data_inicio">Data de início:</label><br/>
            {{ form.data_inicio }}
        </div><br/>
        <div class="fieldWrapper">
            {{ form.data_fim.errors }}
            <label for="data_fim">Data de término:</label><br/>
            {{ form.data_fim }}
        </div><br/>
        <input type="submit" value="Salvar" class="button">
        <input type="reset" value="Cancelar" class="button">
    </form>
    <br/>
    <a href="#">Voltar</a>
{% endblock content %}

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


--
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+unsubscribe@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/e8e23e48-3b52-42bd-983d-cd47f92d63ac%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+unsubscribe@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/CALUDr%2B2aFtYHMPJp4xWPLH7jKWyCkWM8FTp4oFrk6Le4_CwYHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

prevent from backward in form

I submit the form and when I resend or backward the my webpage, my form dose appear again and save data in duplicate.
please help me for solving this issue.

--
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+unsubscribe@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/7841d7d1-f282-4530-9516-bf019c6a067f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

UpdateView, ModelForm - form not redirecting problem

Hello,

I have the following situation.

If I don't refernce a ModelForm in my UpdateView class, the update process works correctly. When I reference the ModelForm in order to customize the fields, the form do not works correctly (do not redirect to the address specified).

forms.py

class PessoaForm(forms.ModelForm):
    dia_nascimento = forms.ChoiceField(choices=[(x, x) for x in range(1, 32)], required=False)
    mes_nascimento = forms.ChoiceField(choices=[(x, x) for x in range(1, 13)], required=False)
    ano_nascimento = forms.CharField(max_length=4, widget=forms.TextInput(attrs={'size':'3'}), required=False)
    dia_falecimento = forms.ChoiceField(choices=[(x, x) for x in range(1, 32)], required=False)
    mes_falecimento = forms.ChoiceField(choices=[(x, x) for x in range(1, 13)], required=False)
    ano_falecimento = forms.CharField(max_length=4, widget=forms.TextInput(attrs={'size':'3'}), required=False)

    class Meta:
        model = Pessoa

--------
models.py

class Pessoa(models.Model):

    SEXO = (
                ('M', _('Masculino')),
                ('F', _('Feminino')),
        )

    nome = models.CharField(_('nome'), max_length=100, null=False, blank=False)
    sobrenome = models.CharField(_('sobrenome'), max_length=300, null=False, blank=False)
    sobrenome_casada = models.CharField(_('sobrenome casada'), max_length=300, null=True, blank=True)
    falecido = models.BooleanField(default=False)
    dia_nascimento = models.PositiveSmallIntegerField(_('dia de nascimento'), null=True, blank=True)
    mes_nascimento = models.PositiveSmallIntegerField(_('mês de nascimento'), null=True, blank=True)
    ano_nascimento = models.CharField(max_length=4, null=True, blank=True, validators=[
            RegexValidator(
                r'^[0-9]*$',
                _('Somente números são permitidos.'),
                'Invalid Number'
            ),
        ],
    )
    ...
    dia_falecimento = models.PositiveSmallIntegerField(_('dia de falecimento'), null=True, blank=True)
    mes_falecimento = models.PositiveSmallIntegerField(_('mês de nascimento'), null=True, blank=True)
    ano_falecimento = models.CharField(max_length=4, null=True, blank=True, validators=[
            RegexValidator(
                r'^[0-9]*$',
                _('Somente números são permitidos.'),
                'Invalid Number'
            ),
        ],
    )
    ...   
    class Meta:
        ordering = ['sobrenome', 'nome']
        verbose_name = _(u'pessoa')
        verbose_name_plural = _(u'pessoas')
   
    def __unicode__(self):
        if(self == None):
            return ""
        else:
            return self.nome + " " + self.sobrenome


-----
views.py

class PessoaUpdate(UpdateView):
    model = Pessoa
    fields = ['nome','sobrenome','sobrenome_casada','sexo','dia_nascimento','mes_nascimento','ano_nascimento','falecido', 'dia_falecimento','mes_falecimento','ano_falecimento']
    form_class = PessoaForm

    def get_success_url(self):
        return "/pessoa/nascimento/"+str(self.kwargs['pk'])+"/"


----------

Does anyone have a clue?

Thanks in advance.

Erick

--
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+unsubscribe@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/CALUDr%2B2vb7kbFGJdnGtP_h%3De50ONvn%2B2x1TjDr95%3D2mV6gFruw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Seems to be a bug in makemessages management command

I'm using Jinja2. There _() construct is equivalent to ugettext().
I tried 'blocktrans' tag - it really works, that right).

But what to do with Jinja2 templates? Or may be this is not a bug but some sort of improvement for compatibility with Jinja2?


On 31 May 2014 15:20, Ramiro Morales <cramm0@gmail.com> wrote:
On Sat, May 31, 2014 at 7:50 AM, Андрей Меньков
<nothingelsematters7@gmail.com> wrote:
>
> I thing the problem is in function django.utils.translation.templatize. It's
> implementation could be found in django.utils.translation.trans_real module.
>
> From docstring for it:
>
> Turns a Django template into something that is understood by xgettext. It
>     does so by translating the Django translation tags into standard gettext
>     function invocations.
>
> Function calling results:
>>> templatize(" {{ _('kfhdsajfkh') }} ")
>>> ('kfhdsajfkh')
>
>>> templatize(""" {{ _(''' abcdefg
>                             hhjkfhsdajfk
>                             fsdauyuirywer
>                        ''') }}
>
>               """)
>>>  XX XXXXX XXXXXXX
>                          XXXXXXXXXXXX
>                          XXXXXXXXXXXXX
>                      XXXX XX
>
>
> So it can be seen that templatize function marks multiline strings as not
> needed to translate.

As Russ says, it's not clear to me if the _() template construct you
are using is from Django i18n or from Jinja.

Django template tags (including trans) aren't multi-line. There is a
ongoing discussion about this.

If you use the Django blocktrans template tag, multi-line literals are
perfectly suported by templatize():

In [1]: from django.utils.translation import templatize

In [2]: templatize("""{% blocktrans %}foo
bar
baz
{% endblocktrans %}""")
Out[2]: " gettext(u'foo\\nbar\\nbaz\\n') SSS\nSSS\nSSS\n"

In [3]:

--
Ramiro Morales
@ramiromorales

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/q2KNl0Bha6o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/CAO7PdF8%3DrNwR%3DOxAGs7TVv8NXA6c8Q%3DA5kD71eOb2mY8mWixCA%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+unsubscribe@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/CAL40Fptj%3DuHZ9qOdCgRpLBdsJw93%3DVEX7JCBO2BFzQuh_DV3NA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Django Wrong OUTER JOIN

Hi everyone,

I'm just starting with Django and I created the following queryset but I can't seem to make the JOIN connect to the one I've defined in my queryset values(..., 'user__uservote__event', ...)

My model declaration:


class UserVote(TimeStampedModel):
    event = models.ForeignKey('events.Event')
    fightchoice = models.ForeignKey('fights.FightChoice')
    user = models.ForeignKey(User)
 
class UserEvent(TimeStampedModel):
    event = models.ForeignKey('events.Event')
    user = models.ForeignKey('users.User')

My queryset:

user_season_events = UserEvent.objects\
    .filter(event__season=season_id, user=request.user.id, user__uservote__user=request.user.id)\
    .order_by('-event__event_on') \
    .select_related('event')\
    .values('event', 'user__uservote__fightchoice__points', 'user__uservote__event',
            'user__uservote__fightchoice__howitended', 'user__uservote__fightchoice__fighter') 

Return the following SQL: 

SELECT "users_userevent"."event_id", "fights_fightchoice"."points", "users_uservote"."event_id", "fights_fightchoice"."howitended_id", "fights_fightchoice"."fighter_id" 
FROM "users_userevent" 
INNER JOIN "events_event" ON ( "users_userevent"."event_id" = "events_event"."id" ) 
INNER JOIN "users_user" ON ( "users_userevent"."user_id" = "users_user"."id" ) 
LEFT OUTER JOIN "users_uservote" ON ( "users_user"."id" = "users_uservote"."user_id" ) 
LEFT OUTER JOIN "fights_fightchoice" ON ( "users_uservote"."fightchoice_id" = "fights_fightchoice"."id" ) 
WHERE ("events_event"."season_id" = 1 AND "users_userevent"."user_id" = 199 AND "users_uservote"."user_id" = 199 ) ORDER BY "events_event"."event_on" DESC

My issue is: 

I want:

LEFT OUTER JOIN "users_uservote" ON "users_user"."id" = "users_uservote"."user_id" )

to be (on events_event not users_user) like this:

LEFT OUTER JOIN users_uservote ON events_event.id = users_uservote.event_id

When I added 'user__uservote__event' to the values in my queryset should it not create it?

Thank you for you help.

--
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+unsubscribe@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/9c9ae9bc-b92a-4fd6-8f1f-15a03eb29469%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Django auth customing error

I want to custom the django auth app, since the default auth app can not meet our project's requierment. Then I figure it out on my own by checking the django document at here.https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#a-full-example. I tried to do that example exactly. Finally, I added AUTH_USER_MODEL = "intelic_auth.MyUser" setting in my settings.py. But I got this error below when I tried to run "python manage.py syncdb". I don't know why. I would be very appreciated if someone can help me figure it out.

CommandError: One or more models did not validate:    helpdesk.ticket: 'assigned_to' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.followup: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.savedsearch: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.usersettings: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.    helpdesk.ticketcc: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

--
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+unsubscribe@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/adb35607-168f-4b6d-a10f-00aaedadbec4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: TDD

You can red online for free this one http://chimera.labs.oreilly.com/books/1234000000754


2014-05-31 7:56 GMT-05:00 Jonathan Querubina <john.chronus@gmail.com>:
Guys,

Could anyone send me a link for a good tutorial on django TDD?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/21274350-53F1-489B-8546-159C6FF7ED10%40gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Jorge Andres Vergara Ebratt
#SoftwareDeveloper (Or at least trying to be)
@javebratt

--
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+unsubscribe@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/CAAeX05GJiX6H3Rs8_sBYNsB%2Bj5O8yXNa4vZ9JCyU9%3D3pWhjmsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

TDD

Guys,

Could anyone send me a link for a good tutorial on django TDD?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/21274350-53F1-489B-8546-159C6FF7ED10%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Seems to be a bug in makemessages management command

On Sat, May 31, 2014 at 7:50 AM, Андрей Меньков
<nothingelsematters7@gmail.com> wrote:
>
> I thing the problem is in function django.utils.translation.templatize. It's
> implementation could be found in django.utils.translation.trans_real module.
>
> From docstring for it:
>
> Turns a Django template into something that is understood by xgettext. It
> does so by translating the Django translation tags into standard gettext
> function invocations.
>
> Function calling results:
>>> templatize(" {{ _('kfhdsajfkh') }} ")
>>> ('kfhdsajfkh')
>
>>> templatize(""" {{ _(''' abcdefg
> hhjkfhsdajfk
> fsdauyuirywer
> ''') }}
>
> """)
>>> XX XXXXX XXXXXXX
> XXXXXXXXXXXX
> XXXXXXXXXXXXX
> XXXX XX
>
>
> So it can be seen that templatize function marks multiline strings as not
> needed to translate.

As Russ says, it's not clear to me if the _() template construct you
are using is from Django i18n or from Jinja.

Django template tags (including trans) aren't multi-line. There is a
ongoing discussion about this.

If you use the Django blocktrans template tag, multi-line literals are
perfectly suported by templatize():

In [1]: from django.utils.translation import templatize

In [2]: templatize("""{% blocktrans %}foo
bar
baz
{% endblocktrans %}""")
Out[2]: " gettext(u'foo\\nbar\\nbaz\\n') SSS\nSSS\nSSS\n"

In [3]:

--
Ramiro Morales
@ramiromorales

--
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+unsubscribe@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/CAO7PdF8%3DrNwR%3DOxAGs7TVv8NXA6c8Q%3DA5kD71eOb2mY8mWixCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

django models

please i need some legit answer please

we have in the models forexaple

class Book():

name = InputTextField
Autho = 


Please are there not more parmaters that can hel you to better define your model. Are there no library for models?

--
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+unsubscribe@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/cb57997d-ac3e-40a4-b7f8-791db1bbbb76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Seems to be a bug in makemessages management command

Hi, Russ.

Thank you for such a detailed response.
I think I have ever found the place where this really occurs. I was posted this message more for knowing if this really a bug or not (maybe I don't know something about template translation and multiline strings in them). 

I have used Jinja2 for template engine. But I think that at this level it's now important whether we use Django Template language or Jinja2, because both are later processed by xgettext with Python option specified.

I thing the problem is in function django.utils.translation.templatize. It's implementation could be found in django.utils.translation.trans_real module. 

From docstring for it:
Turns a Django template into something that is understood by xgettext. It
does so by translating the Django translation tags into standard gettext
function invocations.

Function calling results:
>> templatize(" {{ _('kfhdsajfkh') }} ")
>> ('kfhdsajfkh')

>> templatize(""" {{ _(''' abcdefg
hhjkfhsdajfk fsdauyuirywer ''') }}
""")
>> XX XXXXX XXXXXXX
XXXXXXXXXXXX XXXXXXXXXXXXX XXXX XX


So it can be seen that templatize function marks multiline strings as not needed to translate.

суббота, 31 мая 2014 г., 5:09:17 UTC+3 пользователь Russell Keith-Magee написал:
Hi Андрей,

On Fri, May 30, 2014 at 9:50 PM, Андрей Меньков <nothingel...@gmail.com> wrote:
May be it would better to post this to "Django developers" mailing list?

Possibly - if you think you've found a bug, django-developers is a better audience for that. django-users is a better audience if you're just unsure if you're using a command/API correctly. 
 
пятница, 30 мая 2014 г., 15:53:56 UTC+3 пользователь Андрей Меньков написал:
Django management command doesn't recognize multiline strings as strings to localize. So such strings don't appear in resulting django.po files after running command

For example for such a string

{code}
{{ _(''' fhsdafjkshdfjkasdhfksj
         ytyerwtuiwyertuiywert''') }}
{code}

I'm a little unclear what's going on here. Are you using Django templates, or Jinja2? Django's template language doesn't allow multi-line template tags, and _() isn't valid translation syntax in a Django template. 

If you're using Jinja2, then the source of the bug may be in whatever layer you're using to integrate Jinja2 templates into Django.
 
I might be the bug of GNU xgettext utility, because makemessages uses it to produce *.po files, but after running xgettext I became sure that the problem is in the makemessages command, not xgettext.

I ran xgettext using the following command

xgettext --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=pgettext_lazy:1c,2 --keyword=npgettext_lazy:1c,2,3 --from-code UTF-8 --add-comments=Translators --from-code utf-8 -d django -p ./output_dir -L Python temp_i18n_template.html

After running this command I got file output_dir/django.po with specified string inside it.

What I can do now? What do you think about this "bug" ?

P.S. It's my first attempt to contribute to Django somehow. So please do not judge strictly). I haven't found anywhere about this problem and about its' fixes too.

The make messages is really just a thin wrapper around xgettext; the command you issued manually seems to match pretty closely what Django's makemessages command should be doing. If you're not getting the right output from Django's management command, it possible you've found a bug. If I had to guess, it will be with the code that is discovering the templates that need to be processed, but it's impossible to say for sure without your code in front of me.

If you want to do some digging, the relevant code is in django/core/management/commands/makemessages.py. Most of the code in that file is dedicated to building a command line and executing a call to xgettext; it should be fairly straightforward to understand. If you *do* find a problem, please open a ticket and let us know; or follow up with a thread on the django-dev if you're uncertain if the problem is a bug in Django or your own usage.

Yours,
Russ Magee %-)

--
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+unsubscribe@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/b438471d-5a77-4340-bad5-f6e08258a414%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: check_password in contrib auth tries to update the database

Hello Suhrid,

On 30 May 2014, at 15:58, suhridsatyal@proteus-tech.com wrote:
> check_password method of AbstractBaseUser in django.contrib.auth.models tries to update the database.
> This causes problems when this code executes on a read-only slave database.
>
> def check_password(self, raw_password):
> def setter(raw_password):
> self.set_password(raw_password)
> self.save(update_fields=["password"])
> return check_password(raw_password, self.password, setter)

Yes, this is a feature, which enables upgrading of password hashing. When Django encounters a password that is hashed with an older hash, the setter will be called, which will save the password with the current preferred hash. This can only be done when the raw password is known, which can only happen while Django is checking the password.

I can see how this is an issue in your scenario. A solution I can come up with is to extend this user model[1], where you override only the model's check_password method. The setter parameter to check_password is optional, and if absent it will simply not upgrade passwords. However, the downside of this is of course, that passwords will not be upgraded if we add better hashers in the future.

[1] https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model

cheers,
Erik

--
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+unsubscribe@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/36C9DAD5-F4EF-4EF1-AA22-95997FE6FA3B%40solidlinks.nl.
For more options, visit https://groups.google.com/d/optout.

Re: Need help my first Django app

https://docs.djangoproject.com/en/1.6/intro/tutorial01/

K

On Saturday, May 31, 2014 12:06:20 AM UTC-7, Mamdou Attallah wrote:
Since I have never delveoped any Django app before I need to find an easy tutorial to kick start my first app
I am using free trial of py charm
thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/2593e51e-f3bb-46dc-8c8f-f450bede7d9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.