def test_some_feedback(self): test_user = User() test_user.save() test_athlete_1 = Athlete(user=test_user) test_athlete_1.save() test_date_1 = timezone.now() - timezone.timedelta(days=1) test_activity_1 = Activity(athlete=test_athlete_1, sport='test_sport', description='test_description', date=test_date_1) test_activity_1.save() feedback_description = 'test_feedback' test_feedback_1 = ActivityFeedback(activity=test_activity_1, description=feedback_description) test_feedback_1.save() self.assertEqual(test_activity_1.last_feedback(), feedback_description)
def feedback(request, athlete_id, activity_id): activity = Activity.objects.get(pk=activity_id) if activity: try: feedback_description = request.POST['feedback_text'] try: activity_feedback = ActivityFeedback.objects.get(activity=activity) activity_feedback.description = feedback_description except ActivityFeedback.DoesNotExist: activity_feedback = ActivityFeedback(activity=activity, description=feedback_description) activity_feedback.save() return HttpResponseRedirect(reverse('training:athlete', args=(athlete_id,))) except KeyError: return render(request, reverse('training:athlete', args=(athlete_id,)), { 'error_message': 'Strange! Have you provided a feedback text? =/', }) else: return render(request, reverse('training:athlete', args=(athlete_id,)), { 'error_message': 'Strange! Could not find the requested Activity. =[', })