Skip to content

Conversation

@swaparup36
Copy link
Contributor

@swaparup36 swaparup36 commented Mar 25, 2025

Screenshot 2025-03-26 004402

It resolves #3996

Replaced the code of /social. Now It's displaying data from the queue model in a listed manner.

Summary by CodeRabbit

  • New Features
    • The social page now offers a dynamic, interactive feed that displays updates with images, messages, and clear status indicators.
    • A refreshed layout with a header, detailed description, and breadcrumb navigation enhances user orientation and experience.
    • Pagination controls have been added to navigate through multiple pages of items in the social feed.
    • The routing for the social page has been updated to utilize a view function for improved content handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Walkthrough

The changes modify the /social page by replacing a static template render with a dynamic view. The URL route has been updated in the URL configuration to call a new view function, queue_social_view, which retrieves and orders items from the Queue model. The corresponding template has been restructured to display a dynamic feed with elements such as images, messages, status badges, and dates, replacing the previous static layout with social links.

Changes

File(s) Affected Change Summary
blt/urls.py Updated the social page route to use queue_social_view instead of the static TemplateView.as_view(template_name="social.html").
website/views/social.py, website/templates/social.html Added a new view function queue_social_view to fetch and order Queue items, and overhauled the template to render a dynamic social feed list.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant R as Router (blt/urls.py)
  participant V as queue_social_view
  participant Q as Queue Model
  participant T as Template Renderer

  U ->> R: Request /social
  R ->> V: Route to queue_social_view
  V ->> Q: Query ordered Queue items
  Q -->> V: Return queue items
  V ->> T: Render social.html with context
  T -->> U: Return rendered page
Loading

Assessment against linked issues

Objective Addressed Explanation
Replace the /social code with the content from the queue model, show it in a list with a link to the url and image (#3996)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6dcb7ac and 36ffc48.

📒 Files selected for processing (1)
  • website/views/social.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/views/social.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
website/views/social.py (1)

10-10: Remove debugging print statement before production deployment.

The print statement is useful for development but should be removed before deploying to production. It also lacks proper error handling if the queue is empty.

-    print("Queue items: ", queue_items[0].image)
website/templates/social.html (1)

45-137: Consider adding pagination UI for large datasets.

The template doesn't include pagination controls, which would be needed if you implement pagination in the view.

            </div>
+            <!-- Pagination -->
+            {% if page_obj.has_other_pages %}
+            <div class="mt-6 flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6 rounded-lg shadow-sm">
+                <div class="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
+                    <div>
+                        <p class="text-sm text-gray-700">
+                            Showing <span class="font-medium">{{ page_obj.start_index }}</span> to 
+                            <span class="font-medium">{{ page_obj.end_index }}</span> of 
+                            <span class="font-medium">{{ page_obj.paginator.count }}</span> results
+                        </p>
+                    </div>
+                    <div>
+                        <nav class="isolate inline-flex -space-x-px rounded-md shadow-sm" aria-label="Pagination">
+                            {% if page_obj.has_previous %}
+                            <a href="?page={{ page_obj.previous_page_number }}" class="relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0">
+                                <span class="sr-only">Previous</span>
+                                <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
+                                    <path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd" />
+                                </svg>
+                            </a>
+                            {% endif %}
+                            {% for i in page_obj.paginator.page_range %}
+                                {% if page_obj.number == i %}
+                                    <a href="#" aria-current="page" class="relative z-10 inline-flex items-center bg-blue-600 px-4 py-2 text-sm font-semibold text-white focus:z-20 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600">{{ i }}</a>
+                                {% else %}
+                                    <a href="?page={{ i }}" class="relative inline-flex items-center px-4 py-2 text-sm font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0">{{ i }}</a>
+                                {% endif %}
+                            {% endfor %}
+                            {% if page_obj.has_next %}
+                            <a href="?page={{ page_obj.next_page_number }}" class="relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0">
+                                <span class="sr-only">Next</span>
+                                <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
+                                    <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />
+                                </svg>
+                            </a>
+                            {% endif %}
+                        </nav>
+                    </div>
+                </div>
+            </div>
+            {% endif %}
        </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39a1484 and 638bed7.

📒 Files selected for processing (3)
  • blt/urls.py (2 hunks)
  • website/templates/social.html (1 hunks)
  • website/views/social.py (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
blt/urls.py (1)
website/views/social.py (1)
  • queue_social_view (6-11)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
blt/urls.py (1)

734-734: Good update in URL configuration.

The change from a static template view to a dynamic view function matches the PR objective to replace the /social code with queue model content.

website/templates/social.html (2)

45-137: Well-structured dynamic feed implementation.

The feed list is well-implemented with proper conditional rendering for optional fields (images, launch dates, URLs). The status badges provide good visual feedback, and an empty state is handled appropriately.


22-43: Well-designed header with breadcrumb navigation.

The header section with title, description, and breadcrumb navigation improves user orientation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
website/views/social.py (1)

7-28: Add docstring and consider additional enhancements

Consider adding a docstring to describe the function's purpose and behavior. Also, while the pagination implementation is solid, you might want to further enhance the view with:

  1. Database query error handling
  2. Optional logging for debugging purposes
def queue_social_view(request):
+    """
+    View function for the social page.
+    
+    Retrieves all Queue objects ordered by creation date (newest first)
+    and implements pagination (10 items per page).
+    
+    Args:
+        request: The HTTP request object
+        
+    Returns:
+        Rendered social.html template with paginated queue items
+    """
    # Get all queue items ordered by creation date
    queue_items = Queue.objects.all().order_by("-created")
website/templates/social.html (3)

49-57: Enhance image handling for better performance

The image element could benefit from additional attributes for performance and accessibility.

{% if item.image %}
    <div class="flex-shrink-0">
        <img src="{{ item.image }}"
             alt="Queue item image"
             class="h-24 w-24 rounded-lg object-cover"
             height="64"
             width="64"
+            loading="lazy"
+            alt="{% if item.message %}{{ item.message|truncatechars:50 }}{% else %}Queue update image{% endif %}"
        >
    </div>
{% endif %}

Adding loading="lazy" improves page performance by deferring off-screen images, and a more descriptive alt text enhances accessibility.


150-161: Improve pagination for large numbers of pages

The current pagination implementation displays all page numbers, which could become unwieldy with many pages. Consider implementing a truncated display that shows only a limited range around the current page.

-{% for num in page_obj.paginator.page_range %}
+{% with page_obj.number|add:-2 as start %}
+{% with page_obj.number|add:2 as end %}
+{% for num in page_obj.paginator.page_range %}
+    {% if num == 1 or num == page_obj.paginator.num_pages or num >= start|default:1 and num <= end|default:page_obj.paginator.num_pages %}
     {% if num == page_obj.number %}
        <span class="relative inline-flex items-center px-4 py-2 border border-[#e74c3c] bg-[#e74c3c] text-sm font-medium text-white">
            {{ num }}
        </span>
     {% else %}
        <a href="?page={{ num }}"
           class="relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
            {{ num }}
        </a>
     {% endif %}
+    {% elif num == start|add:-1 or num == end|add:1 %}
+        <span class="relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700">
+            ...
+        </span>
+    {% endif %}
 {% endfor %}
+{% endwith %}
+{% endwith %}

This approach shows page numbers near the current page, first and last pages, and ellipses (...) for skipped ranges, providing a more scalable pagination UI.


124-135: Enhance the empty state presentation

The current empty state is functional but minimal. Consider enhancing it with more information or a call to action to improve user experience.

{% empty %}
    <div class="p-6">
-        <div class="flex items-center text-sm text-blue-700">
+        <div class="flex flex-col items-center text-center py-8">
            <svg class="h-5 w-5 text-blue-400 mr-3"
                 xmlns="http://www.w3.org/2000/svg"
                 viewBox="0 0 20 20"
                 fill="currentColor">
                <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
            </svg>
-            No queue items found.
+            <p class="text-lg font-medium text-gray-900 mt-2">No updates available</p>
+            <p class="text-sm text-gray-500 mt-1">Check back later for new updates in our social feed</p>
+            <a href="{% url 'home' %}" class="mt-4 inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-[#e74c3c] hover:bg-[#c0392b] focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500">
+                Return to Home
+            </a>
        </div>
    </div>
{% endfor %}

This enhancement makes the empty state more visually prominent, adds more context, and provides a navigation option for users.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 638bed7 and 95de932.

📒 Files selected for processing (2)
  • website/templates/social.html (1 hunks)
  • website/views/social.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
website/templates/social.html (3)

5-7: Consistent Naming for Social Feed
There's a minor inconsistency: the title block sets "Social Feeds" (lines 5–7) while the header in the content uses "Social Feed" (line 28). For a consistent user experience, consider using the same terminology throughout the template.

Also applies to: 28-28


22-41: Header Section & Container Layout Clarity
The new container and header section are well structured. The use of responsive utility classes (e.g., min-h-screen, max-w-5xl, px-4) promotes a robust and adaptive layout. For long-term maintainability, consider centralizing frequently reused style definitions into a shared CSS component.


81-104: Readable Date and Time Information
The created and launched dates are rendered with intuitive icons and are formatted using Django’s date filter, which enhances readability. For internationalization, consider verifying that these date formats align with localized preferences.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95de932 and 6dcb7ac.

📒 Files selected for processing (2)
  • website/templates/social.html (1 hunks)
  • website/views/social.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/views/social.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test
🔇 Additional comments (5)
website/templates/social.html (5)

49-57: Image URL Security Validation
The template renders the image using {{ item.image }} without additional validation. As noted in a previous review, it is advisable to validate the URL (e.g., using a custom filter like is_safe_url) to mitigate the risk of rendering malicious content.


58-79: Dynamic Status Badge Rendering
The conditional logic properly handles the display of status badges for "Launched" versus "Pending" items. The badges are clearly marked with distinct colors and icons, effectively communicating the state of each queue item.


105-121: Secure External Link Rendering
The external link is implemented securely by including both target="_blank" and rel="noopener noreferrer", which helps prevent potential security vulnerabilities such as reverse tabnabbing.


125-137: Informative Empty Feed Fallback
The template gracefully handles cases where there are no queue items by displaying a friendly message along with an icon. This ensures users are not met with an empty screen.


141-171: User-Friendly Pagination Controls
The pagination mechanism is both accessible and visually clear. ARIA labeling is used in the <nav> element, and conditional rendering of previous/next links provides a complete navigation experience. It might be beneficial to confirm that the query parameters in the pagination URLs persist any existing filters.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 25, 2025
Copy link
Collaborator

@DonnieBLT DonnieBLT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update this to only filter launched queue_items = Queue.objects.all().order_by("-created")

@swaparup36
Copy link
Contributor Author

please update this to only filter launched queue_items = Queue.objects.all().order_by("-created")

Done!!

@swaparup36 swaparup36 requested a review from DonnieBLT March 26, 2025 07:22
@DonnieBLT DonnieBLT merged commit 4f4611a into OWASP-BLT:main Mar 27, 2025
11 checks passed
mahii-17 pushed a commit to mahii-17/BLT that referenced this pull request Mar 27, 2025
* replaced /social code with content from queue model

* paginator added to /social

* done the changes suggested by bot

* added filter for only launched items in queue model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replace the /social code with the content from the queue model, show it in a list with a link to the url and image

2 participants