Commit fbe3335a05ad5f9ca747b7fe9deb62f89b8075ce
1 parent
e1124f56
Exists in
master
and in
39 other branches
Removing build_filters and adding dehydrate methods to be able of filtering by email
Showing
1 changed file
with
9 additions
and
32 deletions
Show diff stats
src/api/models.py
| ... | ... | @@ -13,32 +13,19 @@ class UserResource(ModelResource): |
| 13 | 13 | class Meta: |
| 14 | 14 | queryset = User.objects.filter(is_active=True) |
| 15 | 15 | resource_name = 'user' |
| 16 | - excludes = ['email', 'password', 'is_active', 'is_staff', | |
| 17 | - 'is_superuser', 'verification_hash'] | |
| 16 | + fields = ['username', 'institution', 'role', 'bio', 'first_name', | |
| 17 | + 'last_name', 'email'] | |
| 18 | 18 | allowed_methods = ['get', ] |
| 19 | 19 | filtering = { |
| 20 | + 'email': ('exact', ), | |
| 20 | 21 | 'username': ALL, |
| 21 | 22 | 'institution': ALL, |
| 22 | 23 | 'role': ALL, |
| 23 | - 'twitter': ALL, | |
| 24 | - 'facebook': ALL, | |
| 25 | - 'google_talk': ALL, | |
| 26 | - 'github': ALL, | |
| 27 | - 'webpage': ALL, | |
| 28 | 24 | 'bio': ALL, |
| 29 | 25 | } |
| 30 | 26 | |
| 31 | - def build_filters(self, filters=None): | |
| 32 | - if filters is None: | |
| 33 | - filters = {} | |
| 34 | - | |
| 35 | - orm_filters = super(UserResource, self).build_filters(filters) | |
| 36 | - | |
| 37 | - if 'email' in filters: | |
| 38 | - qs = User.objects.filter(email=filters['email']) | |
| 39 | - orm_filters['pk__in'] = [i.pk for i in qs] | |
| 40 | - | |
| 41 | - return orm_filters | |
| 27 | + def dehydrate_email(self, bundle): | |
| 28 | + return '' | |
| 42 | 29 | |
| 43 | 30 | |
| 44 | 31 | class EmailAddressResource(ModelResource): |
| ... | ... | @@ -47,26 +34,16 @@ class EmailAddressResource(ModelResource): |
| 47 | 34 | class Meta: |
| 48 | 35 | queryset = EmailAddress.objects.all() |
| 49 | 36 | resource_name = 'emailaddress' |
| 50 | - excludes = ['address', 'md5'] | |
| 37 | + excludes = ['md5', ] | |
| 51 | 38 | allowed_methods = ['get', ] |
| 52 | 39 | filtering = { |
| 40 | + 'address': ('exact', ), | |
| 53 | 41 | 'user': ALL_WITH_RELATIONS, |
| 54 | 42 | 'real_name': ALL, |
| 55 | 43 | } |
| 56 | 44 | |
| 57 | - def build_filters(self, filters=None): | |
| 58 | - if filters is None: | |
| 59 | - filters = {} | |
| 60 | - | |
| 61 | - orm_filters = super(EmailAddressResource, self).build_filters(filters) | |
| 62 | - | |
| 63 | - if 'email' in filters or 'address' in filters: | |
| 64 | - address = filters.get('email') if filters.get('email') else \ | |
| 65 | - filters.get('address') | |
| 66 | - qs = EmailAddress.objects.filter(address=address) | |
| 67 | - orm_filters['pk__in'] = [i.pk for i in qs] | |
| 68 | - | |
| 69 | - return orm_filters | |
| 45 | + def dehydrate_address(self, bundle): | |
| 46 | + return '' | |
| 70 | 47 | |
| 71 | 48 | |
| 72 | 49 | class MessageResource(ModelResource): | ... | ... |