Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncryptedDateField and EncryptedDateTimeField Broken #4

Open
JoeJasinski opened this issue Nov 8, 2010 · 6 comments
Open

EncryptedDateField and EncryptedDateTimeField Broken #4

JoeJasinski opened this issue Nov 8, 2010 · 6 comments

Comments

@JoeJasinski
Copy link
Contributor

When using an EncryptedDateField, I get the following error:
invalid literal for int() with base 10:''
I think this is because when the ModelForm first renders an empty form, the to_python function is passed an empty value and therefore breaks when trying to do the split:
date_value = self.date_class(*map(int, date_text.split(':')))
(I think) I was able to solve this by adding a test to check if the value is empty in the to_python function. Also, once I added this check, I was able to enter values that match only the string format YYYY:MM:DD. To solve this, I added a form_class to the formfield defaults.

Not sure how to submit patches or changes on Github (still new to it), but here's my changes so far. I can submit in a better format if needed. Let me know what you think....
Joe

(d11)jjasinski:~/Sites/d11/src/django-fields/src/django_fields$ diff fields.py fields.py.orig 
8d7
< from django.forms import fields
122c121
<         defaults = {'widget': self.form_widget,'form_class':self.form_field}

---
>         defaults = {'widget': self.form_widget}
128,129c127
<    
<         if value in fields.EMPTY_VALUES:

---
>         if isinstance(value, self.date_class):
132,136c130,131
<             if isinstance(value, self.date_class):
<                 date_value = value
<             else:
<                 date_text = super(BaseEncryptedDateField, self).to_python(value)
<                 date_value = self.date_class(*map(int, date_text.split(':')))

---
>             date_text = super(BaseEncryptedDateField, self).to_python(value)
>             date_value = self.date_class(*map(int, date_text.split(':')))
150d144
<     form_field = forms.DateField
160d153
<     form_field = forms.DateTimeField
@JoeJasinski
Copy link
Contributor Author

The above changes work for when the model field is set to "blank=False, null=False". Still working on getting it to work for "blank=True, null=False"

@JoeJasinski
Copy link
Contributor Author

I have a patch with a bunch of fixes and modifications. I'd like to get involved. How do I submit it to you? (sorry, kind of new to github still)

@adamn
Copy link

adamn commented Dec 15, 2010

@JoeJasinski I don't have commit rights to the system, but typically people fork the repository, make the changes, and then make a 'pull request' back to the owners of this repository.

@svetlyak40wt
Copy link
Owner

Joe, please, fork the repository, modify it and send me a pull request.

But please, add a unittest for the issue.

@JoeJasinski
Copy link
Contributor Author

Thanks AdamN and svetlyak40wt, I'll update with my changes and send you a request.

@JoeJasinski
Copy link
Contributor Author

As an update, I've forked the code and have added my changes. I'm still working on adding unit tests, but time has been scarse lately. I'll let you know when those are done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants