- edited description
exchange_filter recipient is a 'str' object
When I try to create an exchange_filter:
@static_method
exchange_filter(sender, recipient, recipient_list):
print(type(sender) # SimpleLazyObject
print(type(recipient) # str
The docs say recipient is supposed to be a User instance. But, because it’s using a string, no matter what I do it fails if I try to return anything other than None.
If I try to return False, or a string, I get:
'str' object has no attribute 'get_username'
django-postman==3.6.2 from pip install
Comments (9)
-
reporter -
reporter - edited description
-
repo owner - changed status to open
You are probably using a custom form and somewhere in the processing (clean_<something> maybe) the recipients are translated from User to string. It's true that recipient is expected to be kept as a User.
-
reporter Here’s my custom clean method on the recipients field, do you have a suggestion as to what I should be returning here? The forms works fine with this, only the exchange method fails because the recipient is a string instead of a User object.
def clean (self, value): """ This Select2 widget returns a list of ints representing user.id, need to convert that to comma seperated string for django-postman POSTMAN_NAME_USER_AS = 'id' POSTMAN_SHOW_USER_AS = lambda u: u.id """ user_ids_comma_seperated_str = ",".join(map(str, value)) return super (CommaSeperatedUserField, self).clean(user_ids_comma_seperated)
-
repo owner What your CommaSeperatedUserField inherits from?
Do you have a to_python() method in your custom field?
-
reporter Sorry for the typos, I was re-typing from my phone (no internet on my laptop with the code!).
Here is all my attempted customization in one place. There isn’t much.
-
repo owner Your real (wrong) code is:
return super(BasicCommaSeparatedUserField, self).clean(user_ids_comma_seperated_str)
Such writing calls django.forms.fields.CharField.clean(), which essentially returns the argument as-is, so a string instead of a list of User. It seems you misunderstand the usage of super, at many places. If you don’t bother with py27 compatibility, the best is to write it everywhere with the super() syntax only.
-
reporter Thank you! The exchange filter is working as expected now. Sorry for wasting your time on my ignorance of super..
-
reporter - changed status to resolved
- Log in to comment