added role column to worker list. Issue #238
See issue #238 (closed) I understand this might be not that useful since this info can be found on the worker details but you can now search for doctors etc. I also did it to understand the way role filters work. I created a property method to access the role. Why is the first role the role of the worker?
Merge request reports
Activity
mentioned in issue #238 (closed)
161 161 else: 162 162 return False 163 163 164 @property 165 def role(self): 166 roles = self.roles.filter(study=GLOBAL_STUDY_ID) 167 if roles.count() == 0: 168 return WORKER_STAFF added 2 commits
- 08ddf342 - Property role of worker model. Check if the role is valid role. #238 (closed)
- 9f44db56 - unit tests for property role of worker model. Issue #238 (closed)
mentioned in commit 1121aa01
@carlos.vega You can also remove this method:
https://git-r3lab.uni.lu/NCER-PD/scheduling-system/blob/master/smash/web/models/worker.py#L197
and replace it with newly created role property.
Can I? I think it is still required since this method is used by
extend_context
who has the username but not a Worker. The property role is a property of Worker class, but not from user. So I think we still need the static method either way. However, I simplified the access to the role.@staticmethod def get_details(the_user): persons = Worker.objects.filter(user=the_user) if len(persons) == 0: return the_user.get_full_name(), '<No worker information>' else: person = persons[0] role = "N/A" if person.roles.filter(study=GLOBAL_STUDY_ID).count() > 0: - role = person.roles.filter(study=GLOBAL_STUDY_ID)[0].get_role_display() + role = person.role return unicode(person), role
I think if you combine it with:
@staticmethod def get_by_user(the_user): if isinstance(the_user, User): workers = Worker.objects.filter(user=the_user) if len(workers) > 0: return workers[0] else: return None elif isinstance(the_user, Worker): return the_user elif isinstance(the_user, AnonymousUser): return None elif the_user is not None: raise TypeError("Unknown class type: " + the_user.__class__.__name__) else: return None
it should work.
Okey, to avoid conflicts I created an issue to reduce these duplicities and will take care of that once we merge the branches. It's that okey? #239 (closed)