def poll_vote(request): if request.method == 'POST' and request.is_ajax(): vote_choice = request.POST['vote'] poll_id = request.POST['poll_id'] print('********SERVER RECEIVED VOTE FOR POLL: ' + poll_id + '********') poll = get_object_or_404(Poll, pk=poll_id) vote, created = VotePoll.objects.get_or_create(choice=vote_choice, user=request.user, poll=poll) if created: activity = Activity(activity_type='POLL-VOTE', user=request.user, assoc_obj_id=vote.id) activity.save() return HttpResponse(json.dumps({'vote_id': vote.id}), content_type='application/json') return HttpResponse(json.dumps({'vote_id': -1}), content_type='application/json')
def make_announcement(request): announcement_form = AnnouncementForm(request.POST) if announcement_form.is_valid(): announcement = announcement_form.save() announcement.create_date = timezone.now() announcement.feed = Feed.objects.get( neighborhood=request.user.userprofile.house.neighborhood) announcement.type = 'ANNOUNCEMENT' announcement.user = request.user announcement.save() if announcement.id is not None: activity = Activity(activity_type='ANNOUNCEMENT', user=request.user, assoc_obj_id=announcement.id) activity.save() return HttpResponseRedirect('/neighborhood/home/') return HttpResponse("You're not allowed to make announcements homie.")
def new_event(request): if request.method == 'POST': eventform = EventForm(request.POST) if eventform.is_valid(): event = eventform.save() event.neighborhood = request.user.userprofile.house.neighborhood event.creator = request.user event.save() if event.id is not None: activity = Activity(activity_type='EVENT-CREATE', user=request.user, assoc_obj_id=event.id) activity.save() return HttpResponseRedirect('/neighborhood/home') else: return HttpResponse("Event form is not valid!") return HttpResponse('Not a POST request')
def submit_post(request): post_dict = [] if request.is_ajax() and request.method == 'POST': text = request.POST['text'] user = request.user neighborhood = request.user.userprofile.house.neighborhood feed = Feed.objects.get(neighborhood=neighborhood) post_type = request.POST['post_type'] marker_id = request.POST['marker_id'] post = FeedPost(text=text, user=user, feed=feed, type=post_type) print("HAS_MARKER IS: " + request.POST['has_marker']) if int(request.POST['has_marker']) == 1: post.marker = Marker.objects.get(id=marker_id) print('*******************ADDED MARKER TO POST*******************') if post: print('**********************SANITY CHECK*************************') post.save() if post.id is not None: activity = Activity(activity_type='POST', user=request.user, assoc_obj_id=post.id) activity.save() return HttpResponse(json.dumps({'post': post_dict}), content_type='application/json')
def new_poll(request): if request.method == 'POST': # Validate the poll topic Question and Choices poll_form = PollForm(request.POST) if poll_form.is_valid(): neighborhood = request.user.userprofile.house.neighborhood # Save question_form and create Question object poll = poll_form.save() poll.neighborhood = neighborhood poll.creator = request.user poll.save() if poll.id is not None: # create feedpost to post this new poll to the neighborhood feed feed = Feed.objects.get(neighborhood=neighborhood) feedpost = FeedPost(text=poll.question_text, user=request.user, type='POLL', feed=feed, decision=poll) feedpost.save() # create activity for user profile activity = Activity(activity_type='POLL-CREATE', user=request.user, assoc_obj_id=poll.id) activity.save() return HttpResponseRedirect('/neighborhood/home') else: return HttpResponse("Poll is not valid")