def add_watch_later(request): profile = request.user.get_profile() if request.method != 'POST' or 'video_id' not in request.POST: return HttpResponseBadRequest() try: video_id = int(request.POST['video_id']) except ValueError: return HttpResponseBadRequest() video = get_or_none(Video, pk=video_id) if video is None: status = { 'status': 'fail', 'reason': 'Video does not exist.', } else: profile.watch_later_videos.add(video) status = { 'status': 'ok', } return HttpResponse(simplejson.dumps(status), content_type='application/json')
def add_favorite(request): profile = request.user.get_profile() if request.method == "GET": return redirect('profile-get-favorites', page_number=1) if 'video_id' not in request.POST: return HttpResponseBadRequest() try: video_id = int(request.POST['video_id']) except ValueError: return HttpResponseBadRequest() video = get_or_none(Video, pk=video_id) if video is None: status = { 'status': 'fail', 'reason': 'Video does not exist.', } else: profile.favorite_videos.add(video) status = { 'status': 'ok', } return HttpResponse(simplejson.dumps(status), content_type='application/json')
def _register(self, user=None): """ The method registers the member to the website. This entails creating a user account and a user profile linked to the Member object. The models which inherit from Member can thus be reached through a user account/profile. The keyword argument `user` represents an existing auth.User object to use for the Member instance instead of creating a new one. """ if user is None: user = User.objects.create_user( username=self.username, password=self.password) user.is_active = self.active # Automatically add the user to the proper group if self._group_name is not None: group = get_or_none(Group, name=self._group_name) if group is not None: user.groups.add(group) user.save() profile = UserProfile(user=user, member=self) profile.save()