def get_context_data(self, **kwargs): context = super(CompetitionView, self).get_context_data(**kwargs) competition = self.object profile = Profile.objects.by_user_id(competition.user_id) if profile is None: self.redirect("/") # todo: adapt return category = Category.objects.get_by_id(competition.category_id) if category is not None: category.total_views += 1 category.save() video_embed_code = utils.video_embed_code(competition.intro_video_url) activities = Activity.objects.feed(competition) videos = Video.objects.filter(pk__in=competition.videos) user_id = self.request.user.id is_my_competition = competition.user_id == user_id is_already_compete = \ Video.objects.filter(user_id=user_id, competition_id=competition.competition_id) disable_compete = is_my_competition or is_already_compete context.update({ 'activities': activities, 'category': category, 'profile': profile, 'video_embed_code': video_embed_code, 'videos': videos, 'disable_compete': disable_compete, }) return context
def get_context_data(self, **kwargs): context = super(ProfileView, self).get_context_data(**kwargs) profile = Profile.objects.by_username(self.username) if profile is None: raise Http404() # todo: move it to the model? video_embed_code = utils.video_embed_code(profile.profile_video_url) activities = Activity.objects.top_100_activities_for_user(profile) comment_list = profile.user.comment_comments.all() user_id = profile.user.id active_competitions = Competition.objects.active(user_id, self.my_profile) completed_competitions = Competition.objects.completed(user_id, self.my_profile) age = utils.calculate_age(profile.birthdate) context.update( { "profile": profile, "video_embed_code": video_embed_code, "activities": activities, "age": age, "comment_list": comment_list, "active_competitions": active_competitions, "completed_competitions": completed_competitions, } ) return context
def get_context_data(self, **kwargs): context = super(VideoView, self).get_context_data(**kwargs) video = self.object profile = Profile.objects.by_user_id(video.user_id) competition = Competition.objects.get_by_id(video.competition_id) category = Category.objects.get_by_id(competition.category_id) if category is not None: category.total_views += 1 category.save() # todo: maybe we should just remove voted1 case, it's covered by voted2 voted1 = Vote.objects.filter(user_id=self.request.user.id, video_id=video.video_id) voted2 = Vote.objects.filter(user_id=self.request.user.id, competition_id=video.competition_id) voted = voted1 or voted2 video_embed_code = utils.video_embed_code(video.video_url) context.update({ 'category': category, 'competition': competition, 'profile': profile, 'video_embed_code': video_embed_code, 'voted': voted, }) return context