Skip to content

Courses view on courses search#604

Merged
A1L13N merged 2 commits into
alphaonelabs:mainfrom
abdelrahman390:bug-courses-view
May 11, 2025
Merged

Courses view on courses search#604
A1L13N merged 2 commits into
alphaonelabs:mainfrom
abdelrahman390:bug-courses-view

Conversation

@abdelrahman390
Copy link
Copy Markdown
Contributor

@abdelrahman390 abdelrahman390 commented May 11, 2025

Related issues

Fixes #601

Checklist

  • Did you run the pre-commit? (If not, your PR will most likely not pass — please ensure it passes pre-commit)
  • Did you test the change? (Ensure you didn’t just prompt the AI and blindly commit — test the code and confirm it works)
  • Added screenshots to the PR description (if applicable)

Befor:
Annotation 2025-05-12 001018
Annotation 2025-05-12 001042

After:
Annotation 2025-05-12 010210
Annotation 2025-05-12 010242

Summary by CodeRabbit

  • New Features
    • Users now see a "View Course" button for courses they are enrolled in, providing direct access to course details.
  • Improvements
    • The course search page more clearly distinguishes between courses available to the user, invite-only courses, and those that can be added to the cart.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2025

"""

Walkthrough

The changes update the course search page to display a "View Course" button for logged-in users who are enrolled in or teaching a course, instead of showing "Add to Cart" or "Invite Only." The backend view now provides the template with a set of course titles associated with the current user, enabling this new conditional rendering.

Changes

File(s) Change Summary
web/views.py Modified course_search to add a set of course titles the user is enrolled in or teaches to the template context.
web/templates/courses/search.html Updated template logic to show "View Course" for courses in user_courses, else show "Invite Only" or "Add to Cart".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant View (course_search)
    participant Template (search.html)
    participant DB

    User->>View (course_search): Request course search page
    View (course_search)->>DB: Query courses
    alt User is authenticated
        alt User is teacher
            View (course_search)->>DB: Query courses taught by user
            View (course_search)->>Template: Pass user_courses = set of taught course titles
        else User is student
            View (course_search)->>DB: Query enrollments for user
            View (course_search)->>Template: Pass user_courses = set of enrolled course titles
        end
    else
        View (course_search)->>Template: Pass user_courses = None
    end
    Template (search.html)->>User: Render course cards
    alt Course in user_courses
        Template (search.html)->>User: Show "View Course" button
    else
        alt Course is invite-only
            Template (search.html)->>User: Show "Invite Only" label
        else
            Template (search.html)->>User: Show "Add to Cart" button
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Show enrolled or taught courses with "View Course" button for logged-in users (#601)

Suggested reviewers

  • A1L13N
    """

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a2286f and d2d171c.

📒 Files selected for processing (2)
  • web/templates/courses/search.html (1 hunks)
  • web/views.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/views.py (1)
web/models.py (2)
  • Course (234-333)
  • Enrollment (591-610)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Tests
  • GitHub Check: build-and-test
🔇 Additional comments (2)
web/views.py (2)

1441-1454: Good implementation of user course tracking!

This addition correctly tracks courses for both teachers and students. For teachers, it gets all courses they teach, and for students, it gets all courses they're enrolled in. The use of select_related("course") for student enrollments is particularly good as it avoids potential N+1 query issues.

Minor note: There's a small grammatical error in the comment - "if founded" should be "if found" or could be removed.


1467-1467: LGTM: Good addition to the context dictionary

Correctly adding the user_courses set to the template context allows the template to check if a user is enrolled in or teaching a course to show the appropriate action button.

✨ 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.
    • 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.

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
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Hello @abdelrahman390, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses issue #601 and modifies the courses search view to display a 'View Course' button for users who are either teachers or students enrolled in a course. The changes involve modifying the web/templates/courses/search.html template to include a conditional check for user enrollment and updating the web/views.py file to pass user course information to the template context.

Highlights

  • Feature: Adds a 'View Course' button to the course search results for enrolled students and teachers.
  • Template Modification: Updates the courses/search.html template to conditionally display the 'View Course' button based on user enrollment.
  • Context Update: Modifies the course_search view in web/views.py to include user course titles in the template context.

Changelog

  • web/templates/courses/search.html
    • Added a conditional check to display 'View Course' button if the user is enrolled in the course.
    • The condition checks if user_courses exists and if the course.title is in user_courses.
  • web/views.py
    • Initialized user_course_titles to None.
    • Determined if the user is a student.
    • Fetched courses for teachers and created a set of course titles.
    • Fetched enrollments for students and created a set of course titles from enrolled courses.
    • Added user_courses to the context passed to the template.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A button appears,
A path to courses so clear,
For students to learn.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a feature to display a 'View Course' button on the course search page for courses a user is already enrolled in, enhancing user experience. The implementation appears sound, but there are a few areas for improvement.

Summary of Findings

  • Clarity of Conditionals: The conditional logic in the template could be simplified for better readability. Consider combining conditions where appropriate to reduce nesting and improve understanding at a glance.
  • Data Retrieval Optimization: The current implementation retrieves user course titles, which could potentially be optimized to reduce database queries, especially if the number of courses or users grows significantly. Caching or more efficient querying strategies might be beneficial.

Merge Readiness

The changes are well-structured and address the intended functionality. However, addressing the clarity of conditionals and optimizing data retrieval would enhance the code's maintainability and performance. I recommend addressing these points before merging. I am unable to directly approve the pull request, and users should have others review and approve this code before merging.

Copy link
Copy Markdown
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

🔭 Outside diff range comments (1)
web/views.py (1)

1441-1473: 🧹 Nitpick (assertive)

Good implementation for displaying user-specific course information

The code successfully adds user-specific course data to the template context, allowing for personalized "View Course" buttons in search results. This is a nice enhancement to the user experience.

You could optimize the nested if statements on lines 1446-1447 by combining them:

- if request.user.is_authenticated:
-     if not request.user.profile.is_teacher:
-         is_student = True
+ if request.user.is_authenticated and not request.user.profile.is_teacher:
+     is_student = True
🧰 Tools
🪛 Ruff (0.8.2)

1446-1447: Use a single if statement instead of nested if statements

Combine if statements using and

(SIM102)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc9b70d and 6a2286f.

📒 Files selected for processing (2)
  • web/templates/courses/search.html (1 hunks)
  • web/views.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/views.py (1)
web/models.py (2)
  • Course (234-333)
  • Enrollment (591-610)
🪛 Ruff (0.8.2)
web/views.py

1446-1447: Use a single if statement instead of nested if statements

Combine if statements using and

(SIM102)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run Tests
  • GitHub Check: build-and-test

Comment thread web/templates/courses/search.html Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 11, 2025
@A1L13N A1L13N added this pull request to the merge queue May 11, 2025
Merged via the queue into alphaonelabs:main with commit 46bc218 May 11, 2025
11 checks passed
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.

logged in users see their enrolled or teached courses like unpurchased users

2 participants