From 279869fcbb2dd8c2a542a1de8eec0c277c057be0 Mon Sep 17 00:00:00 2001 From: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:16:29 -0500 Subject: [PATCH] Add project_visit_count field to Project model and update serializers --- blt/settings.py | 28 +++++++++++++-- .../0177_project_project_visit_count.py | 17 ++++++++++ website/models.py | 34 ++++++++++++++++--- website/serializers.py | 9 +++-- 4 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 website/migrations/0177_project_project_visit_count.py diff --git a/blt/settings.py b/blt/settings.py index a720eea18..521ae1c8c 100644 --- a/blt/settings.py +++ b/blt/settings.py @@ -330,9 +330,29 @@ LOGIN_REDIRECT_URL = "/" +# LOGGING = { +# "version": 1, +# "disable_existing_loggers": False, +# "handlers": { +# "console": { +# "class": "logging.StreamHandler", +# }, +# "mail_admins": { +# "class": "django.utils.log.AdminEmailHandler", +# }, +# }, +# "loggers": { +# "": { +# "handlers": ["console"], +# "level": "DEBUG", +# }, +# }, +# } +# disable logging unless critical + LOGGING = { "version": 1, - "disable_existing_loggers": False, + "disable_existing_loggers": True, "handlers": { "console": { "class": "logging.StreamHandler", @@ -343,11 +363,13 @@ }, "loggers": { "": { - "handlers": ["console"], - "level": "DEBUG", + "handlers": [], # Disable logging by setting handlers to an empty list + "level": "CRITICAL", # Only log critical errors }, }, } + + USERS_AVATAR_PATH = "avatars" AVATAR_PATH = os.path.join(MEDIA_ROOT, USERS_AVATAR_PATH) diff --git a/website/migrations/0177_project_project_visit_count.py b/website/migrations/0177_project_project_visit_count.py new file mode 100644 index 000000000..cc1bffff1 --- /dev/null +++ b/website/migrations/0177_project_project_visit_count.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1.4 on 2025-01-01 20:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("website", "0176_repo_contributor_repo_contributor_count_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="project", + name="project_visit_count", + field=models.IntegerField(default=0), + ), + ] diff --git a/website/models.py b/website/models.py index 47fd23570..afc7f8dbb 100644 --- a/website/models.py +++ b/website/models.py @@ -77,7 +77,9 @@ class Integration(models.Model): blank=True, ) organization = models.ForeignKey( - "Organization", on_delete=models.CASCADE, related_name="organization_integrations" + "Organization", + on_delete=models.CASCADE, + related_name="organization_integrations", ) created_at = models.DateTimeField(auto_now_add=True) @@ -456,6 +458,7 @@ def delete_image_on_issue_delete(sender, instance, **kwargs): logger.error( f"Error deleting image from Google Cloud Storage: {blob_name} - {str(e)}" ) + else: @receiver(post_delete, sender=Issue) @@ -489,6 +492,7 @@ def delete_image_on_post_delete(sender, instance, **kwargs): logger.error( f"Error deleting image from Google Cloud Storage: {blob_name} - {str(e)}" ) + else: @receiver(post_delete, sender=IssueScreenshot) @@ -606,7 +610,11 @@ class UserProfile(models.Model): modified = models.DateTimeField(auto_now=True) visit_count = models.PositiveIntegerField(default=0) team = models.ForeignKey( - Organization, on_delete=models.SET_NULL, related_name="user_profiles", null=True, blank=True + Organization, + on_delete=models.SET_NULL, + related_name="user_profiles", + null=True, + blank=True, ) def check_team_membership(self): @@ -889,7 +897,11 @@ def __str__(self): class Project(models.Model): organization = models.ForeignKey( - Organization, null=True, blank=True, related_name="projects", on_delete=models.CASCADE + Organization, + null=True, + blank=True, + related_name="projects", + on_delete=models.CASCADE, ) name = models.CharField(max_length=255) slug = models.SlugField(unique=True, blank=True) @@ -897,11 +909,14 @@ class Project(models.Model): url = models.URLField( unique=True, null=True, blank=True ) # Made url nullable in case of no website + project_visit_count = models.IntegerField(default=0) twitter = models.CharField(max_length=30, null=True, blank=True) facebook = models.URLField(null=True, blank=True) logo = models.ImageField(upload_to="project_logos", null=True, blank=True) created = models.DateTimeField(auto_now_add=True) # Standardized field name modified = models.DateTimeField(auto_now=True) # Standardized field name + # add languages + # add tags def save(self, *args, **kwargs): if not self.slug: @@ -1022,7 +1037,11 @@ class TimeLog(models.Model): ) # associate organization with sizzle organization = models.ForeignKey( - Organization, on_delete=models.CASCADE, related_name="time_logs", null=True, blank=True + Organization, + on_delete=models.CASCADE, + related_name="time_logs", + null=True, + blank=True, ) start_time = models.DateTimeField() end_time = models.DateTimeField(null=True, blank=True) @@ -1175,7 +1194,11 @@ class UserBadge(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) badge = models.ForeignKey(Badge, on_delete=models.CASCADE) awarded_by = models.ForeignKey( - User, null=True, blank=True, related_name="awarded_badges", on_delete=models.SET_NULL + User, + null=True, + blank=True, + related_name="awarded_badges", + on_delete=models.SET_NULL, ) awarded_at = models.DateTimeField(auto_now_add=True) reason = models.TextField(blank=True, null=True) @@ -1245,6 +1268,7 @@ class Repo(models.Model): tags = models.ManyToManyField("Tag", blank=True) last_updated = models.DateTimeField(null=True, blank=True) total_issues = models.IntegerField(default=0) + # rename this to repo_visit_count and make sure the github badge works with this project_visit_count = models.IntegerField(default=0) watchers = models.IntegerField(default=0) open_pull_requests = models.IntegerField(default=0) diff --git a/website/serializers.py b/website/serializers.py index 74f64ca31..cea46168c 100644 --- a/website/serializers.py +++ b/website/serializers.py @@ -129,7 +129,7 @@ class ProjectSerializer(serializers.ModelSerializer): stars = serializers.IntegerField() forks = serializers.IntegerField() external_links = serializers.JSONField() - project_visit_count = serializers.IntegerField() + # project_visit_count = serializers.IntegerField() class Meta: model = Project @@ -172,4 +172,9 @@ class ActivityLogSerializer(serializers.ModelSerializer): class Meta: model = ActivityLog fields = ["id", "user", "window_title", "url", "recorded_at", "created"] - read_only_fields = ["id", "user", "recorded_at", "created"] # Auto-filled fields + read_only_fields = [ + "id", + "user", + "recorded_at", + "created", + ] # Auto-filled fields