Install our app for a better experience!

HTML Feedback Guide

HTML Feedback Support in Teacher Evaluation API

๐ŸŽจ Rich Text Support

YES! Your API fully supports HTML-formatted feedback content, just like what CKEditor produces. The feedback_content field accepts and preserves all HTML formatting.

โœ… What HTML Features Are Supported

Your system supports all standard HTML elements including:

  • Headings: <h1>, <h2>, <h3>, etc.
  • Text Formatting: <strong>, <em>, <u>, <span>
  • Lists: <ul>, <ol>, <li>
  • Tables: <table>, <tr>, <td>, <th>
  • Paragraphs: <p>, <div>, <blockquote>
  • Styling: style attributes for colors, fonts, spacing
  • Links: <a href="..."> (preserved as-is)
  • Images: <img src="..."> (URLs preserved)

๐Ÿ“ CKEditor Integration

Your CKEditor already produces HTML that works perfectly with the API:

CKEditor Output โ†’ API Input

// What CKEditor gives you
const editorContent = editor.getData();
// Returns: "<h3>Feedback</h3><p>Student shows <strong>excellent</strong> work...</p>"

// Send directly to API
const feedbackData = {
    "title": "Assignment Feedback",
    "feedback_content": editorContent,  // HTML content as-is
    "teacher_name": "Dr. Smith",
    "assessment_type": "essay",
    // ... other fields
};

๐Ÿš€ API Examples with HTML Content

Simple HTML Feedback

{
    "organization_id": 1,
    "feedbacks": [
        {
            "title": "Essay Assignment Feedback",
            "feedback_content": "<h3>Overall Assessment</h3><p>The student demonstrates <strong>excellent critical thinking</strong> skills throughout this essay.</p><h4>Strengths:</h4><ul><li>Clear thesis statement</li><li>Well-structured arguments</li><li>Good use of evidence</li></ul><h4>Areas for Improvement:</h4><ol><li>Grammar and punctuation need attention</li><li>Conclusion could be stronger</li></ol><p><em>Grade: B+ (87%)</em></p>",
            "teacher_name": "Prof. Johnson",
            "teacher_experience_level": "experienced",
            "assessment_type": "essay",
            "student_level": "Undergraduate",
            "subject_area": "English Literature"
        }
    ]
}

Advanced HTML with Styling

{
    "organization_id": 1,
    "feedbacks": [
        {
            "title": "Lab Report Evaluation",
            "feedback_content": "<div style='font-family: Arial, sans-serif;'><h2 style='color: #2C3E50; border-bottom: 2px solid #3498DB;'>Lab Report Assessment</h2><table border='1' style='border-collapse: collapse; width: 100%;'><tr style='background-color: #f0f8ff;'><th style='padding: 8px;'>Criteria</th><th style='padding: 8px;'>Score</th><th style='padding: 8px;'>Comments</th></tr><tr><td style='padding: 8px;'>Methodology</td><td style='padding: 8px; text-align: center;'>90%</td><td style='padding: 8px;'>Excellent experimental design</td></tr><tr style='background-color: #f9f9f9;'><td style='padding: 8px;'>Data Analysis</td><td style='padding: 8px; text-align: center;'>75%</td><td style='padding: 8px;'>Good but needs more detail</td></tr></table><blockquote style='background-color: #fff8dc; padding: 15px; border-left: 4px solid #daa520;'><p><em>Overall, this is solid work that demonstrates good scientific understanding.</em></p></blockquote></div>",
            "teacher_name": "Dr. Chen",
            "teacher_experience_level": "expert",
            "assessment_type": "report",
            "student_level": "Graduate",
            "subject_area": "Chemistry"
        }
    ]
}

๐Ÿ”ง Integration Examples

Frontend JavaScript (sending CKEditor content)

// Get content from CKEditor
const feedbackHTML = CKEDITOR.instances.feedback_editor.getData();

// Prepare API payload
const apiPayload = {
    organization_id: selectedOrgId,
    feedbacks: [{
        title: document.getElementById('feedback_title').value,
        feedback_content: feedbackHTML,  // Rich HTML content
        teacher_name: document.getElementById('teacher_name').value,
        teacher_experience_level: document.getElementById('experience').value,
        assessment_type: document.getElementById('assessment_type').value,
        student_level: document.getElementById('student_level').value,
        subject_area: document.getElementById('subject_area').value
    }]
};

// Send to API
fetch('/assessment/api/feedbacks/bulk/', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${authToken}`
    },
    body: JSON.stringify(apiPayload)
})
.then(response => response.json())
.then(data => {
    console.log('Feedback submitted:', data);
});

Python Integration

import requests
from bs4 import BeautifulSoup

def submit_html_feedback(auth_token, org_id, html_feedback_data):
    """Submit HTML feedback via API"""

    url = "http://Preparebuddy.com/assessment/api/feedbacks/bulk/"
    headers = {
        "Authorization": f"Bearer {auth_token}",
        "Content-Type": "application/json"
    }

    # Prepare payload with HTML content
    payload = {
        "organization_id": org_id,
        "feedbacks": [{
            "title": html_feedback_data['title'],
            "feedback_content": html_feedback_data['html_content'],  # HTML as-is
            "teacher_name": html_feedback_data['teacher'],
            "assessment_type": "essay",
            "student_level": "Undergraduate",
            "subject_area": html_feedback_data['subject']
        }]
    }

    response = requests.post(url, json=payload, headers=headers)

    if response.status_code == 201:
        return response.json()
    else:
        raise Exception(f"API Error: {response.status_code} - {response.text}")

# Example usage
html_content = """
<h2>Assignment Evaluation</h2>
<p>The student shows <strong>excellent progress</strong> in understanding the material.</p>
<h3>Key Strengths:</h3>
<ul>
    <li>Clear analytical thinking</li>
    <li>Good use of examples</li>
    <li>Well-organized presentation</li>
</ul>
<p style="color: #2E8B57;"><strong>Grade: A- (92%)</strong></p>
"""

feedback_data = {
    'title': 'Weekly Assignment Review',
    'html_content': html_content,
    'teacher': 'Prof. Smith',
    'subject': 'Computer Science'
}

result = submit_html_feedback(auth_token, org_id, feedback_data)
print(f"Submitted feedback ID: {result['feedbacks'][0]['id']}")

๐Ÿ“Š Word Count Calculation

The API automatically calculates word count from HTML content by:

  1. Extracting text: Strips HTML tags to get plain text
  2. Counting words: Splits by whitespace and counts
  3. Storing both: Preserves original HTML + calculates word count
# Example: This HTML content
html_content = "<h3>Great work!</h3><p>The student shows <strong>excellent</strong> understanding.</p>"

# Becomes word count: 8
# (Great, work, The, student, shows, excellent, understanding)

๐ŸŽฏ Best Practices for HTML Feedback

1. Structure Your Feedback

<h3>Overall Assessment</h3>
<p>Brief summary...</p>

<h4>Strengths</h4>
<ul>
    <li>Point 1</li>
    <li>Point 2</li>
</ul>

<h4>Areas for Improvement</h4>
<ol>
    <li>Improvement 1</li>
    <li>Improvement 2</li>
</ol>

<h4>Grade</h4>
<p><strong>Final Score: A- (92%)</strong></p>

2. Use Semantic HTML

<!-- Good: Semantic elements -->
<h3>Assessment Results</h3>
<p><strong>Excellent work</strong> on this assignment.</p>
<blockquote>This demonstrates deep understanding.</blockquote>

<!-- Avoid: Presentation-only markup -->
<font color="red" size="5">Assessment Results</font>
<b>Excellent work</b> on this assignment.

3. Include Visual Elements

<!-- Tables for structured feedback -->
<table border="1" style="border-collapse: collapse;">
    <tr>
        <th>Criteria</th>
        <th>Score</th>
        <th>Comments</th>
    </tr>
    <tr>
        <td>Content Quality</td>
        <td>85%</td>
        <td>Well researched and organized</td>
    </tr>
</table>

<!-- Colored text for emphasis -->
<p style="color: #2E8B57;"><strong>Excellent work!</strong></p>
<p style="color: #CD853F;"><em>Needs improvement</em></p>

๐Ÿ”„ Processing Flow

Here's how HTML feedback flows through your system:

CKEditor โ†’ HTML Content โ†’ API Submission โ†’ Database Storage โ†’ AI Evaluation โ†’ Report Generation
    โ†“              โ†“              โ†“              โ†“              โ†“              โ†“
Rich Text   โ†’  HTML String  โ†’  JSON Payload  โ†’  TextField   โ†’  AI Analysis  โ†’  Formatted Report
  1. CKEditor produces rich HTML
  2. API receives and validates HTML
  3. Database stores HTML exactly as received
  4. AI Evaluation analyzes the HTML content
  5. Reports can render HTML or convert to plain text

๐Ÿ›ก๏ธ HTML Safety and Validation

Your system handles HTML safely:

  • Storage: HTML is stored exactly as received
  • Display: HTML can be rendered safely in reports
  • Analysis: AI models process both HTML structure and text content
  • Word Count: Automatically extracted from HTML

Optional: HTML Sanitization

If you want to restrict certain HTML elements:

from bs4 import BeautifulSoup

def sanitize_feedback_html(html_content):
    """Optional: Clean HTML if needed"""
    soup = BeautifulSoup(html_content, 'html.parser')

    # Remove potentially problematic elements
    for script in soup(["script", "style"]):
        script.decompose()

    # Keep only safe tags
    allowed_tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'br', 'strong', 
                   'em', 'u', 'ul', 'ol', 'li', 'table', 'tr', 'td', 'th', 
                   'blockquote', 'span', 'div', 'a']

    return str(soup)

๐Ÿ“ˆ Advanced Features

Embedded Images

<!-- Images are preserved with their URLs -->
<p>Student's diagram analysis:</p>
<img src="/media/uploads/student_diagram.png" alt="Student diagram" style="max-width: 500px;">
<p>The diagram shows good understanding of the concept.</p>

Styled Tables for Rubric Feedback

<table style="width: 100%; border-collapse: collapse; margin: 15px 0;">
    <tr style="background-color: #f8f9fa;">
        <th style="border: 1px solid #dee2e6; padding: 12px;">Criteria</th>
        <th style="border: 1px solid #dee2e6; padding: 12px;">Weight</th>
        <th style="border: 1px solid #dee2e6; padding: 12px;">Score</th>
        <th style="border: 1px solid #dee2e6; padding: 12px;">Comments</th>
    </tr>
    <tr>
        <td style="border: 1px solid #dee2e6; padding: 12px;">Content Quality</td>
        <td style="border: 1px solid #dee2e6; padding: 12px;">40%</td>
        <td style="border: 1px solid #dee2e6; padding: 12px;">85%</td>
        <td style="border: 1px solid #dee2e6; padding: 12px;">Excellent research and analysis</td>
    </tr>
</table>

๐Ÿงช Testing HTML Feedback

Use the provided test script:

# Run the HTML feedback examples
python html_feedback_examples.py

# Or integrate into your existing test
python simple_api_test.py

The test will show you: - โœ… HTML content is preserved exactly - โœ… Word count is calculated correctly
- โœ… Formatting appears in evaluation reports - โœ… AI analysis works with rich content

๐Ÿ’ก Pro Tips

  1. CKEditor Config: Your existing CKEditor configuration works perfectly
  2. Consistent Styling: Use CSS classes or inline styles for consistent formatting
  3. Mobile Friendly: Use responsive HTML for better report viewing
  4. Accessibility: Include alt text for images and proper heading structure
  5. Performance: Large HTML content is handled efficiently by your system

Your API is ready to handle rich HTML feedback content exactly as CKEditor produces it! ๐ŸŽ‰