anitab-org / portal

THIS PROJECT IS ARCHIVED. Systers Portal for communities.
GNU General Public License v2.0
68 stars 209 forks source link

Refactor UserView in users.views #354

Open ajatprabha opened 6 years ago

ajatprabha commented 6 years ago

Description

As a developer, I need to refactor the code in views.py, so that I can make use of correct Generic Class Based View and reduce the coupling in the code.

Current Code Structure

https://github.com/systers/portal/blob/3d870165ad0b93e55c084a2e463bede642ec6ff3/systers_portal/users/views.py#L12-L37

Mocks

Since DetailView is a better choice than TemplateView, I suggest the following changes.

class UserView(LoginRequiredMixin, DetailView):
    """User view"""
    template_name = "users/view_profile.html"
    model = SystersUser

    def get_object(self, queryset=None):
        return get_object_or_404(SystersUser, user__username=self.kwargs.get('username'))

JoinRequestManager will need a new method to be used in template as Django prohibits applying filters in template and should be implemented in Manager: https://github.com/systers/portal/blob/3d870165ad0b93e55c084a2e463bede642ec6ff3/systers_portal/membership/models.py#L8

class JoinRequestManager(models.Manager):
    """Model manager for JoinRequest model"""
    # existing methods

    def unapproved(self):
        return self.filter(is_approved=False)

Other files which require change are in the gist. PS: There'll be no visual change in the frontend.

Acceptance Criteria

Update [Required]

Definition of Done

Estimation

1-2 hour(s)

yatna commented 6 years ago

I think code refactoring is a lengthy task and can be reserved for GSoC 18

ajatprabha commented 6 years ago

Sure @yatna, I'm planning to include this in my proposal. Thanks.