Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ RECAPTCHA_PRIVATE_KEY='dummy_value'
# The toolbar should not be used in a remote environment
ENABLE_TOOLBAR=""
DJANGO_RUNSERVER_HIDE_WARNING="True"
# GitHub API Configuration (for Djangonaut stats - Issue #615)
# Get token from: https://github.com/settings/tokens
# Required scopes: public_repo
GITHUB_TOKEN= <Github token>
4 changes: 4 additions & 0 deletions .env.template.local
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ ENABLE_TOOLBAR=""
PLAYWRIGHT_TEST_USERNAME="playwright_test"
PLAYWRIGHT_TEST_PASSWORD="hunter2"
DJANGO_RUNSERVER_HIDE_WARNING="True"
# GitHub API Configuration (for Djangonaut stats - Issue #615)
# Get token from: https://github.com/settings/tokens
# Required scopes: public_repo
GITHUB_TOKEN=<Github token>
7 changes: 7 additions & 0 deletions accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class CustomUserAdmin(ExportCsvMixin, BaseUserAdmin):
model = CustomUser
actions = ["export_as_csv"]

fieldsets = BaseUserAdmin.fieldsets + (
("GitHub Integration", {"fields": ("github_username",)}),
)
add_fieldsets = BaseUserAdmin.add_fieldsets + (
("GitHub Integration", {"fields": ("github_username",)}),
)


@admin.register(UserProfile)
class UserProfileAdmin(ExportCsvMixin, admin.ModelAdmin):
Expand Down
23 changes: 23 additions & 0 deletions accounts/migrations/0010_customuser_github_username.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.2.7 on 2025-12-09 17:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0009_useravailability"),
]

operations = [
migrations.AddField(
model_name="customuser",
name="github_username",
field=models.CharField(
blank=True,
help_text="GitHub username (without @)",
max_length=39,
null=True,
),
),
]
7 changes: 6 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@


class CustomUser(AbstractUser):
pass
github_username = models.CharField(
Copy link
Member

Choose a reason for hiding this comment

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

Please be aware we've added this field to the UserProfile model already.

max_length=39, # GitHub max username length
blank=True,
null=True,
help_text="GitHub username (without @)",
)


class UserProfile(models.Model):
Expand Down
28 changes: 27 additions & 1 deletion home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SessionMembershipAdmin(admin.ModelAdmin):
@admin.register(Session)
class SessionAdmin(admin.ModelAdmin):
inlines = [SessionMembershipInline]
actions = ["form_teams_action"]
actions = ["form_teams_action", "collect_djangonaut_stats_action"]

def get_urls(self):
"""Add custom URLs for team formation"""
Expand All @@ -71,9 +71,20 @@ def get_urls(self):
self.admin_site.admin_view(calculate_overlap_ajax),
name="session_calculate_overlap",
),
path(
"<int:session_id>/collect-stats/",
self.admin_site.admin_view(self.collect_stats_view),
name="session_collect_stats",
),
]
return custom_urls + urls

def collect_stats_view(self, request, session_id):
"""Handle GitHub stats collection for a session."""
from .views.sessions import collect_stats_view

return collect_stats_view(request, session_id)
Comment on lines +82 to +86
Copy link
Member

Choose a reason for hiding this comment

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

I think having this as an actual link rather than an action is probably best. I just introduced this in #619


@admin.action(description="Form teams for this session")
def form_teams_action(self, request, queryset):
"""Redirect to team formation interface for selected session"""
Expand All @@ -89,6 +100,21 @@ def form_teams_action(self, request, queryset):
url = reverse("admin:session_form_teams", args=[session.id])
return redirect(url)

@admin.action(description="Collect Djangonaut GitHub stats")
def collect_djangonaut_stats_action(self, request, queryset):
"""Redirect to GitHub stats collection view for selected session"""
if queryset.count() != 1:
self.message_user(
request,
"Please select exactly one session to collect stats.",
messages.ERROR,
)
return

session = queryset.first()
url = reverse("admin:session_collect_stats", args=[session.id])
return redirect(url)


@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
Expand Down
1 change: 1 addition & 0 deletions home/management/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Management commands package."""
1 change: 1 addition & 0 deletions home/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Services package for home app."""
Loading