Re: Customised handling for wrong passwords entered in Login page in Django.

2016-05-03 Thread Arun S
Thanks Simon,

I could now do all kinds of Session logging by handling the signals.
Great Information.

Cheers
Arun.

On Tuesday, May 3, 2016 at 7:33:45 PM UTC+5:30, Simon Charette wrote:
>
> Hi Arun,
>
> If you only want to log failed login attempts I suggest you connect a 
> receiver to
> the user_login_failed signal[1] instead.
>
> Cheers,
> Simon
>
> [1] 
> https://docs.djangoproject.com/en/1.9/ref/contrib/auth/#django.contrib.auth.signals.user_login_failed
>
> Le mardi 3 mai 2016 06:01:59 UTC-4, Arun S a écrit :
>>
>> Hi,
>>
>> I was trying to add a Customised View to Handle Wrong Passwords entered 
>> by Users.
>>
>> As of now, Djangos Framework just outputs, "Invalid Username or Password" 
>> when a Wrong password is entered by the User.
>>
>> This doesnt allow much flexibility if some information such as Invalid 
>> Access needs to be Logged.
>> Thus it would be good to Redirect these into a Customized view where the 
>> Logging of such information can be done and then redirected back to the 
>> Login page with Error.
>>
>> Any Ideas on how easily this can be done ?
>>
>> I tried adding a View when a Wrong password is called but always ended up 
>> in the below Error:
>>
>>   File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", 
>> line 578, in reverse
>> return force_text(iri_to_uri(resolver._reverse_with_prefix(view, 
>> prefix, *args, **kwargs)))
>>   File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", 
>> line 495, in _reverse_with_prefix
>> (lookup_view_s, args, kwargs, len(patterns), patterns))
>> NoReverseMatch: Reverse for '' with arguments '()' and keyword arguments 
>> '{}' not found. 0 pattern(s) tried: []
>>
>>
>> The login.html looks as simple as this.
>> td>{{ form.password }}
>> {% if form.password.errors %}
>>   > class="error">You must specify a password.
>>   {% endif %}
>>   
>>
>> *{% if form.non_field_errors %}  > id="password_error_div" class="error">Invalid username or 
>> password.  {% endif %}*
>>   
>> In the Highlighted case, i would like to handle the Error, Log the 
>> information to a file required and return back to the page.
>>
>> Any Help on how this can be done would be great.
>> Thanks.
>>
>

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


Re: manipulate n insert field values

2016-05-03 Thread Shameema Mohsin
#Z value calculation
#
#step1: converting lat and long to int

latitude int = (latitude + 90) × 10^6
longitude int = (latitude + 180) × 10^6

#note 10^6 = 100 

We compute the Morton value for a spatial point P (x, y)
by interleaving the bits of x and y. For example, when x =
3(011 ) and y = 4(100), the Morton value for P is
100101 = 37 

#step2: convert int (base 10) to binary digits (base 2)
..?
#step3: interleave both values bits and compute z value
#take first bit from y cordinate  (longitude) : 1
#take first bit from x cordinate  (lat) : 0
#take 2nd bit from y cordinate  (longitude) :0
#take 2nd bit from x cordinate  (lat) : 1
#take 3rd bit from y cordinate  (longitude) : 0
#take 3rd bit from x cordinate  (lat) : 1

therefore z binary value is 100101 
and z value is 37

#this is the technique used to convert spatial 2D indexing to 1D to improve 
efficiency.

I do not know the python syntax. Kindly 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+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/11aa86cc-0a4d-41be-b759-9a2ac83099cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: manipulate n insert field values

2016-05-03 Thread Shameema Mohsin
#Z value calculation
#
#step1: converting lat and long to int

latitude int = (latitude + 90) × 10^6
longitude int = (latitude + 180) × 10^6

#note 10^6 = 100

We compute the Morton value for a spatial point P (x, y)
by interleaving the bits of x and y. For example, when x =
3(011 ) and y = 4(100), the Morton value for P is
100101 = 37

#step2: convert int (base 10) to binary digits (base 2)
..?
#step3: interleave both values bits and compute z value
#take first bit from y cordinate  (longitude) : 1
#take first bit from x cordinate  (lat) : 0
#take 2nd bit from y cordinate  (longitude) :0
#take 2nd bit from x cordinate  (lat) : 1
#take 3rd bit from y cordinate  (longitude) : 0
#take 3rd bit from x cordinate  (lat) : 1

therefore z binary value is 100101
and z value is 37

#this is the technique used to convert spatial 2D indexing to 1D to improve
efficiency.

I do not know the python syntax. Kindly help.





On Tue, May 3, 2016 at 3:22 PM, Erik Cederstrand 
wrote:

>
> > Den 3. maj 2016 kl. 02.45 skrev Shameema Mohsin  >:
> >
> >
> > Stil stuck with the z order calculation and usage of the property field.
> Kindly help. I am new to Django, only knows php well.
>
> Where are you stuck? Show your error messages, current non-working code
> and expected result, or describe your problem in more detail.
>
> I assume you have code to calculate the z order (I have no idea what it
> is). Otherwise, other forums would be better for help on this. Assuming
> that, you would do:
>
> def get_z_order(lat, long):
># Jiggle those numbers
>return z_order
>
>
> class Employees(models.Model):
>[...]
>@property
>def zval(self):
>return get_z_order(self.empLat, self.empLong)
>
>
> You can then access zval as if it was a model field.
>
> Erik
>
> --
> 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/8IzLt_0cO8Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0E25E884-F38C-4314-B2B3-0ADAF813253E%40cederstrand.dk
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Using django login functionality in a non django app

2016-05-03 Thread Larry Martell
So I have been working on this and I think I am very close. I have a
view /falcon_login/ and I have the @login_required decorator on it. It
returns user info in JSON. In my Qt app I invoke /falcon_login/ and
because the user is not logged in the django login page is brought up.
After they login my /falcon_login/ view code runs and returns the
JSON.

But here is my issue - from the Qt app I cannot get the response from
the the login page, so after the successful login I do a GET on the
/falcon_login/ - since they have just logged in I would expect my code
to run and return the JSON. But in my Qt app I don't get the JSON, I
get an empty response with a 302 return.

Looking in my server's log I see this:

GET /falcon_login/ => generated 0 bytes in 2 msecs (HTTP/1.1 302)
GET /accounts/login/?next=/falcon_login/ => generated 3409 bytes in 10 msecs
POST /accounts/login/ => generated 0 bytes in 128 msecs (HTTP/1.1 302)
GET /falcon_login/ => generated 29 bytes in 9 msecs (HTTP/1.1 200)
GET /falcon_login/ => generated 0 bytes in 1 msecs (HTTP/1.1 302)

So it seems that when my Qt code sends the get after the login django
does not think the user is logged in. So I'm wondering exactly how the
login_required decorator makes that determination. I looked at the
code and it uses is_authenticated(), which looks like it always
returns True. Yet it seems like it returns False in this case

I would think that immediately after logging in login_required would
return True.

What am I missing here?

On Wed, Apr 27, 2016 at 11:53 AM, Gergely Polonkai  wrote:
>
> I would create a separate view for this, like /falcon_login/, which could 
> give you a plain text result. But that’s totally up to you.
>
>
> Gergely Polonkai
> about.me/gergely.polonkai
>
> 2016-04-27 16:57 GMT+02:00 Larry Martell :
>>
>> Well, not really. I have managed to invoke my django login screen from
>> my Qt app, but after I log in, of course my django app comes up.
>>
>> What I would like is to pass in some parameter to the login screen
>> (which is easy), and then have my django app detect that and after
>> successfully or unsuccessfully logging in, return a token or error
>> code to the Qt app and not bring up the django app. But I'm not sure
>> how to do that.
>>
>> On Tue, Apr 26, 2016 at 9:27 AM, Gergely Polonkai  
>> wrote:
>> >
>> > That means you have to be able to do it via the API. The other solution is 
>> > to pop up a web view for these tasks. However, we are moving out from 
>> > Django field here, as this is getting more and more a falcon/UX-related 
>> > question.
>> >
>> >
>> > Gergely Polonkai
>> > about.me/gergely.polonkai
>> >
>> > 2016-04-26 14:19 GMT+02:00 Larry Martell :
>> >>
>> >> I need to support create user, change password, delete user and forgot 
>> >> password.
>> >>
>> >> On Tue, Apr 26, 2016 at 7:32 AM, Gergely Polonkai  
>> >> wrote:
>> >> >
>> >> >
>> >> > That’s not a big issue if you really communicate with Django via a 
>> >> > web-based API. If the user can’t log in, you can simply redirect them 
>> >> > to a web page. I don’t see the need for user admin functions, though.
>> >> >
>> >> >
>> >> > Gergely Polonkai
>> >> > about.me/gergely.polonkai
>> >> >
>> >> > 2016-04-26 13:10 GMT+02:00 Larry Martell :
>> >> >>
>> >> >> Well, the issue with simply implementing auth, is that we'd need to
>> >> >> not only implement login, which is easy, but also forgot password, and
>> >> >> all the user admin functions. Since we have that already with django I
>> >> >> want to leverage that and not reinvent the wheel.
>> >> >>
>> >> >> On Tue, Apr 26, 2016 at 2:29 AM, Gergely Polonkai 
>> >> >>  wrote:
>> >> >> > Now I somewhat understand what falcon is, I suggest that you simply
>> >> >> > implement auth on you web app (it seems to me there is none or 
>> >> >> > little right
>> >> >> > now. Of course, you don't have to protect all iour views, or you may 
>> >> >> > want to
>> >> >> > display a different dataset, but that's another topic.
>> >> >> >
>> >> >> > When that is done, you have to do two things in your Qt app. First, 
>> >> >> > make
>> >> >> > sure that when the server says that you are not authorized, pop up a 
>> >> >> > login
>> >> >> > window. After a successful login, store the user's credentials for 
>> >> >> > later
>> >> >> > use. What type of authentication to use and what to store is up to 
>> >> >> > your
>> >> >> > decision: HTTP Basic (store user/password), HTTP session (store the 
>> >> >> > session
>> >> >> > cookie) or token (store the token) based auths are the most common 
>> >> >> > examples.
>> >> >> >
>> >> >> > Best,
>> >> >> > Gergely
>> >> >> >
>> >> >> > On Apr 26, 2016 00:09, "Larry Martell"  
>> >> >> > wrote:
>> >> >> >>
>> >> >> >> The Qt app talks to the server with web requests routed to python 
>> >> >> >> code
>> >> >> >> by falcon. It currently has no authentication/authorization of any
>> >> >> >> kind. It's not a web app, you can't just navigate to any page, you 
>> >> >> >> can
>> >> >> 

Re: Querying a model with a ForeignKey

2016-05-03 Thread ofeyofey
No problem. I will post if i figure it out.
Thanks very much for your help

On Tuesday, 3 May 2016 18:43:53 UTC+1, ofeyofey wrote:
>
> I have two tables in a sqlite3 DB, PostModel and TopicModel. The PostModel 
> has fields id, post, author, pub_date and topicid. This last fields topicid 
> has a foreignkey to the other table Postmodel. PostModel has the fields id, 
> topic.
> There is a one-to-many relation from the TopicModel to the PostModel. So a 
> Topic can have many posts but a post can only have one topic.
> I would like to create query the PostModel to get the latest post for each 
> topicid.
> So something like, SELECT PostModel.topicid WHERE date_pub is the latest. 
> But i would like to use the Django Query API not SQL.
> My models look like this,
>
> class TopicModel(models.Model):
> topic = models.CharField(max_length=300)
> extra = models.CharField(max_length=100)
>
> def __str__(self):  # __unicode__ on Python 2
> return self.topic
>
> class PostModel(models.Model):
> post = HTMLField(blank=True)
> pub_date = models.DateTimeField('date published')
> author = models.CharField(max_length=30)
> topicid = models.ForeignKey(TopicModel, related_name = 'topicThing')
>
> def __str__(self):  # __unicode__ on Python 2
> return self.post
>
> Here is the view
>
> def thread(request, id):
> if request.method == "POST":
> print 'we are inside POST'
> pk = id
> tform = get_object_or_404(TopicModel, pk=id)
> Pform = PostForm(request.POST)
> if Pform.is_valid():
> # tform = Tform.save(commit=False)
> pform = Pform.save(commit=False)
> pform.topicid = tform
> # pform.topicid = pk
> pform.author = request.user
> pform.pub_date = timezone.now()
> pform.save()
> # return redirect('post_detail', pk=post.pk)
> return redirect('thread', id)
> else:
> pk=id
> pModel = reversed(PostModel.objects.all().filter(topicid_id=pk))
> postform = PostForm()
> return render(request, 'thread.html', {'pModel': pModel, 'postform' : 
> postform})
>
> Thanks
>

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


Re: Querying a model with a ForeignKey

2016-05-03 Thread Aaron Cannon
I fear doing this efficiently is beyond my limited abilities.  Will
look forward to other answers you might get.

Good luck.

Aaron

On 5/3/16, ofeyofey  wrote:
> Aaron thanks for looking at this.
> I understand what you did now, and that is great.
> But I actually realised that the views I showed are not the correct ones
> and the view I want to do this in called 'init' actually has no id.
> So How might I get one instance of each topic where if there is more than
> one instance I get the latest one only?
>
> Here is the view i should have posted.
>
> def init(request):
> # tModel = reversed(TopicModel.objects.all())
> # pModel = reversed(PostModel.objects.all())
> pModel =
> reversed(PostModel.objects.filter(topicid_id=pk).order_by('-pub_date')[0])
> # context = {'tModel': tModel, 'pModel': pModel}
> context = {'pModel': pModel}
> return render(request, 'forum.html', context)
>
> Thanks again,
>
>
> On Tuesday, 3 May 2016 18:43:53 UTC+1, ofeyofey wrote:
>>
>> I have two tables in a sqlite3 DB, PostModel and TopicModel. The PostModel
>>
>> has fields id, post, author, pub_date and topicid. This last fields
>> topicid
>> has a foreignkey to the other table Postmodel. PostModel has the fields
>> id,
>> topic.
>> There is a one-to-many relation from the TopicModel to the PostModel. So a
>>
>> Topic can have many posts but a post can only have one topic.
>> I would like to create query the PostModel to get the latest post for each
>>
>> topicid.
>> So something like, SELECT PostModel.topicid WHERE date_pub is the latest.
>>
>> But i would like to use the Django Query API not SQL.
>> My models look like this,
>>
>> class TopicModel(models.Model):
>> topic = models.CharField(max_length=300)
>> extra = models.CharField(max_length=100)
>>
>> def __str__(self):  # __unicode__ on Python 2
>> return self.topic
>>
>> class PostModel(models.Model):
>> post = HTMLField(blank=True)
>> pub_date = models.DateTimeField('date published')
>> author = models.CharField(max_length=30)
>> topicid = models.ForeignKey(TopicModel, related_name = 'topicThing')
>>
>> def __str__(self):  # __unicode__ on Python 2
>> return self.post
>>
>> Here is the view
>>
>> def thread(request, id):
>> if request.method == "POST":
>> print 'we are inside POST'
>> pk = id
>> tform = get_object_or_404(TopicModel, pk=id)
>> Pform = PostForm(request.POST)
>> if Pform.is_valid():
>> # tform = Tform.save(commit=False)
>> pform = Pform.save(commit=False)
>> pform.topicid = tform
>> # pform.topicid = pk
>> pform.author = request.user
>> pform.pub_date = timezone.now()
>> pform.save()
>> # return redirect('post_detail', pk=post.pk)
>> return redirect('thread', id)
>> else:
>> pk=id
>> pModel = reversed(PostModel.objects.all().filter(topicid_id=pk))
>> postform = PostForm()
>> return render(request, 'thread.html', {'pModel': pModel, 'postform' :
>>
>> postform})
>>
>> Thanks
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a0a43100-4172-4054-aaf2-0302a8a13cbe%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Querying a model with a ForeignKey

2016-05-03 Thread ofeyofey
Aaron thanks for looking at this.
I understand what you did now, and that is great.
But I actually realised that the views I showed are not the correct ones 
and the view I want to do this in called 'init' actually has no id.
So How might I get one instance of each topic where if there is more than 
one instance I get the latest one only?

Here is the view i should have posted.

def init(request):
# tModel = reversed(TopicModel.objects.all())
# pModel = reversed(PostModel.objects.all())
pModel = 
reversed(PostModel.objects.filter(topicid_id=pk).order_by('-pub_date')[0])
# context = {'tModel': tModel, 'pModel': pModel}
context = {'pModel': pModel}
return render(request, 'forum.html', context)

Thanks again,


On Tuesday, 3 May 2016 18:43:53 UTC+1, ofeyofey wrote:
>
> I have two tables in a sqlite3 DB, PostModel and TopicModel. The PostModel 
> has fields id, post, author, pub_date and topicid. This last fields topicid 
> has a foreignkey to the other table Postmodel. PostModel has the fields id, 
> topic.
> There is a one-to-many relation from the TopicModel to the PostModel. So a 
> Topic can have many posts but a post can only have one topic.
> I would like to create query the PostModel to get the latest post for each 
> topicid.
> So something like, SELECT PostModel.topicid WHERE date_pub is the latest. 
> But i would like to use the Django Query API not SQL.
> My models look like this,
>
> class TopicModel(models.Model):
> topic = models.CharField(max_length=300)
> extra = models.CharField(max_length=100)
>
> def __str__(self):  # __unicode__ on Python 2
> return self.topic
>
> class PostModel(models.Model):
> post = HTMLField(blank=True)
> pub_date = models.DateTimeField('date published')
> author = models.CharField(max_length=30)
> topicid = models.ForeignKey(TopicModel, related_name = 'topicThing')
>
> def __str__(self):  # __unicode__ on Python 2
> return self.post
>
> Here is the view
>
> def thread(request, id):
> if request.method == "POST":
> print 'we are inside POST'
> pk = id
> tform = get_object_or_404(TopicModel, pk=id)
> Pform = PostForm(request.POST)
> if Pform.is_valid():
> # tform = Tform.save(commit=False)
> pform = Pform.save(commit=False)
> pform.topicid = tform
> # pform.topicid = pk
> pform.author = request.user
> pform.pub_date = timezone.now()
> pform.save()
> # return redirect('post_detail', pk=post.pk)
> return redirect('thread', id)
> else:
> pk=id
> pModel = reversed(PostModel.objects.all().filter(topicid_id=pk))
> postform = PostForm()
> return render(request, 'thread.html', {'pModel': pModel, 'postform' : 
> postform})
>
> Thanks
>

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


Re: Querying a model with a ForeignKey

2016-05-03 Thread Aaron Cannon
Does

pModel = PostModel.objects.filter(topicid_id=pk).order_by('-pub_date')[0]

work for you?

Also, I believe it would be more conventional if you named your
topicid field simply topic, your post field as body, and your topic
field as name.

Luck.

Aaron

On 5/3/16, ofeyofey  wrote:
> I have two tables in a sqlite3 DB, PostModel and TopicModel. The PostModel
> has fields id, post, author, pub_date and topicid. This last fields topicid
>
> has a foreignkey to the other table Postmodel. PostModel has the fields id,
>
> topic.
> There is a one-to-many relation from the TopicModel to the PostModel. So a
> Topic can have many posts but a post can only have one topic.
> I would like to create query the PostModel to get the latest post for each
> topicid.
> So something like, SELECT PostModel.topicid WHERE date_pub is the latest.
> But i would like to use the Django Query API not SQL.
> My models look like this,
>
> class TopicModel(models.Model):
> topic = models.CharField(max_length=300)
> extra = models.CharField(max_length=100)
>
> def __str__(self):  # __unicode__ on Python 2
> return self.topic
>
> class PostModel(models.Model):
> post = HTMLField(blank=True)
> pub_date = models.DateTimeField('date published')
> author = models.CharField(max_length=30)
> topicid = models.ForeignKey(TopicModel, related_name = 'topicThing')
>
> def __str__(self):  # __unicode__ on Python 2
> return self.post
>
> Here is the view
>
> def thread(request, id):
> if request.method == "POST":
> print 'we are inside POST'
> pk = id
> tform = get_object_or_404(TopicModel, pk=id)
> Pform = PostForm(request.POST)
> if Pform.is_valid():
> # tform = Tform.save(commit=False)
> pform = Pform.save(commit=False)
> pform.topicid = tform
> # pform.topicid = pk
> pform.author = request.user
> pform.pub_date = timezone.now()
> pform.save()
> # return redirect('post_detail', pk=post.pk)
> return redirect('thread', id)
> else:
> pk=id
> pModel = reversed(PostModel.objects.all().filter(topicid_id=pk))
> postform = PostForm()
> return render(request, 'thread.html', {'pModel': pModel, 'postform' :
> postform})
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8dc3a17e-850e-4b5f-91d3-1909c45f97a8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Django formset security and injecting PKs in formset hidden id fields

2016-05-03 Thread Rob Ladd


I've noticed something troubling in Django formsets:

Each formset.form has a hidden field with the id of the model being edited. 

All one would need to do is change this id and submit, and the default 
formset clean() or save() methods don't bat an eye.


I would think that it wouldn't be too complicated to keep track of which 
objects were in the original formset queryset, and compare them on save. 

Given all the other convenient security methods we have, I wonder why 
Django doesn't do this already?

-- 
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/f2a0ed48-fd23-4f4c-b13d-c11828ef5a55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django formset hidden id field

2016-05-03 Thread Rob Ladd
Carl Meyer said:

"Whatever queryset you pass to the model formset limits the 
available rows for editing. The end user can edit the PK to refer to any 
item in that queryset, but not any item in the table. "

That's not true, based on my observation. 
As long as the PK refers to any object of that type, it can be edited by 
monkeying with the hidden id field.
I think that's a pretty big gotcha, since we have conveniences like 
permission_required decorator, {% csrf_token %}, etc.

On Wednesday, May 27, 2015 at 9:47:08 AM UTC-4, Cheng Guo wrote:
>
> Hello,
>
> I have a formset and when I render it, Django would include this line in 
> the HTML:
>
> 
>
> I am curious what is the purpose of having an id field here. 
>
> I mean in what situation would you use it. I did look through Django's 
> documentation 
> on formset 
> but 
> cannot find much documentation on this.
> One answer I got is that this id field is the value of the primary key of 
> the model bound to this form. It is there so that when the formset updates, 
> people can use it to retrieve the corresponding record from the database.
>
> Is the above explaination correct?
>
> If this explaination is correct, then my next question is, wouldn't it be 
> dangerous to expose the primary key like that? I can make a post call to 
> your server with a modified pk which can mess up your database.
>
> Thank you!
>

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


Querying a model with a ForeignKey

2016-05-03 Thread ofeyofey
I have two tables in a sqlite3 DB, PostModel and TopicModel. The PostModel 
has fields id, post, author, pub_date and topicid. This last fields topicid 
has a foreignkey to the other table Postmodel. PostModel has the fields id, 
topic.
There is a one-to-many relation from the TopicModel to the PostModel. So a 
Topic can have many posts but a post can only have one topic.
I would like to create query the PostModel to get the latest post for each 
topicid.
So something like, SELECT PostModel.topicid WHERE date_pub is the latest. 
But i would like to use the Django Query API not SQL.
My models look like this,

class TopicModel(models.Model):
topic = models.CharField(max_length=300)
extra = models.CharField(max_length=100)

def __str__(self):  # __unicode__ on Python 2
return self.topic

class PostModel(models.Model):
post = HTMLField(blank=True)
pub_date = models.DateTimeField('date published')
author = models.CharField(max_length=30)
topicid = models.ForeignKey(TopicModel, related_name = 'topicThing')

def __str__(self):  # __unicode__ on Python 2
return self.post

Here is the view

def thread(request, id):
if request.method == "POST":
print 'we are inside POST'
pk = id
tform = get_object_or_404(TopicModel, pk=id)
Pform = PostForm(request.POST)
if Pform.is_valid():
# tform = Tform.save(commit=False)
pform = Pform.save(commit=False)
pform.topicid = tform
# pform.topicid = pk
pform.author = request.user
pform.pub_date = timezone.now()
pform.save()
# return redirect('post_detail', pk=post.pk)
return redirect('thread', id)
else:
pk=id
pModel = reversed(PostModel.objects.all().filter(topicid_id=pk))
postform = PostForm()
return render(request, 'thread.html', {'pModel': pModel, 'postform' : 
postform})

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8dc3a17e-850e-4b5f-91d3-1909c45f97a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How and where should I put a version number in my Django project?

2016-05-03 Thread Scot Hacker
Another approach is to use git commit IDs and/or git tags to track 
releases, then display that data (and commit date) in a template, only to 
superusers or some group. I did a little blog post about this recently:

http://blog.birdhouse.org/2016/04/22/django_git_template_tag/

./s

-- 
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/33efe23d-7ed7-4358-9ff1-7b41495b93e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How and where should I put a version number in my Django project?

2016-05-03 Thread Nate Granatir
You can put the version for your project in:
my_project/my_project/__init__.py (same folder as settings.py)
like this:

__version__ = '1.0.27'


Then your project acts as a python module, and you can refer to the version 
number, for instance in your settings.py, as:

GRAPPELLI_ADMIN_TITLE = 'My Project v{}'.format(my_project.__version__)


(Here the Grappelli plugin uses this in the headers of all its admin 
templates.)

Nate


On Tuesday, May 3, 2016 at 4:21:38 AM UTC-5, Martin Torre Castro wrote:
>
> I'm making a Django project consisting of several apps and I want to use a 
> version number for the whole project, which would be useful for tracking 
> the status of the project between each time it comes to production.
>
>
> I've read and googled and I've found how to put a version number for each 
> django app of mine, but not for a whole project.
>
> I assume that the *settings.py* (in my case it would be base.py, because 
> the settings are inherited for each environment: developmente, 
> pre-production, production) would be the ideal file for storing it, but I 
> would like to know good practices from other Django programmers, because I 
> haven't found any.
>
>
> Thank you in advance
>

-- 
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/e2b5850a-a378-4a27-b6d6-c3de3e6354be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What's the best way to auto convert a model field values before it is rendered?

2016-05-03 Thread Derek
I would add it as a custom model method - see: 
https://docs.djangoproject.com/es/1.9/topics/db/models/#model-methods

So, for example:

class Temperature(models.Model):
user = models.ForeignKey(User, unique=False)
celcius = models.FloatField(null=True, blank=True)

def _get_fahrenheit(self):
"Returns the temperature in Fahrenheit."
return '%s' % (self.celcius * 1.8 + 32.0)
fahrenheit = property(_get_fahrenheit)


On Tuesday, 26 April 2016 23:43:51 UTC+2, Vince wrote:
>
> I need to store and retrieve temperatures in a model.  I'd like to store 
> all the values in celsius.  However some users prefer to view the value in 
> fahrenheit.
> What is the recommended way to setup a model like this?  
>
> Perhaps manually convert the values in the view and on save?
> Or is it possible to use python properties in a model for saves, updates 
> and gets? 
> Or is some other practice preferred?
>
> class Temp(models.Model):
> user = models.ForeignKey(User, unique=False)
> temperature = models.FloatField(null=True, blank=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/4908e6a5-2b55-4abe-8a44-03e174c06704%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customised handling for wrong passwords entered in Login page in Django.

2016-05-03 Thread Simon Charette
Hi Arun,

If you only want to log failed login attempts I suggest you connect a 
receiver to
the user_login_failed signal[1] instead.

Cheers,
Simon

[1] 
https://docs.djangoproject.com/en/1.9/ref/contrib/auth/#django.contrib.auth.signals.user_login_failed

Le mardi 3 mai 2016 06:01:59 UTC-4, Arun S a écrit :
>
> Hi,
>
> I was trying to add a Customised View to Handle Wrong Passwords entered by 
> Users.
>
> As of now, Djangos Framework just outputs, "Invalid Username or Password" 
> when a Wrong password is entered by the User.
>
> This doesnt allow much flexibility if some information such as Invalid 
> Access needs to be Logged.
> Thus it would be good to Redirect these into a Customized view where the 
> Logging of such information can be done and then redirected back to the 
> Login page with Error.
>
> Any Ideas on how easily this can be done ?
>
> I tried adding a View when a Wrong password is called but always ended up 
> in the below Error:
>
>   File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", 
> line 578, in reverse
> return force_text(iri_to_uri(resolver._reverse_with_prefix(view, 
> prefix, *args, **kwargs)))
>   File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", 
> line 495, in _reverse_with_prefix
> (lookup_view_s, args, kwargs, len(patterns), patterns))
> NoReverseMatch: Reverse for '' with arguments '()' and keyword arguments 
> '{}' not found. 0 pattern(s) tried: []
>
>
> The login.html looks as simple as this.
> td>{{ form.password }}
> {% if form.password.errors %}
>class="error">You must specify a password.
>   {% endif %}
>   
>
> *{% if form.non_field_errors %}   id="password_error_div" class="error">Invalid username or 
> password.  {% endif %}*
>   
> In the Highlighted case, i would like to handle the Error, Log the 
> information to a file required and return back to the page.
>
> Any Help on how this can be done would be great.
> Thanks.
>

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


Re: Chinese humanize number conversion

2016-05-03 Thread Simon Charette
Hi Malte,

The conversion takes place in the intword template filter[1].

The Chinese translation of the intword_converters can be found in the
locale directory of the humanize application[2].

These translations are handled over Transifex[3].

Cheers,
Simon

[1] 
https://github.com/django/django/blob/72ea289ab7f3a0c2c6dca7b2eb73f3117409f8f0/django/contrib/humanize/templatetags/humanize.py#L58-L138
[2] 
https://github.com/django/django/blob/master/django/contrib/humanize/locale/zh_Hans/LC_MESSAGES/django.po
[3] https://www.transifex.com/django/django/language/zh_CN/

Le lundi 2 mai 2016 22:57:40 UTC-4, Malte a écrit :
>
> Hi,
>
> The Chinese humanization of numbers is not correct for large and very 
> large numbers.
> 1.400.000 converts into 1.4 百万 but should be 140万
> 166,200,000,000 converts into 166.2十亿 but should be 1662亿
> I just looked through the Django core code but couldn't find where that 
> conversion takes place.
>
> Where does all of that go down?
>

-- 
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/30339ba1-1525-4566-8a25-71d67c73aa60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python3 + makemessages = "invalid multibyte sequence"

2016-05-03 Thread Torsten Bronger
Hallöchen!

Torsten Bronger writes:

> With Django 1.9.5 and Python 3, I get warnings like
>
> ./jb_common/templates/404.html.py:35: invalid multibyte sequence
>
> when I run "manage.py makemessages".  The problem occurs only in
> HTML files with (validly) UTF-8-encoded characters in them.  In
> the .po file, these characters are skipped.  How can I fix this?
>
> The problem does not occur with Python 2.

This seems to be the issue:
https://code.djangoproject.com/ticket/26093

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de

-- 
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/87d1p3tjrk.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


How to access selected options from a select list to show them in a table ?

2016-05-03 Thread xhoikallupi
So i have a select list and a table,and i want to show only the data that 
corresponds the selected item.

This is my index.html file 


Owners
---
{% for owner in owners %}
 {{ owner.person_id }} {{ owner.first_name }} {{ 
owner.last_name }}
{% endfor %}

 


Id
Space
City
Street
Price
Purpose



{% for info in information %}


{{ info.owner_id }}
{{ info.space }}
{{ info.city }}
{{ info.street }}
{{ info.price }}
{{ info.get_purpose }}
{% endfor %}





-- 
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/e3502e4e-c58b-46e7-8201-9b07edcca7dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Customised handling for wrong passwords entered in Login page in Django.

2016-05-03 Thread Arun S
Hi,

I was trying to add a Customised View to Handle Wrong Passwords entered by 
Users.

As of now, Djangos Framework just outputs, "Invalid Username or Password" 
when a Wrong password is entered by the User.

This doesnt allow much flexibility if some information such as Invalid 
Access needs to be Logged.
Thus it would be good to Redirect these into a Customized view where the 
Logging of such information can be done and then redirected back to the 
Login page with Error.

Any Ideas on how easily this can be done ?

I tried adding a View when a Wrong password is called but always ended up 
in the below Error:

  File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 
578, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, 
prefix, *args, **kwargs)))
  File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 
495, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for '' with arguments '()' and keyword arguments 
'{}' not found. 0 pattern(s) tried: []


The login.html looks as simple as this.
td>{{ form.password }}
{% if form.password.errors %}
  You must specify a password.
  {% endif %}
  

*{% if form.non_field_errors %}  Invalid username or 
password.  {% endif %}*
  
In the Highlighted case, i would like to handle the Error, Log the 
information to a file required and return back to the page.

Any Help on how this can be done would be great.
Thanks.

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


Re: manipulate n insert field values

2016-05-03 Thread Erik Cederstrand

> Den 3. maj 2016 kl. 02.45 skrev Shameema Mohsin :
> 
> 
> Stil stuck with the z order calculation and usage of the property field. 
> Kindly help. I am new to Django, only knows php well.

Where are you stuck? Show your error messages, current non-working code and 
expected result, or describe your problem in more detail.

I assume you have code to calculate the z order (I have no idea what it is). 
Otherwise, other forums would be better for help on this. Assuming that, you 
would do:

def get_z_order(lat, long):
   # Jiggle those numbers
   return z_order


class Employees(models.Model):
   [...]
   @property
   def zval(self):
   return get_z_order(self.empLat, self.empLong)


You can then access zval as if it was a model field.

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+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/0E25E884-F38C-4314-B2B3-0ADAF813253E%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: How and where should I put a version number in my Django project?

2016-05-03 Thread Martín Torre Castro
I will look it at night.

Thanks

On 3 May 2016 at 11:36, Mike Dewhirst  wrote:

> On 3/05/2016 7:21 PM, Martin Torre Castro wrote:
>
>> I'm making a Django project consisting of several apps and I want to use
>> a version number for the whole project, which would be useful for
>> tracking the status of the project between each time it comes to
>> production.
>>
>>
>> I've read and googled and I've found how to put a version number for
>> each django app of mine, but not for a whole project.
>>
>> I assume that the *settings.py* (in my case it would be base.py,
>> because the settings are inherited for each environment: developmente,
>> pre-production, production) would be the ideal file for storing it, but
>> I would like to know good practices from other Django programmers,
>> because I haven't found any.
>>
>
> Have a look at Django itself in ../site-packages/django/__init__.py
>
> Mike
>
>
>>
>> Thank you in advance
>>
>> --
>> 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/1487d708-62f4-4ea0-844b-c61107e58746%40googlegroups.com
>> <
>> https://groups.google.com/d/msgid/django-users/1487d708-62f4-4ea0-844b-c61107e58746%40googlegroups.com?utm_medium=email&utm_source=footer
>> >.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/OrvIGmSW8_4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0f8e0a4b-26d4-5b02-8b6f-b3d1db19c201%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKijOkyVMk1s9d6ZG5VOBRQammo%3DnArx8Wr-pg4fjMTOee_BHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How and where should I put a version number in my Django project?

2016-05-03 Thread Mike Dewhirst

On 3/05/2016 7:21 PM, Martin Torre Castro wrote:

I'm making a Django project consisting of several apps and I want to use
a version number for the whole project, which would be useful for
tracking the status of the project between each time it comes to production.


I've read and googled and I've found how to put a version number for
each django app of mine, but not for a whole project.

I assume that the *settings.py* (in my case it would be base.py,
because the settings are inherited for each environment: developmente,
pre-production, production) would be the ideal file for storing it, but
I would like to know good practices from other Django programmers,
because I haven't found any.


Have a look at Django itself in ../site-packages/django/__init__.py

Mike




Thank you in advance

--
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/1487d708-62f4-4ea0-844b-c61107e58746%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


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


How and where should I put a version number in my Django project?

2016-05-03 Thread Martin Torre Castro


I'm making a Django project consisting of several apps and I want to use a 
version number for the whole project, which would be useful for tracking 
the status of the project between each time it comes to production.


I've read and googled and I've found how to put a version number for each 
django app of mine, but not for a whole project.

I assume that the *settings.py* (in my case it would be base.py, because 
the settings are inherited for each environment: developmente, 
pre-production, production) would be the ideal file for storing it, but I 
would like to know good practices from other Django programmers, because I 
haven't found any.


Thank you in advance

-- 
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/1487d708-62f4-4ea0-844b-c61107e58746%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Integer field choice list keeps triggering migration

2016-05-03 Thread Mike Dewhirst

On 3/05/2016 4:58 PM, jorrit...@gmail.com wrote:

I have the following model and choice list:

BTW_TARIEF_CHOICES = {
(1, '6%'),
(2, '21%'),
(3, '0%'),
}



Migrations see these changes as model changes. The model does change 
because it gets actual new choices in its definition.


At any particular revision of your software there will be or might be 
different possible choices. So that means you can roll back to a 
different revision and get the correct choices for that revision.


Mike



class FactuurItem(models.Model):
naam = models.CharField(max_length=100)
factuur_naam = models.CharField(max_length=100)
eenheid = models.CharField(max_length=10)
prijs = models.DecimalField(max_digits=6, decimal_places=2)
btw_tarief = models.IntegerField(choices=BTW_TARIEF_CHOICES, default=2)

class Meta:
ordering = ['naam']

def __str__(self):
return self.naam


Makemigrations creates a migration for the btw_tarief field every time I
run it, even though the field hasn't changed. It shows up in every
migration file that has been created since I added the field to the
model. The only thing that seems different in every migration file is
that the order of BTW_TARIEF_CHOICES is randomized:

class Migration(migrations.Migration):

dependencies = [
('common', '0021_auto_20160503_0849'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, '21%')], 
default=2),
),
]


class Migration(migrations.Migration):

dependencies = [
('common', '0020_auto_20160502_1656'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(2, '21%'), (3, '0%'), (1, '6%')], 
default=2),
),
]


class Migration(migrations.Migration):

dependencies = [
('common', '0019_auto_20160502_1604'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, '21%')], 
default=2),
),
]


And so on... This happens on Django 1.9.5 and 1.9.6 .

Any ideas why this might be happening?

--
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/88e66c3f-6ebe-4a14-93fe-1b865b712e61%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


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


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-05-03 Thread Michal Petrucha
Hi Bruce,

On Mon, May 02, 2016 at 02:31:37PM -0700, Bruce Whealton wrote:
> Michal,
>I had to read your response a few times but I finally got it.  I was 
> reading
> that all migrations are created in development only and then applied during 
> production.  
> So, during development you use makemigrations and then when deployed
> you migrate.  
> 
> Thus, if you add a new feature, you make the migration on the 
> development system then push it to producation, where you can
> issue the command python manage.py migrate.  

Yes, that sounds correct.

> I just thought of something that is related to migrations.  Suppose,
> with my contacts app, I want to change the name field to be
> first_name + last_name.  If there is data in the database, how will
> this be handled?


There's a description of almost exactly this kind of migration in the
docs:
https://docs.djangoproject.com/en/1.9/topics/migrations/#data-migrations

To give you a more complete overview of how to do that, first, you
create a migration to add the new columns, after which you should have
both the old columns, and the new ones in the database at the same
time. This is a regular schema migration.

Then, you create a data migration which will read data from the old
columns, do any processing, and save the data in new columns. This is
usually called a data migration, and is achieved using the RunPython
migration operation. Alternatively, if you are comfortable with SQL,
and if you are able to express the data transformation in a few SQL
queries, you can use RunSQL instead.

Finally, you create a third migration – another schema migration, in
which you just remove the old columns.

If you want to be able to apply the data migration in reverse, you'll
also have to define a function (or SQL statements) that will perform
the reverse operation. This is optional, but it might come in handy
sometimes, such as when switching between development branches where
each branch has a different set of migrations.


As a final note, you can use the same technique for example if you
want to add a non-nullable unique field to a database that already
contains data. The docs contain a quick walkthrough for this kind of
operation:
https://docs.djangoproject.com/en/1.9/howto/writing-migrations/#migrations-that-add-unique-fields


Does this help?

Michal

-- 
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/20160503074848.GS435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: makemigrations throws table does not exist error

2016-05-03 Thread Michal Petrucha
On Mon, May 02, 2016 at 02:01:24PM -0700, Lucian Willoughby wrote:
> I am trying to re-create an older project from a git repository. I do not 
> have the original MySql database. I emptied the migration folders and tried 
> to run "python manage.py makemigrations" which resulted in the following 
> error : "Table 'age-sdb.login_esm_systems_experience_choice' doesn't 
> exist". 'age-sdb.login_esm_systems_experience_choice' is a table from the 
> project. I have tried "python manage.py makemigrations --empty" with the 
> same results. All migrartion folders are empty

Hi Lucian,

First, deleting all migrations is not something you should do, except
in one specific case, and that is when you are moving from South
migrations to native django.core.migrations. In any other case, your
migrations are a part of your code base, and you should treat them as
such. In some situations you might want to squash incremental
migrations into bigger ones as an optimization, but simply removing
all existing migrations is not the right way to do that.

If you are starting with a new database, you can just apply all
existing migrations without removing them and running makemigrations,
that's the purpose of having migrations in the first place.

Second, regarding that error you are getting, that looks very much
like your application is trying to make database queries during
import, which is not possible, because Django needs to import your
application before it can create and apply migrations that will
actually create those tables.

The traceback you get should reveal where you are trying to access the
database on import, you'll have to fix that code.

Good luck,

Michal

-- 
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/20160503072349.GR435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


upgrade from 1.4 to 1.8

2016-05-03 Thread Samarjeet Singh
The problem i am facing is :
1.login to the app every thing is fine
2.logout
3.login back again (then if i click on any tab it redirects me to the login 
page back again )

any idea what can be the problem ???
PS:one more thing previously when the user does a login the number of key 
was same in the session table(the session key was modified) but now in 1.8 
the number of session key entry increases by two or more. 

-- 
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/1b92eaf8-ace9-499e-ad24-8037aa736ca8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regarding Session ID and cookie validation

2016-05-03 Thread Samarjeet Singh
thanks for the reply 
what my main concern is that does django logs every bad cookie (if the 
cookie is not correct does it logs this ( no it does not i think) but what 
does it do except not letting the user to enter does it raise any exception 
) 

On Sunday, May 1, 2016 at 7:34:55 PM UTC+5:30, Avraham Serour wrote:
>
> > 1. When cookies are used to carry authentication tokens or session IDs 
> within a web application, and multiple such cookies are present, the django 
> verify all such cookies before granting access to the user session. 
> What kind of verification do you expect here? if the submited session id 
> is a valid session id?
>
> > 2. All conflicting cookies are treated as invalid by django.
> What's the question here?
>
> > 3. If validation of any such cookie fails, the cookie treated as if it 
> didn't exist, and the event is added to the audit log or not by django.
> If this is a question then yes, user is treated as not logged in.
>
> > 4. In django after validation of all such cookies, permission are 
> evaluated based on the cookies for which validation succeeded.
> No, permission is handled by the application and stored on db, it would be 
> a huge security issue if the permissions were stored on the cookie
>
> > 5. Cleartext Storage of Sensitive Information in a Cookie:info may be 
> stored in plane of coded form And how much difficult it is to decode.
> what's the question here?
>
> > 6. Information Exposure Through Persistent Cookies:How many old or 
> unused cookie are stored and persist in the system
> If I remember correctly django stores two cookies by default, session id 
> and language
>
> > 7. Reliance on Cookies without Validation and Integrity Checking:- Is it 
> doing the signing and unsigningalways for the integrity check and is this 
> only been done by the default django framework
> I didn't understand the question
>
> > 8. Sensitive Cookie in HTTPS Session Without 'Secure' Attribute : if it 
> is OFF or ON and in which circumstaces this should be ON.
> Don't be lazy, this one you can easily make a hello world and check 
> yourself
>
> > 9. Session IDs are fully validated before they may be used:how is 
> session Id validated in django and the API used for it and how can i check 
> in my framework
> Session id's are checked if they are present on the database. Why do you 
> want to check yourself? do you need to replace the validation?
>
> good luck
> Avraham
>
>
> On Wed, Apr 27, 2016 at 8:58 AM, Samarjeet Singh  > wrote:
>
>> Hi All,
>>
>> Your input is very much valuable ,kindly help me out regarding this. 
>>
>> I need to have a CSDL compliance for following for a project using django 
>> framwork :-
>> But my main concern here is how does django framework validates the 
>> session id and cookie and is
>> it defalut in all the frameworks.I have seen the API (like signed and 
>> unsugned) also but how to ensure that my framework is doing
>> these checks:-
>> 1. When cookies are used to carry authentication tokens or session IDs 
>> within a web application, and multiple such cookies are present, the django 
>> verify all such cookies before granting access to the user session. 
>> 2. All conflicting cookies are treated as invalid by django.
>>
>> 3. If validation of any such cookie fails, the cookie treated as if it 
>> didn't exist, and the event is added to the audit log or not by django.
>>
>> 4. In django after validation of all such cookies, permission are 
>> evaluated based on the cookies for which validation succeeded.
>>
>> 5. Cleartext Storage of Sensitive Information in a Cookie:info may be 
>> stored in plane of coded form and how much difficult it is to decode. 
>> 6. Information Exposure Through Persistent Cookies:How many old or unused 
>> cookie are stored and persist in the system 
>> 7. Reliance on Cookies without Validation and Integrity Checking:- Is it 
>> doing the signing and unsigningalways for the integrity check and is this 
>> only been done by the default django frame work.
>>
>> 8. Sensitive Cookie in HTTPS Session Without 'Secure' Attribute : if it 
>> is OFF or ON and in which circumstaces this should be ON.
>>
>> 9. Session IDs are fully validated before they may be used:how is session 
>> Id validated in django and the API used for it and how can i check in my 
>> framework.
>>  
>>
>> regards 
>> samarjeet singh
>>
>> -- 
>> 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/1ad806f5-73d8-4389-866d-de3e884f4415%40googlegroups.com
>>  
>>