From 0c5c7e64c8b477986e5f715015fca774f168024a Mon Sep 17 00:00:00 2001 From: Krishna Kaushal Date: Mon, 18 Nov 2024 21:42:10 +0530 Subject: [PATCH 01/24] Feature added to recommend Users from profile page --- website/admin.py | 9 + ...on_recommendation_unique_recommendation.py | 51 ++++++ website/models.py | 22 +++ website/serializers.py | 1 + website/templates/profile.html | 159 ++++++++++++++++++ website/views/user.py | 28 ++- 6 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 website/migrations/0154_recommendation_recommendation_unique_recommendation.py diff --git a/website/admin.py b/website/admin.py index a811f2669..4b8f77b36 100644 --- a/website/admin.py +++ b/website/admin.py @@ -211,6 +211,11 @@ def short_description(self, obj): admin.site.unregister(User) +class RecommendationAdmin(admin.ModelAdmin): + list_display = ("recommender", "recommended_user", "created_at") + search_fields = ("recommender__username", "recommended_user__username") + + class UserAdmin(ImportExportModelAdmin): resource_class = UserResource list_display = ( @@ -245,6 +250,7 @@ class UserProfileAdmin(admin.ModelAdmin): "flagged_count", "subscribed_domains_count", "subscribed_users_count", + "recommendation_count", "x_username", "linkedin_url", "github_url", @@ -273,6 +279,9 @@ def subscribed_domains_count(self, obj): def subscribed_users_count(self, obj): return obj.subscribed_users.count() + def recommendation_count(self, obj): + return obj.recommendations.count() + class IssueScreenshotAdmin(admin.ModelAdmin): model = IssueScreenshot diff --git a/website/migrations/0154_recommendation_recommendation_unique_recommendation.py b/website/migrations/0154_recommendation_recommendation_unique_recommendation.py new file mode 100644 index 000000000..e3922a90f --- /dev/null +++ b/website/migrations/0154_recommendation_recommendation_unique_recommendation.py @@ -0,0 +1,51 @@ +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("website", "0153_delete_contributorstats"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Recommendation", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "recommended_user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="received_recommendations", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "recommender", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="given_recommendations", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + migrations.AddConstraint( + model_name="recommendation", + constraint=models.UniqueConstraint( + fields=("recommender", "recommended_user"), name="unique_recommendation" + ), + ), + ] \ No newline at end of file diff --git a/website/models.py b/website/models.py index 3398c8e1c..0a7f11c95 100644 --- a/website/models.py +++ b/website/models.py @@ -890,6 +890,28 @@ def __str__(self): return f"ActivityLog by {self.user.username} at {self.recorded_at}" +class Recommendation(models.Model): + recommender = models.ForeignKey( + User, on_delete=models.CASCADE, related_name="given_recommendations" + ) + recommended_user = models.ForeignKey( + User, on_delete=models.CASCADE, related_name="received_recommendations" + ) + created_at = models.DateTimeField(auto_now_add=True) + + class Meta: + constraints = [ + models.UniqueConstraint( + fields=["recommender", "recommended_user"], name="unique_recommendation" + ) + ] + + def __str__(self): + return ( + f"Recommendation from {self.recommender.username} to {self.recommended_user.username}" + ) + + class DailyStatusReport(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) date = models.DateField() diff --git a/website/serializers.py b/website/serializers.py index a73857674..a9282df64 100644 --- a/website/serializers.py +++ b/website/serializers.py @@ -68,6 +68,7 @@ class Meta: "issue_flaged", "total_score", "activities", + "recommendations", ) diff --git a/website/templates/profile.html b/website/templates/profile.html index bdda41c67..a9d107a8f 100644 --- a/website/templates/profile.html +++ b/website/templates/profile.html @@ -269,6 +269,49 @@ color: #ff5722; font-weight: bold; } + + /* Added styles for Recommendations */ + .recommend-user { + background-color: #fff; + padding: 20px; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0,0,0,0.1); + } + .red-btn { + background-color: #cc0000; + color: #fff; + border: none; + margin : 10px; + padding: 10px 20px; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.3s; + } + .red-btn:hover { + background-color: #990000; + } + .error { + color: #cc0000; + font-weight: bold; + margin-bottom: 15px; + } + + #user_list { + max-height: 200px; + overflow-y: auto; + border: 1px solid #ddd; + padding: 10px; + border-radius: 5px; + } + + .user-item { + padding: 5px 0; + border-bottom: 1px solid #eee; + } + + .user-item:last-child { + border-bottom: none; + } {% endblock style %} {% block content %} @@ -494,6 +537,9 @@ + @@ -515,6 +561,31 @@
+
+
Spot a Talent? Recommend Now!
+
+ {% csrf_token %} + + +
+ {% for user in all_users %} +
+ + +
+ {% endfor %} +
+ +
+
@@ -671,6 +742,65 @@

Following:

+
- {% if object.userprofile.recommendation_blurb %} -
-

Recommendation Blurb

+
+

Recommendation Blurb

+ {% if object.userprofile.recommendation_blurb %}

{{ object.userprofile.recommendation_blurb }}

- {% if user.is_authenticated and user != object %} - - {% endif %} + {% else %} +

No recommendation blurb yet.

+ {% endif %} + {% if request.user.is_authenticated and request.user != object %} + + {% endif %} +
+ + + +
Monthly Report @@ -970,6 +1070,13 @@

Bookmarks:

openRecommendations.addEventListener("click",()=>{ openRecommendations.style.display="none"; }); + + var closeRecommends = document.getElementById("close-Recommendations"); + var openRecommends = document.getElementById("recommends"); + openRecommends.addEventListener("click",()=>{ + openRecommends.style.display="none"; + }); + var closeBookmark = document.getElementById("close-Bookmark"); var openBookmark = document.getElementById("Bookmark"); closeBookmark.addEventListener("click",()=>{ @@ -989,7 +1096,10 @@

Bookmarks:

function openRecommendationModal(){ openRecommendations.style.cssText = "display:block !important;" } - + + function openRecommendsModal(){ + openRecommends.style.cssText = "display:block !important;" + } function openBookmarkModal(){ @@ -1057,25 +1167,6 @@

Bookmarks:

var chart = new ApexCharts(document.querySelector("#chart"), options); chart.render(); -