Re: Regular Expression with Variables.

2016-05-18 Thread Stephen J. Butler
I think I'd just use format() on the regex, being careful to escape '{' and
'}':

regex_f=r'^.*(?=.*{{{MIN},{MAX}}}*)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^
&*?@#-_+=])'
regex=regex_f.format(MIN=settings.MY_RE_MIN, MAX=settings.MY_RE_MAX)


On Thu, May 19, 2016 at 12:37 AM, Arun S  wrote:

> Hi,
>
> I have a Regular Expression something like this:
> regex=r'^.*(?=.*{8,}*)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
>r'.*$',
>
> In this, i would like to read the values from the Django Setting file on
> the Max and Min Length and provide them as my input instead of Hard Coding.
>
> How can a Variable be provided/escaped in a regex.
> Can some one throw some light on this ?
>
> Cheers
> Arun
>
>
> --
> 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/90556052-063e-4307-b095-c37a9920399b%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/CAD4ANxWXKPTst1QACxy%2BXbjJK0hF%2B1264Gs9oqafHRcwqRMSKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Regular Expression with Variables.

2016-05-18 Thread Arun S
Hi,

I have a Regular Expression something like this:
regex=r'^.*(?=.*{8,}*)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!$%^&*?@#-_+=])'
   r'.*$',

In this, i would like to read the values from the Django Setting file on 
the Max and Min Length and provide them as my input instead of Hard Coding.

How can a Variable be provided/escaped in a regex.
Can some one throw some light on this ?

Cheers
Arun


-- 
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/90556052-063e-4307-b095-c37a9920399b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django queryset/annotate get extra column

2016-05-18 Thread stunaz
Hi,
I would like to write the following query using django orm.

select * ,
(select image_url from blog_image bi where bi.blog_id = b.id and bi.
principal=1) as blog_main_imange
from blog b


Any idea, how to write the queryset ?

-- 
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/d5973fd0-6dc5-4c8f-8ae0-53fbf7c541bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a spanish version of Two Scoops of Django?

2016-05-18 Thread Luis Zárate
That sound very good, so if you need help with translations I could help
you in my few free time.

Break language barrier is so important for me, I think more people could
learn django faster and without discrimination.

So ViVa la libertad. :)

El martes, 17 de mayo de 2016, David Alejandro Reyes Milian <
davidreyesmilia...@gmail.com> escribió:
> Thanks for asking. I could like to make a full Spanish translation  of
this amazing book, how can I speak to Audrey or Danny? Can you help?
>
> Greetings!
>
> El martes, 17 de mayo de 2016, 17:09:22 (UTC-4), Russell Keith-Magee
escribió:
>>
>> Hi David,
>> To the best of my knowledge, there aren’t any translations of Two Scoops
available - but I’ve asked Audrey and Danny to confirm. If there is, I’ll
report back and let you know.
>> Yours,
>> Russ Magee %-)
>> On Tue, May 17, 2016 at 9:03 PM, David Alejandro Reyes Milian <
davidreye...@gmail.com> wrote:
>>>
>>> Do you know if there is a Spanish version of Two Scoops of Django?
>>>
>>> --
>>> 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/9548ab5d-d529-4eda-a84b-37c14780fd68%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/75d8bb7e-b610-4ade-b3cb-a351594be04e%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyOo-BTYT6HHxh81bS6yxmM3-2j18rp7Mos%2Bc0cm92MkiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django middleware process exception not call

2016-05-18 Thread Luis Zárate
Hi,

I was working with middleware that catch exceptions and redirect to other
view depending of except type.

My idea was raise custom exceptions in several parts of the code and catch
in middlewaware with proces exception function, but I have an exception
raise in template tag when template is render and after process exception
call, so this function is never call.

I surft in django code an understand what happen but I thing that django
could call process exception if exception occurred in template o have some
way to catch template exceptions, something like a function named process
template exception.







-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyONUKK2rsVRpAjYa4Yty3%2B4-m8ZMP4VcO-uaiWEbMVuyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django send_mail smtp gmail

2016-05-18 Thread James Schneider
> >>> from django.core.mail import send_mail
> >>> send_mail('subject is', 'message is and is not 12342', '
fromem...@gmail.com', ['sen...@gmail.com'])
> 1
> >>>
>
> I am receiving this email in my gmail account, incidently which is the
same gmail account used for the smtp, but the from email is showing up as
the sen...@gmail.com and should be fromem...@gmail.com
>

The GMail servers will automatically override any provided envelope or
message sender address value and replace it with the address used to
authenticate to SMTP due to name space collisions and spam protection.
There's no way to override this behavior. You'll need to find another mail
relay service if this is critical.

-James

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


Django send_mail smtp gmail

2016-05-18 Thread ofeyofey
Hi,

I have set up smtp with a gmail account. When I use send_mail the from 
email is not showing up in the account receiving the email.

Django settings.py

# DEFAULT_FROM_EMAIL = 'sen...@gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'sen...@gmail.com'
EMAIL_HOST_PASSWORD = '**'
EMAIL_USE_TLS = True

Using 

$ python manage.py shell

I send the mail as follows,

>>> from django.core.mail import send_mail
>>> send_mail('subject is', 'message is and is not 12342', 
'fromem...@gmail.com', ['sen...@gmail.com'])
1
>>> 

I am receiving this email in my gmail account, incidently which is the same 
gmail account used for the smtp, but the from email is showing up as the 
sen...@gmail.com and should be fromem...@gmail.com

Any help would be greatly appreciated,

Thanks,

Shane



-- 
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/ee382612-fe68-4118-9bf0-5f51692c5521%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A question on save_m2m()

2016-05-18 Thread Ankush Thakur
Ah! Stupid, stupid me. 

Thanks a lot for clarifying! :-)

Best,
Ankush

On Wednesday, May 18, 2016 at 12:15:57 PM UTC+5:30, James Schneider wrote:
>
>
>
> On Sat, May 14, 2016 at 2:42 AM, Ankush Thakur  > wrote:
>
>> So the following section from the docs has me a little confused:
>>
>> =
>> Another side effect of using commit=False is seen when your model has a 
>> many-to-many relation with another model. If your model has a many-to-many 
>> relation and you specify commit=False when you save a form, Django cannot 
>> immediately save the form data for the many-to-many relation. This is 
>> because it isn’t possible to save many-to-many data for an instance until 
>> the instance exists in the database.
>>
>> To work around this problem, every time you save a form using 
>> commit=False, Django adds a save_m2m() method to your ModelForm subclass. 
>> After you’ve manually saved the instance produced by the form, you can 
>> invoke save_m2m() to save the many-to-many form data. For example:
>>
>> # Create a form instance with POST data.
>> >>> f = AuthorForm(request.POST)
>>
>> # Create, but don't save the new author instance.
>> >>> new_author = f.save(commit=False)
>>
>> # Modify the author in some way.
>> >>> new_author.some_field = 'some_value'
>>
>> # Save the new instance.
>> >>> new_author.save()
>>
>> # Now, save the many-to-many data for the form.
>> >>> f.save_m2m()
>> ==
>>
>> I can understand why Django doesn't save Many-to-Many data when commit is 
>> set to False, but why do we need to  manually call save_m2m() after doing 
>> save() manually? Why doesn't Django update the associated Many-to-Many data 
>> automatically in this case?
>>
>>
> Look a bit closer at the process you listed from the docs: 
>
> The initial f.save(commit=False) is run on the bound ModelForm object, and 
> returns an unsaved Author object (new_author), which means that the M2M 
> relations are not saved either (since you can't save a M2M without a fully 
> saved/initialized object already in the DB). 
>
> You are then running save() on new_author, not on f, which means you are 
> saving the primary model instance returned by the form, not saving the form 
> itself.
>
> The last step is the f.save_m2m() call, which tells the form (not 
> new_author) to grab the related objects and tie them to your new_author 
> object, and completes saving all pieces of the form. 
>
> HTH,
>
> -James
>

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


sub accounts in django

2016-05-18 Thread Mehdy M. Haghy
Creating sub accounts is a pretty common scenario.
you have clients like (copmany1, company2, ..., company N) 
and they have their own users, roles and permissions. 
any recommendation on how to implement this or any package recommendation?

-- 
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/14bb6ea9-112b-44d7-8b89-d7ad041fddcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why not working exampe from Django docs

2016-05-18 Thread Tim Graham
It might be that the meta class should be removed (or at least, app_label 
should refer to the actual label of your app):

class Meta:
app_label = 'mysessions'


Does it work if you do that? Do you have the app in INSTALLED_APPS?

On Wednesday, May 18, 2016 at 8:39:48 AM UTC-4, Seti Volkylany wrote:
>
> https://docs.djangoproject.com/en/1.9/topics/http/sessions/#example
>
> from django.contrib.sessions.backends.db import SessionStore as DBStorefrom 
> django.contrib.sessions.base_session import AbstractBaseSessionfrom django.db 
> import models
> class CustomSession(AbstractBaseSession):
> account_id = models.IntegerField(null=True, db_index=True)
>
> class Meta:
> app_label = 'mysessions'
>
> @classmethod
> def get_session_store_class(cls):
> return SessionStore
> class SessionStore(DBStore):
> @classmethod
> def get_model_class(cls):
> return CustomSession
>
> def create_model_instance(self, data):
> obj = super(SessionStore, self).create_model_instance(data)
> try:
> account_id = int(data.get('_auth_user_id'))
> except (ValueError, TypeError):
> account_id = None
> obj.account_id = account_id
> return obj
>
>
> In settings registered as next:
>
>
> SESSION_ENGINE = 'apps.app_sessions.backends.extended_session_store'
>
>
>
> When I made attempt create migrations, Django - silent
>
>
> In [6]: !./manage.py makemigrations
> No changes detected
>
>
>

-- 
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/9bf971e9-c792-4e87-800c-7aac3a2407a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why not working exampe from Django docs

2016-05-18 Thread Seti Volkylany
https://docs.djangoproject.com/en/1.9/topics/http/sessions/#example

from django.contrib.sessions.backends.db import SessionStore as DBStorefrom 
django.contrib.sessions.base_session import AbstractBaseSessionfrom django.db 
import models
class CustomSession(AbstractBaseSession):
account_id = models.IntegerField(null=True, db_index=True)

class Meta:
app_label = 'mysessions'

@classmethod
def get_session_store_class(cls):
return SessionStore
class SessionStore(DBStore):
@classmethod
def get_model_class(cls):
return CustomSession

def create_model_instance(self, data):
obj = super(SessionStore, self).create_model_instance(data)
try:
account_id = int(data.get('_auth_user_id'))
except (ValueError, TypeError):
account_id = None
obj.account_id = account_id
return obj


In settings registered as next:


SESSION_ENGINE = 'apps.app_sessions.backends.extended_session_store'



When I made attempt create migrations, Django - silent


In [6]: !./manage.py makemigrations
No changes detected


-- 
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/66583aa8-0e69-4590-9420-6db734267ec6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Booleanfield in Admin/ shows wrong data (Django 1.8)

2016-05-18 Thread 'Uwe Küllmar' via Django users
Hello,

I installed a new Server with DB2/LINUXX8664 10.5.7, Django 1.8.13, ibm_db 
2.0.7 and  ibm_db_django 1.0.9.2. 
After restoring my database on the  new system (source was also db2 with 
django 1.7) I have the problem that the check boxes in the admin area shows 
wrong data. All Check boxes are selected and ignore the values from the 
database.

If I query the data in the django shell I got 1 and 0 instead of  True and 
False  (Booleanfields)
To except errors in my code I have created a fresh  django project and I 
see the same issue.



Python 2.7.11+ (default, Apr 17 2016, 14:00:29) 
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from polls.models import *
>>> for  i  in Dummy.objects.all():
...  print i.isboo ,  i.noboo
... 
1 0
1 1
0 0

from the models 

class Dummy(models.Model):
isboo = models.BooleanField(default=True)
noboo = models.BooleanField(default=False)


Regards,
 Uwe 

-- 
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/2b8906e0-4fd3-4a4b-b225-0155f4bea193%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Password Validation

2016-05-18 Thread Arun S
Hi,

Thanks for the Suggestion.
James, in the option that you provided makes the User change the Password 
of the Logged in user which might turn out to be a costly operation.
But Yes, validating within the View and then using Authenticate() does 
sound easier.

https://docs.djangoproject.com/en/1.9/topics/auth/default/#auth-web-requests
I shall check this.
Thanks.



On Wednesday, May 18, 2016 at 1:22:16 PM UTC+5:30, James Schneider wrote:
>
>
>
> On Wed, May 18, 2016 at 12:08 AM, Arun S  
> wrote:
>
>> Hi ,
>>
>> I have a small issue with the Validation of Passwords in the Change 
>> Password Page.
>>
>> Due to certain different requirements, i have written my own Custom Forms 
>> for Change Password.
>>
>> Now in this, I would want to first Validate the Old Password Field with 
>> the Current Users Password.
>>
>> The Problem i am facing here is that the OldPassword Field provides me a 
>> Password in Raw String Format.
>> But  the user.password returns a Hashed Output of the Users Password 
>>
>> And for obvious Reasons, the Validation fails between OldPassword and the 
>> User.Password.
>>
>> In many forums i checked that the Reverse way to get the Passed from the 
>> Hashed Values is not possible.
>> So my only way to do this validation is through Encrypting the 
>> OldPassword and then Comparing the Hash.
>> But i am not sure how to do that.
>>
>
> Note that you are hashing the raw password, not encrypting it. Hashes are 
> not reversible by design.
>  
>
>>
>> Can some one please tell me how is this possible to achieve and what are 
>> the Apis that i can use to get the Password to be compared.
>>
>
> If your form has access to the username, I would recommend writing a 
> custom validator or clean() method for one of your password fields: 
>
> https://docs.djangoproject.com/en/1.9/ref/forms/fields/#validators
>
> https://docs.djangoproject.com/en/1.9/ref/forms/validation/#cleaning-a-specific-field-attribute
>
> If you don't have access to the username (just the user ID in the DB), it 
> may be easier to run the validation in the view itself since you'll have 
> access to request.user to pass along to authenticate(). The form itself 
> (and therefore none of the clean() or validation functions) do not have 
> access to the request where the user object is stored. 
>
> That's of course assuming that you are changing the password of the 
> logged-in user. 
>
> You can then use the authenticate() method with the existing password in 
> your custom validation function to see if the provided password is the same 
> one the user is currently using.
>
>
> https://docs.djangoproject.com/en/1.9/topics/auth/default/#django.contrib.auth.authenticate
>  
>
> -James
>

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


Re: Django Password Validation

2016-05-18 Thread James Schneider
On Wed, May 18, 2016 at 12:08 AM, Arun S  wrote:

> Hi ,
>
> I have a small issue with the Validation of Passwords in the Change
> Password Page.
>
> Due to certain different requirements, i have written my own Custom Forms
> for Change Password.
>
> Now in this, I would want to first Validate the Old Password Field with
> the Current Users Password.
>
> The Problem i am facing here is that the OldPassword Field provides me a
> Password in Raw String Format.
> But  the user.password returns a Hashed Output of the Users Password
>
> And for obvious Reasons, the Validation fails between OldPassword and the
> User.Password.
>
> In many forums i checked that the Reverse way to get the Passed from the
> Hashed Values is not possible.
> So my only way to do this validation is through Encrypting the OldPassword
> and then Comparing the Hash.
> But i am not sure how to do that.
>

Note that you are hashing the raw password, not encrypting it. Hashes are
not reversible by design.


>
> Can some one please tell me how is this possible to achieve and what are
> the Apis that i can use to get the Password to be compared.
>

If your form has access to the username, I would recommend writing a custom
validator or clean() method for one of your password fields:

https://docs.djangoproject.com/en/1.9/ref/forms/fields/#validators
https://docs.djangoproject.com/en/1.9/ref/forms/validation/#cleaning-a-specific-field-attribute

If you don't have access to the username (just the user ID in the DB), it
may be easier to run the validation in the view itself since you'll have
access to request.user to pass along to authenticate(). The form itself
(and therefore none of the clean() or validation functions) do not have
access to the request where the user object is stored.

That's of course assuming that you are changing the password of the
logged-in user.

You can then use the authenticate() method with the existing password in
your custom validation function to see if the provided password is the same
one the user is currently using.

https://docs.djangoproject.com/en/1.9/topics/auth/default/#django.contrib.auth.authenticate


-James

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


Re: Django Password Validation

2016-05-18 Thread orzodk
Arun S  writes:

> Hi ,
>
> I have a small issue with the Validation of Passwords in the Change Password 
> Page.
>
> Due to certain different requirements, i have written my own Custom Forms for 
> Change Password.
>
> Now in this, I would want to first Validate the Old Password Field with the 
> Current Users Password.
>
> The Problem i am facing here is that the OldPassword Field provides me a 
> Password in Raw String Format.
> But  the user.password returns a Hashed Output of the Users Password
>
> And for obvious Reasons, the Validation fails between OldPassword and the 
> User.Password.
>
> In many forums i checked that the Reverse way to get the Passed from the 
> Hashed Values is not possible.
> So my only way to do this validation is through Encrypting the OldPassword 
> and then Comparing the Hash.
> But i am not sure how to do that.
>
> Can some one please tell me how is this possible to achieve and what are the 
> Apis that i can use to get the Password to be compared.
>
> Arun.

The easiest way is to authenticate the user using the password from the
form. It will return the user object if the password was correct, or
None if it wasn't.

For more information and an example see the docs:
https://docs.djangoproject.com/en/1.9/topics/auth/default/#auth-web-requests

-- 
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/m2lh377qt0.fsf%400zb9ja0m9c.com.
For more options, visit https://groups.google.com/d/optout.


Django Password Validation

2016-05-18 Thread Arun S
Hi ,

I have a small issue with the Validation of Passwords in the Change 
Password Page.

Due to certain different requirements, i have written my own Custom Forms 
for Change Password.

Now in this, I would want to first Validate the Old Password Field with the 
Current Users Password.

The Problem i am facing here is that the OldPassword Field provides me a 
Password in Raw String Format.
But  the user.password returns a Hashed Output of the Users Password 

And for obvious Reasons, the Validation fails between OldPassword and the 
User.Password.

In many forums i checked that the Reverse way to get the Passed from the 
Hashed Values is not possible.
So my only way to do this validation is through Encrypting the OldPassword 
and then Comparing the Hash.
But i am not sure how to do that.

Can some one please tell me how is this possible to achieve and what are 
the Apis that i can use to get the Password to be compared.

Arun.

-- 
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/9e1d304c-8d93-4b64-93ef-bab420fc0511%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A question on save_m2m()

2016-05-18 Thread James Schneider
On Sat, May 14, 2016 at 2:42 AM, Ankush Thakur 
wrote:

> So the following section from the docs has me a little confused:
>
> =
> Another side effect of using commit=False is seen when your model has a
> many-to-many relation with another model. If your model has a many-to-many
> relation and you specify commit=False when you save a form, Django cannot
> immediately save the form data for the many-to-many relation. This is
> because it isn’t possible to save many-to-many data for an instance until
> the instance exists in the database.
>
> To work around this problem, every time you save a form using
> commit=False, Django adds a save_m2m() method to your ModelForm subclass.
> After you’ve manually saved the instance produced by the form, you can
> invoke save_m2m() to save the many-to-many form data. For example:
>
> # Create a form instance with POST data.
> >>> f = AuthorForm(request.POST)
>
> # Create, but don't save the new author instance.
> >>> new_author = f.save(commit=False)
>
> # Modify the author in some way.
> >>> new_author.some_field = 'some_value'
>
> # Save the new instance.
> >>> new_author.save()
>
> # Now, save the many-to-many data for the form.
> >>> f.save_m2m()
> ==
>
> I can understand why Django doesn't save Many-to-Many data when commit is
> set to False, but why do we need to  manually call save_m2m() after doing
> save() manually? Why doesn't Django update the associated Many-to-Many data
> automatically in this case?
>
>
Look a bit closer at the process you listed from the docs:

The initial f.save(commit=False) is run on the bound ModelForm object, and
returns an unsaved Author object (new_author), which means that the M2M
relations are not saved either (since you can't save a M2M without a fully
saved/initialized object already in the DB).

You are then running save() on new_author, not on f, which means you are
saving the primary model instance returned by the form, not saving the form
itself.

The last step is the f.save_m2m() call, which tells the form (not
new_author) to grab the related objects and tie them to your new_author
object, and completes saving all pieces of the form.

HTH,

-James

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