Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nitinawari
Copy link
Contributor

@nitinawari nitinawari commented Jun 1, 2025

close #2577

There was no link with badges and their icons, so I first linked them and then showed them on the about us pages for motivation for new users
image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added a new "Streak Badges" section to the About page, showcasing badges for various activity streak durations with images and descriptions.
  • Chores
    • Linked streak badge icons to their respective badges for improved display and recognition.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 1, 2025

Walkthrough

A data migration script was added to associate streak badge icons with Badge model instances by copying static icon files to the media directory and updating badge records. Additionally, the about page template was updated to display a new "Streak Badges" section, showcasing various streak badge images and descriptions.

Changes

File(s) Change Summary
website/migrations/0242_link_streak_badge_icons.py Added a migration script to link streak badge icons to Badge model instances by copying icon files and updating DB.
website/templates/about.html Added a new "Streak Badges" section with images and descriptions for various streak badges.

Sequence Diagram(s)

sequenceDiagram
    participant Migration
    participant BadgeModel
    participant FileSystem

    Migration->>BadgeModel: Query badges by title
    loop For each badge title
        BadgeModel->>FileSystem: Check if static icon file exists
        alt Icon exists
            FileSystem->>FileSystem: Copy icon to media directory
            FileSystem->>BadgeModel: Open and save icon to badge's icon field
            BadgeModel->>BadgeModel: Update badge record
        else Icon missing
            Note right of Migration: Skip badge update
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate Streak Badges Display on About Us Page - Feature examples of streak badges and achievements (#2577)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Data migration for badge icons (website/migrations/0242_link_streak_badge_icons.py) The migration prepares badge icons but does not implement display or history on profile pages as required by the issue.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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/migrations/0242_link_streak_badge_icons.py (1)

36-36: Add missing final newline.

The file is missing a final newline as indicated by the pipeline failure.

    operations = [
        migrations.RunPython(link_streak_badge_icons),
-    ] 
+    ]
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 36-36: Final newline missing

(C0304)

website/templates/about.html (1)

71-139:

Details

❓ Verification inconclusive

Consider using database Badge instances instead of static file references.

The template directly references static badge images, but the migration suggests these badges should be dynamic from the Badge model. This creates a potential inconsistency where badge icons are stored in the database but not used by the template.

Consider whether the template should reference Badge model instances instead:

<!-- Alternative approach using database badges -->
{% for badge in streak_badges %}
    <div class="flex flex-col items-center">
        {% if badge.icon %}
            <img src="{{ badge.icon.url }}"
                 alt="{{ badge.title }} Badge"
                 class="w-24 h-24 rounded-xl border-4 border-[#e74c3c] shadow-lg mb-3 object-contain"
                 width="96"
                 height="96">
        {% endif %}
        <span class="text-lg font-bold text-[#e74c3c]">{{ badge.title }}</span>
        <span class="text-gray-600 text-center text-sm">{{ badge.description }}</span>
    </div>
{% endfor %}

This would require passing streak badges from the view context.


🏁 Script executed:

#!/bin/bash
# Description: Check if there are views that pass badge data to templates
# Expected: Find view functions that query Badge model for templates

# Search for Badge model usage in views
ast-grep --pattern 'Badge.objects.$$$'

# Check if about view passes any badge context
rg -A 10 -B 5 "def.*about" --type py

Length of output: 2133


Potential Dynamic Badge Context Needed for About Page

Our search did not find any view supplying streak badge data to about.html. If these badges are meant to be managed via the Badge model, the about view must query and pass them to the template. Otherwise, the current static references are appropriate.

• No render(..., "about.html", ...) call in website/views includes a streak_badges context key
• No existing code in views populates a streak_badges or similar variable

Next steps:

  1. Confirm whether streak badges should be static or driven by the database.
  2. If dynamic:
    from website.models import Badge
    
    def about(request):
        streak_badges = Badge.objects.filter(type="streak").order_by("title")
        return render(request, "about.html", {"streak_badges": streak_badges})
    And refactor the template:
    {% for badge in streak_badges %}
      <div class="flex flex-col items-center">
        <img src="{{ badge.icon.url }}" alt="{{ badge.title }} Badge" >
        <span class="text-lg font-bold text-[#e74c3c]">{{ badge.title }}</span>
        <span class="text-gray-600 text-center text-sm">{{ badge.description }}</span>
      </div>
    {% endfor %}
  3. If static is intended, no change is required.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 5450ac5 and 9889b76.

📒 Files selected for processing (2)
  • website/migrations/0242_link_streak_badge_icons.py (1 hunks)
  • website/templates/about.html (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
website/migrations/0242_link_streak_badge_icons.py (1)
website/models.py (1)
  • Badge (1381-1395)
🪛 Pylint (3.3.7)
website/migrations/0242_link_streak_badge_icons.py

[convention] 23-23: Line too long (113/100)

(C0301)


[convention] 36-36: Final newline missing

(C0304)


[convention] 1-1: Missing module docstring

(C0114)


[convention] 1-1: Module name "0242_link_streak_badge_icons" doesn't conform to snake_case naming style

(C0103)


[error] 4-4: Unable to import 'django.conf'

(E0401)


[error] 5-5: Unable to import 'django.core.files'

(E0401)


[error] 6-6: Unable to import 'django.db'

(E0401)


[convention] 8-8: Missing function or method docstring

(C0116)


[convention] 9-9: Variable name "Badge" doesn't conform to snake_case naming style

(C0103)


[warning] 8-8: Unused argument 'schema_editor'

(W0613)


[convention] 30-30: Missing class docstring

(C0115)


[refactor] 30-30: Too few public methods (0/2)

(R0903)

🪛 GitHub Actions: CI/CD Optimized
website/migrations/0242_link_streak_badge_icons.py

[error] 1-1: isort formatting check failed. The file was automatically modified by isort to fix import sorting issues.

🔇 Additional comments (3)
website/migrations/0242_link_streak_badge_icons.py (1)

19-19:

Details

✅ Verification successful

Verify that Badge instances exist for all mapped titles.

The migration assumes that Badge instances with the specified titles already exist in the database. If any badges are missing, they will be silently skipped.


🏁 Script executed:

#!/bin/bash
# Description: Check if Badge model instances exist for the mapped titles
# Expected: All badge titles should exist in the database

# Search for Badge model creation or fixtures that create these badges
ast-grep --pattern 'Badge.objects.create($$$title=$_$$$)'

# Also check for any badge fixtures or seeds
fd -e json -e py -e sql . --exec grep -l "Weekly Streak\|15 Day Streak\|Monthly Streak\|100 Day Streak\|Six Month Streak\|Yearly Streak" {} \;

Length of output: 327


🏁 Script executed:

#!/bin/bash
# Inspect badge creation in migration 0168 to confirm titles are created before linking icons
rg -n "Badge.objects.create" -A 3 website/migrations/0168_add_streak_badges.py || true
rg -n "bulk_create" -A 3 website/migrations/0168_add_streak_badges.py || true
grep -nE "Weekly Streak|15 Day Streak|Monthly Streak|100 Day Streak|Six Month Streak|Yearly Streak" website/migrations/0168_add_streak_badges.py

Length of output: 560


🏁 Script executed:

#!/bin/bash
# Show RunPython usage and the function adding streak badges
rg -n -C3 "RunPython" website/migrations/0168_add_streak_badges.py || true
rg -n -C3 "def add_streak_badges" website/migrations/0168_add_streak_badges.py || true
rg -n -C3 "apps.get_model" website/migrations/0168_add_streak_badges.py || true

Length of output: 405


🏁 Script executed:

#!/bin/bash
# Display the contents of the migration that adds streak badges
sed -n '1,200p' website/migrations/0168_add_streak_badges.py

Length of output: 2759


🏁 Script executed:

#!/bin/bash
# Display migration 0242 to inspect title-icon mapping and dependencies
sed -n '1,200p' website/migrations/0242_link_streak_badge_icons.py

Length of output: 1565


Streak badges already created in prior migration
Migration 0168_add_streak_badges.py uses get_or_create to create all six streak badges (“Weekly Streak”, “15 Day Streak”, “Monthly Streak”, “100 Day Streak”, “Six Month Streak”, “Yearly Streak”), so they will exist by the time migration 0242_link_streak_badge_icons.py runs. No further verification needed.

website/templates/about.html (2)

80-84: LGTM! Excellent accessibility and responsive design implementation.

The badge image implementations are well-structured with:

  • Proper alt attributes for accessibility
  • Explicit width and height attributes for performance
  • Responsive grid layout with appropriate breakpoints
  • Consistent styling with proper contrast and visual hierarchy
  • Object-contain class to maintain aspect ratios

Also applies to: 90-94, 100-104, 110-114, 120-124, 130-134


73-76: LGTM! Good motivational content with proper internationalization.

The section heading and description effectively motivate users to maintain streaks. All text content properly uses Django's i18n translation tags for internationalization support.

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

♻️ Duplicate comments (1)
website/migrations/0242_link_streak_badge_icons.py (1)

9-30: ⚠️ Potential issue

Previous review suggestions were not implemented - add error handling and logging.

The migration function still lacks the error handling, logging, and robustness improvements suggested in the previous review. Without proper exception handling around file operations, this migration could fail partially, leaving the database in an inconsistent state.

Please implement the error handling and logging suggestions from the previous review to ensure migration reliability.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 24-24: Line too long (113/100)

(C0301)


[convention] 9-9: Missing function or method docstring

(C0116)


[convention] 10-10: Variable name "Badge" doesn't conform to snake_case naming style

(C0103)


[warning] 9-9: Unused argument 'schema_editor'

(W0613)

🧹 Nitpick comments (2)
website/migrations/0242_link_streak_badge_icons.py (2)

24-24: Fix line length violation.

This line exceeds the 100-character limit (113 characters). Break it into multiple lines for better readability.

-                media_icon_path = os.path.join(settings.MEDIA_ROOT, "badges", os.path.basename(static_icon_path))
+                media_icon_path = os.path.join(
+                    settings.MEDIA_ROOT, "badges", os.path.basename(static_icon_path)
+                )
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 24-24: Line too long (113/100)

(C0301)


9-9: Add function docstring for better documentation.

The migration function is missing a docstring that explains its purpose and behavior.

 def link_streak_badge_icons(apps, schema_editor):
+    """Link streak badge icons from static files to Badge model instances."""
     Badge = apps.get_model("website", "Badge")
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 9-9: Missing function or method docstring

(C0116)


[warning] 9-9: Unused argument 'schema_editor'

(W0613)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9889b76 and 9006c07.

📒 Files selected for processing (1)
  • website/migrations/0242_link_streak_badge_icons.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
website/migrations/0242_link_streak_badge_icons.py (1)
website/models.py (1)
  • Badge (1381-1395)
🪛 Pylint (3.3.7)
website/migrations/0242_link_streak_badge_icons.py

[convention] 24-24: Line too long (113/100)

(C0301)


[convention] 1-1: Missing module docstring

(C0114)


[convention] 1-1: Module name "0242_link_streak_badge_icons" doesn't conform to snake_case naming style

(C0103)


[error] 4-4: Unable to import 'django.conf'

(E0401)


[error] 5-5: Unable to import 'django.core.files'

(E0401)


[error] 6-6: Unable to import 'django.db'

(E0401)


[convention] 9-9: Missing function or method docstring

(C0116)


[convention] 10-10: Variable name "Badge" doesn't conform to snake_case naming style

(C0103)


[warning] 9-9: Unused argument 'schema_editor'

(W0613)


[convention] 32-32: Missing class docstring

(C0115)


[refactor] 32-32: Too few public methods (0/2)

(R0903)

🔇 Additional comments (1)
website/migrations/0242_link_streak_badge_icons.py (1)

32-38: Migration class structure is correct.

The Migration class is properly configured with the correct dependencies and operations for this data migration.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 32-32: Missing class docstring

(C0115)


[refactor] 32-32: Too few public methods (0/2)

(R0903)

@DonnieBLT DonnieBLT enabled auto-merge June 4, 2025 16:39
@DonnieBLT DonnieBLT added this pull request to the merge queue Jun 5, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jun 5, 2025
* added new streak badges and showed them on aboutus pages

* pre-commit fix

---------

Co-authored-by: DonnieBLT <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 5, 2025
@DonnieBLT DonnieBLT merged commit 1e2cdda into OWASP-BLT:main Jul 1, 2025
15 checks passed
DonnieBLT added a commit that referenced this pull request Jul 1, 2025
DonnieBLT added a commit that referenced this pull request Jul 1, 2025
@DonnieBLT
Copy link
Collaborator

DonnieBLT commented Jul 1, 2025

the migration didn't work. can you separate this into a separate command that runs please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants