def ajax_comment(request, object_type): if request.POST: content = request.POST.get("content","") obj_id = request.POST.get("pk","") date = timezone.now() milestone=None requirement_task=None if object_type == Milestone: milestone = get_object_or_404(object_type,pk=obj_id) else: requirement_task = get_object_or_404(object_type,pk=obj_id) comment = Comment(event_user=request.user,content=content, date_created=date, requirement_task=requirement_task, milestone=milestone, event_kind="K") comment.save() response_data = {} response_data['content'] = content response_data['date'] = date.__str__() response_data['user'] = request.user.username return HttpResponse(json.dumps(response_data), content_type="application/json")
def display_task(request, primkey, comments_field=None): """ Displays a task to viewers with a commet field It handles the displaying of all tasks : intra and cross The post method handles the receiving of a submitted comment and saves it Renders in : modal Refreshes : if new comment added, refreshed content of modal """ # TODO: Redirect people who aren't allowd to view this task. # Add edit and delete buttons for cores and supercoords # Display ALL details in the template - template needs work. print primkey dajax = Dajax() html_content = "" primkey = int(primkey) # Save comment if new comment given # Get Task + comments and populate try: task = Task.objects.get(pk = primkey) task_statuses = TASK_STATUSES print "task" if request.method == 'POST' and comments_field != None: # Add new comment if necessary if comments_field == "": dajax.add_css_class("#comments_field", "error") else : task_comment = Comment() task_comment.task = Task.objects.filter(id = task.id)[0] task_comment.author = request.user task_comment.comment_string = comments_field task_comment.time_stamp = datetime.datetime.now() task_comment.save() print "check comment" if ( comments_field != "" and comments_field != None ) or request.method == 'GET': print "true" # i.e. if "Submit Comment" was pressed, and comment was given OR GET ... need to refresh comments = Comment.objects.filter(task = task) html_content = render_to_string('tasks/display.html', locals(), RequestContext(request)) print html_content dajax.remove_css_class('#id_modal', 'hide') # Show modal dajax.assign("#id_modal", "innerHTML", html_content) # Populate modal print "done" except: show_alert(dajax, "error", "The task was not found") html_content = "" return dajax.json()
def rcomment(request): if request.POST: content = request.POST.get("content","") requirement_id = request.POST.get("pk","") date = timezone.now() requirement = get_object_or_404(Requirement,pk=requirement_id) comment = Comment(event_user=request.user,content=content, date_created=date, requirement_task=requirement,event_kind="K") comment.save() response_data = {} response_data['content'] = content response_data['date'] = date.__str__() response_data['user'] = request.user.username return HttpResponse(json.dumps(response_data), content_type="application/json")
def display_task(request, primkey): #TODO: Redirect people who aren't allowd to view this task. Add edit and delete buttons for cores and supercoords #Display ALL details in the template - template needs work. try: task = Task.objects.get(pk = primkey) task_statuses = TASK_STATUSES except: messages.error(request, "The task does not exist.") return redirect('dash.views.dash_view', permanent=True) # Handles comments related to task also if request.method == 'GET' and request.GET != {}: task_comment = Comment() task_comment.task = Task.objects.filter(id = task.id)[0] task_comment.author = request.user task_comment.comment_string = request.GET['comments_field'] task_comment.time_stamp = datetime.datetime.now() task_comment.save() comments = Comment.objects.filter(task = task) return render_to_response('tasks/display_temp.html', locals() )