Esempio n. 1
0
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()
Esempio n. 2
0
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() )