def list_details(request, feedback_id): page = request.GET.get('page') if not page: page = 1 feedback = Feedback.objects.get(pk=feedback_id) details = Detail.objects.filter(feedback=feedback_id) paginator = Paginator(details, settings.DETAILS_PER_PAGE) try: details_range = paginator.page(page) except EmptyPage: # If page is out of range details_range = paginator.range(paginator.num_pages) return render(request, 'reviews/details/list.html', { 'feedback': feedback, 'details': details_range, })
def view_task(request, task_id): """ View task details. Allow task details to be edited. """ task = get_object_or_404(Item, pk=task_id) comment_list = Comment.objects.filter(task=task_id) # Before doing anything, make sure the accessing user has permission to view this item. # Determine the group this task belongs to, and check whether current user is a member of that group. # Admins can edit all tasks. if task.list.team or request.user.is_staff: auth_ok = 1 if request.POST: form = EditItemForm(request.POST, instance=task) if form.is_valid(): form.save() # Also save submitted comment, if non-empty if request.POST['comment-body']: c = Comment( author=request.user, task=task, body=request.POST['comment-body'], ) c.save() # And email comment to all people who have participated in this thread. email_subject = render_to_string("todolist/email/assigned_subject.txt", {'task': task}) email_body = render_to_string("todolist/email/newcomment_body.txt", {'task': task, 'body': request.POST['comment-body'], 'site': current_site, 'user': request.user}) # Get list of all thread participants - task creator plus everyone who has commented on it. recip_list = [] recip_list.append(task.created_by.email) commenters = Comment.objects.filter(task=task) for c in commenters: recip_list.append(c.author.email) # Eliminate duplicate emails with the Python set() function recip_list = set(recip_list) # Send message try: send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False) messages.success(request, "Comment sent to thread participants.") except: messages.error(request, "Comment saved but mail not sent. Contact your administrator.") messages.success(request, "The task has been edited.") return HttpResponseRedirect(reverse('todo-incomplete_tasks', args=[task.list.id, task.list.slug])) else: form = EditItemForm(instance=task) if task.due_date: thedate = task.due_date else: thedate = datetime.datetime.now() else: messages.info(request, "You do not have permission to view/edit this task.") paginator = Paginator(comment_list, 10) # Show 25 comments per page # paginator.orphans = int(5) paginator.range = range(5) page = request.GET.get('page') try: comments = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comments = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comments = paginator.page(paginator.num_pages) return render_to_response('todolist/view_task.html', locals(), context_instance=RequestContext(request))
def view_task(request, task_id): """ View task details. Allow task details to be edited. """ task = get_object_or_404(Item, pk=task_id) comment_list = Comment.objects.filter(task=task_id) # Before doing anything, make sure the accessing user has permission to view this item. # Determine the group this task belongs to, and check whether current user is a member of that group. # Admins can edit all tasks. if task.list.team or request.user.is_staff: auth_ok = 1 if request.POST: form = EditItemForm(request.POST, instance=task) if form.is_valid(): form.save() # Also save submitted comment, if non-empty if request.POST['comment-body']: c = Comment( author=request.user, task=task, body=request.POST['comment-body'], ) c.save() # And email comment to all people who have participated in this thread. email_subject = render_to_string( "todolist/email/assigned_subject.txt", {'task': task}) email_body = render_to_string( "todolist/email/newcomment_body.txt", { 'task': task, 'body': request.POST['comment-body'], 'site': current_site, 'user': request.user }) # Get list of all thread participants - task creator plus everyone who has commented on it. recip_list = [] recip_list.append(task.created_by.email) commenters = Comment.objects.filter(task=task) for c in commenters: recip_list.append(c.author.email) # Eliminate duplicate emails with the Python set() function recip_list = set(recip_list) # Send message try: send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False) messages.success( request, "Comment sent to thread participants.") except: messages.error( request, "Comment saved but mail not sent. Contact your administrator." ) messages.success(request, "The task has been edited.") return HttpResponseRedirect( reverse('todo-incomplete_tasks', args=[task.list.id, task.list.slug])) else: form = EditItemForm(instance=task) if task.due_date: thedate = task.due_date else: thedate = datetime.datetime.now() else: messages.info(request, "You do not have permission to view/edit this task.") paginator = Paginator(comment_list, 10) # Show 25 comments per page # paginator.orphans = int(5) paginator.range = range(5) page = request.GET.get('page') try: comments = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comments = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comments = paginator.page(paginator.num_pages) return render_to_response('todolist/view_task.html', locals(), context_instance=RequestContext(request))
def view_event(request, year, month, day, slug): """ View event details. """ event = get_object_or_404(Event, slug=slug) comment_list = EventComment.objects.filter(event=event.id) # if request.user.is_staff: auth_ok = 1 if request.POST: form = EditItemForm(request.POST, instance=event) if form.is_valid(): # Also save submitted comment, if non-empty if request.POST['comment']: c = EventComment( user=request.user, event=event, comment=request.POST['comment'], ) c.save() # And email comment to all people who have participated in this thread. # email_subject = render_to_string("events/email/owner_notification_on_add_comment.txt", {'event': event}) # email_body = render_to_string("events/email/owner_notification_on_add_comment.txt", # {'event': event, 'body': request.POST['comment'], # 'site': current_site, 'user': request.user}) # # Get list of all thread participants - task creator plus everyone who has commented on it. # recip_list = [] # recip_list.append(task.created_by.email) # commenters = Comment.objects.filter(task=task) # for c in commenters: # recip_list.append(c.author.email) # # Eliminate duplicate emails with the Python set() function # recip_list = set(recip_list) # # Send message # try: # send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False) # messages.success(request, "Comment sent to thread participants.") # except: # messages.error(request, "Comment saved but mail not sent. Contact your administrator.") # messages.success(request, "The event has been edited.") return HttpResponseRedirect( reverse('event_detail', kwargs={ 'slug': event.slug, 'year': '{0:04d}'.format(event.start.year), 'month': '{0:02d}'.format(event.start.month), 'day': '{0:02d}'.format(event.start.day), })) else: form = EditItemForm(instance=event) paginator = Paginator(comment_list, 20) # Show 25 comments per page # paginator.orphans = int(5) paginator.range = range(5) page = request.GET.get('page') try: comments = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comments = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comments = paginator.page(paginator.num_pages) return render_to_response('events/event_detail.html', locals(), context_instance=RequestContext(request))
def view_event(request, year, month, day, slug): """ View event details. """ event = get_object_or_404(Event, slug=slug) comment_list = EventComment.objects.filter(event=event.id) # if request.user.is_staff: auth_ok = 1 if request.POST: form = EditItemForm(request.POST, instance=event) if form.is_valid(): # Also save submitted comment, if non-empty if request.POST['comment']: c = EventComment( user=request.user, event=event, comment=request.POST['comment'], ) c.save() # And email comment to all people who have participated in this thread. # email_subject = render_to_string("events/email/owner_notification_on_add_comment.txt", {'event': event}) # email_body = render_to_string("events/email/owner_notification_on_add_comment.txt", # {'event': event, 'body': request.POST['comment'], # 'site': current_site, 'user': request.user}) # # Get list of all thread participants - task creator plus everyone who has commented on it. # recip_list = [] # recip_list.append(task.created_by.email) # commenters = Comment.objects.filter(task=task) # for c in commenters: # recip_list.append(c.author.email) # # Eliminate duplicate emails with the Python set() function # recip_list = set(recip_list) # # Send message # try: # send_mail(email_subject, email_body, task.created_by.email, recip_list, fail_silently=False) # messages.success(request, "Comment sent to thread participants.") # except: # messages.error(request, "Comment saved but mail not sent. Contact your administrator.") # messages.success(request, "The event has been edited.") return HttpResponseRedirect(reverse('event_detail', kwargs={ 'slug': event.slug, 'year': '{0:04d}'.format(event.start.year), 'month': '{0:02d}'.format(event.start.month), 'day': '{0:02d}'.format(event.start.day), })) else: form = EditItemForm(instance=event) paginator = Paginator(comment_list, 20) # Show 25 comments per page # paginator.orphans = int(5) paginator.range = range(5) page = request.GET.get('page') try: comments = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comments = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comments = paginator.page(paginator.num_pages) return render_to_response('events/event_detail.html', locals(), context_instance=RequestContext(request))