- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.8k
 
收藏系统 #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
收藏系统 #766
Conversation
增加k8s部署配置 && 升级依赖
| 
           你好,感谢提交,脚本可否统一放在 blog.js中?或者直接使用form提交。  | 
    
| 
           另外麻烦修改下到dev分支哈。  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a favorite system allowing logged-in users to bookmark articles, view them in “我的收藏”, and toggle favorite status directly from article details.
- Added a "我的收藏" menu item in the navigation.
 - Introduced a new favorite list view and template to display user favorites.
 - Implemented new endpoints, models, and migrations for handling favorite actions.
 
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| templates/share_layout/nav.html | Added a new menu item linking to the favorite list page. | 
| templates/blog/favorite_list.html | Created a new template for displaying the user’s favorites. | 
| templates/blog/article_detail.html | Added favorite toggle functionality in the article detail view. | 
| blog/views.py | Introduced new endpoints for adding, removing, checking, and listing favorites. | 
| blog/urls.py | Added URL routes for the favorite related endpoints. | 
| blog/models.py | Added the Favorite model with a unique-together constraint. | 
| blog/migrations/0007_favorite.py | Added migration for the Favorite model. | 
| 
           好的,已经改了  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements a collection system that allows authenticated users to favorite articles, view them in their favorites list, and remove them when desired. Key changes include adding navigation links and pages for favorites, creating new view functions and URL routes for favorite-related actions, and implementing client‐side JavaScript to handle favorite toggling.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description | 
|---|---|
| templates/share_layout/nav.html | Added a navigation menu entry linking to the favorites list. | 
| templates/blog/favorite_list.html | Created a new page to display the user's favorited articles. | 
| templates/blog/article_detail.html | Inserted a favorite button on article detail pages for logged-in users. | 
| deploy/k8s/configmap.yaml | Updated database credentials for improved security. | 
| blog/views.py | Added view functions to manage favorite actions. | 
| blog/urls.py | Introduced new URL routes for favorite functionalities. | 
| blog/static/blog/js/blog.js | Added JavaScript to handle favorite checking, adding, and removal. | 
| blog/models.py | Created a new model to represent a favorited article. | 
| blog/migrations/0007_favorite.py | Added the migration for the new Favorite model. | 
| 
               | 
          ||
| <li class="menu-item"> | ||
| <a href="{% url 'blog:favorite_list' %}"> | ||
| <i class="fa fa-star"></i> 我的收藏 | 
    
      
    
      Copilot
AI
    
    
    
      May 21, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider wrapping the text '我的收藏' with a translation tag (e.g. {% trans '我的收藏' %}) for consistency with other localized strings.
| <i class="fa fa-star"></i> 我的收藏 | |
| <i class="fa fa-star"></i> {% trans '我的收藏' %} | 
| <div class="favorite-container" style="margin: 20px 0;"> | ||
| <button id="favoriteBtn" class="btn btn-primary" data-article-id="{{ article.id }}"> | ||
| <i class="fa fa-star"></i> | ||
| <span id="favoriteText">收藏文章</span> | 
    
      
    
      Copilot
AI
    
    
    
      May 21, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider wrapping '收藏文章' in a translation function to ensure consistent internationalization support as seen elsewhere in the application.
| <span id="favoriteText">收藏文章</span> | |
| <span id="favoriteText">{% trans "收藏文章" %}</span> | 
| const isFavorite = favoriteBtn.classList.contains('btn-danger'); | ||
| const url = isFavorite ? `/favorite/remove/${articleId}/` : `/favorite/add/${articleId}/`; | ||
| 
               | 
          ||
| fetch(url, { | 
    
      
    
      Copilot
AI
    
    
    
      May 21, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding error handling (e.g. catch blocks) for fetch requests will make the client-side interactions more robust in case of network failures.
登陆后可收藏,收藏后会显示在‘我的收藏’里,点击可跳转