def comment_event(request, event_id): if request.method == 'POST': form = CommentEventForm(request.POST) if form.is_valid(): event = get_object_or_404(Event, id=event_id) user = request.user comment = EventComment(event=event, user=user, text=form.cleaned_data['text']) comment.save() else: print form.errors return HttpResponseRedirect(reverse('events_show', args=[event_id]))
def saveComment(request): event_id = request.POST['event_id'] user_id = request.POST['user_id'] comment = request.POST['comment'] user_name = request.POST['user_name'] date = dateutil.parser.parse(request.POST['date']) event = Event.objects.get(pk=int(event_id)) e = EventComment(user_id=user_id,comment=comment,user_name=user_name,event=event,pub_date=date) e.save() return jsonhelper.json_response({'ok':'ok'})
def view_event(request, slug): """View event view.""" event = get_object_or_404(Event, slug=slug) attendees = event.attendees.exclude(groups__name='Mozillians') event_url = reverse('events_view_event', kwargs={'slug': slug}) email_att_initial = { 'subject': event.name, 'body': '%s\n%s' % (event.name, settings.SITE_URL + event_url)} email_att_form = EmailUsersForm(attendees, initial=email_att_initial) if request.method == 'POST': if not request.user.is_authenticated(): messages.error(request, 'Permission Denied') return redirect('main') event_comment = EventComment(event=event, user=request.user) event_comment_form = forms.EventCommentForm(request.POST, instance=event_comment) if event_comment_form.is_valid(): event_comment_form.save() messages.success(request, 'Comment saved') # provide new clean form event_comment_form = forms.EventCommentForm() else: event_comment_form = forms.EventCommentForm() return render(request, 'view_event.html', {'event': event, 'email_attendees_form': email_att_form, 'similar_events': event.get_similar_events(), 'comments': event.eventcomment_set.all(), 'event_comment_form': event_comment_form, 'event_comment_form_url': event_url})