def get(self, request, *args, **kwargs): response = DetailView.get(self, request, *args, **kwargs) # check if the follow button was hit if request.GET.get("follow", "") == "true": follow_project(request.user, self.object) # check if the unfollow button was hit if request.GET.get("follow", "") == "false": unfollow_project(request.user, self.object) return response
def form_valid(self, form): # check if manager or developers have changed for changed in form.changed_data: if changed == "developer": # newly added developers follow the project by default, unfollow in forms.py for dev in set(form.cleaned_data[changed]) - set(self.object.developer.all()): follow_project(dev, form.instance) if changed == "manager": # newly added managers follow the project by default, unfollow in forms.py for man in set(form.cleaned_data[changed]) - set(self.object.manager.all()): follow_project(man, form.instance) return UpdateView.form_valid(self, form)
def form_valid(self, form): form.instance.creator = self.request.user # NOTE: this is necessary here even though it is a CreateView, because # "ValueError: "<Project: test_project>" needs to have a value for # field "project" before this many-to-many relationship can be used." form.instance.save() form.instance.manager.add(self.request.user) # per default a user follows the project he created follow_project(self.request.user, form.instance) # and every developer follows the project, too for dev in form.cleaned_data["developer"]: follow_project(dev, form.instance) return super(ProjectCreateView, self).form_valid(form)
def test_unfollow_project(self): # unfollow the project with the unfollow button on the dashboard self.client.get( reverse('landing_page:home') + "?unfollow=" + str(self.project.pk)) self.assertNotIn(self.project, following(self.user)) # follow the project again follow_project(self.user, self.project) # unfollow the project with the unfollow button on the project page self.client.get( reverse('project:detail', kwargs={'project': project_settings['name_short']}) + "?follow=false") self.assertNotIn(self.project, following(self.user))