Skip to content

Commit

Permalink
Add project_visit_count field to Project model and update serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT committed Jan 1, 2025
1 parent 3ed77c0 commit 279869f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
28 changes: 25 additions & 3 deletions blt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)

Expand Down
17 changes: 17 additions & 0 deletions website/migrations/0177_project_project_visit_count.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
34 changes: 29 additions & 5 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -889,19 +897,26 @@ 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)
description = models.TextField()
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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions website/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 279869f

Please sign in to comment.