django-fields icon indicating copy to clipboard operation
django-fields copied to clipboard

EncryptedDateField and EncryptedDateTimeField Broken

Open JoeJasinski opened this issue 15 years ago • 6 comments

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 avatar Nov 08 '10 18:11 JoeJasinski

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 avatar Nov 08 '10 18:11 JoeJasinski

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)

JoeJasinski avatar Nov 17 '10 07:11 JoeJasinski

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

adamn avatar Dec 15 '10 20:12 adamn

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

But please, add a unittest for the issue.

svetlyak40wt avatar Jan 21 '11 19:01 svetlyak40wt

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

JoeJasinski avatar Jan 24 '11 17:01 JoeJasinski

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.

JoeJasinski avatar Jan 29 '11 17:01 JoeJasinski