def MoodManageAddView(request, username=''): user = User.objects.get(username=username) form = MoodForm(request.POST or None) if form.is_valid(): thisDate = form.cleaned_data['date'] thisRating = form.cleaned_data['rating'] thisKeywords = form.cleaned_data['keywords'] thisUser = User.objects.get(username=username) mood = Mood(user=thisUser, date=thisDate, rating=thisRating, keywords=thisKeywords) mood.save() return HttpResponseRedirect(URL_DASHBOARD(user.username)) return HttpResponseRedirect(URL_DASHBOARD(username))
def MoodManageUpdateView(request, username='', moodid=''): mood = Mood.objects.get(id=moodid) user = User.objects.get(username=username) form = MoodForm(request.POST or None) if form.is_valid(): mood.date = form.cleaned_data['date'] mood.rating = form.cleaned_data['rating'] mood.keywords = form.cleaned_data['keywords'] mood.save() return HttpResponseRedirect(URL_DASHBOARD(user.username)) else: template_name = 'master/mood_manage_update.html' template_value = {'form': form, 'mood': mood, 'user': user} return render_to_response(template_name, template_value, context_instance=RequestContext(request))
def DashboardView(request, username=''): user = User.objects.get(username=username) # Goals: ## Todo todo_form = TodoForm() todos = Todo.objects.filter(user_id=user.id, status=1) # list all undos ## 10K Hours tracker_form = TrackerForm() trackers = Tracker.objects.filter(user_id=user.id) ## Event event_form = EventForm() events = Event.objects.filter(user_id=user.id) # Life: ## Mood mood_form = MoodForm() moods = Mood.objects.filter(user_id=user.id) ## Dream dream_form = DreamForm() dreams = Dream.objects.filter(user_id=user.id) ## Diary diary_form = DiaryForm() diaries = Diary.objects.filter(user_id=user.id) # Rendering template template_name = 'master/dashboard.html' template_value = { 'TodoForm': todo_form, 'todos': todos, 'EventForm': event_form, 'events': events, 'TrackerForm': tracker_form, 'trackers': trackers, 'MoodForm': mood_form, 'moods': moods, 'DreamForm': dream_form, 'dreams': dreams, 'DiaryForm': diary_form, 'diaries': diaries, } return render_to_response(template_name, template_value, context_instance=RequestContext(request))