Skip to content

Commit bf30cef

Browse files
committed
2 parents 566f1d4 + ea24b7a commit bf30cef

2,436 files changed

Lines changed: 147288 additions & 650 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/settings.py

Lines changed: 472 additions & 3 deletions
Large diffs are not rendered by default.

core/urls.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
path('', include('home.urls')),
9999
path("api/tip/today/", views.tip_today, name="tip_today"),
100100

101-
]
101+
]
102+
103+
104+
105+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
102106

103-
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

h origin main --dry-run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1728e368 (HEAD -> main) Add Python Compiler and Enhanced Quiz Integration
2+
b1d2f663 Update xss_attempts.log
3+
f67b95b4 cyber challenges page update by krishna chaudhari
4+
d9f42dfd Merge pull request #345 from M0Nabel13/main
5+
530b046e Updated codeql.yml

home/admin.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
from django.contrib import admin
24
from .models import TeamMember
35
from .models import AdminNotification
@@ -40,10 +42,19 @@
4042
AppAttackReport,
4143
PenTestingRequest,
4244
SecureCodeReviewRequest,
45+
46+
47+
# Python Compiler Models
48+
CodeExecution,
49+
CodeTemplate,
50+
CodeSubmission,
51+
CompilerSettings,
52+
4353
JobAlert,
4454
GraduateProgram,
4555
CareerFAQ
4656

57+
4758
)
4859

4960

@@ -262,6 +273,72 @@ class SecureCodeReviewRequestAdmin(admin.ModelAdmin):
262273
readonly_fields = ['submitted_at']
263274

264275

276+
277+
# Python Compiler Admin Classes
278+
@admin.register(CodeExecution)
279+
class CodeExecutionAdmin(admin.ModelAdmin):
280+
list_display = ['user', 'language', 'is_successful', 'execution_time', 'created_at', 'ip_address']
281+
list_filter = ['language', 'is_successful', 'created_at', 'ip_address']
282+
search_fields = ['user__email', 'code', 'output', 'error_message']
283+
readonly_fields = ['created_at', 'execution_time', 'memory_used']
284+
ordering = ['-created_at']
285+
286+
def get_readonly_fields(self, request, obj=None):
287+
if obj: # If editing existing object
288+
return ['user', 'language', 'code', 'input_data', 'output', 'error_message',
289+
'execution_time', 'memory_used', 'is_successful', 'created_at', 'ip_address']
290+
return self.readonly_fields
291+
292+
293+
@admin.register(CodeTemplate)
294+
class CodeTemplateAdmin(admin.ModelAdmin):
295+
list_display = ['title', 'category', 'difficulty', 'is_active', 'created_at']
296+
list_filter = ['category', 'difficulty', 'is_active', 'created_at']
297+
search_fields = ['title', 'description', 'template_code']
298+
readonly_fields = ['created_at', 'updated_at']
299+
300+
fieldsets = (
301+
('Basic Information', {
302+
'fields': ('title', 'description', 'category', 'difficulty', 'is_active')
303+
}),
304+
('Code Content', {
305+
'fields': ('template_code', 'expected_output', 'hints')
306+
}),
307+
('Timestamps', {
308+
'fields': ('created_at', 'updated_at'),
309+
'classes': ('collapse',)
310+
}),
311+
)
312+
313+
314+
@admin.register(CodeSubmission)
315+
class CodeSubmissionAdmin(admin.ModelAdmin):
316+
list_display = ['user', 'template', 'is_correct', 'execution_time', 'submitted_at']
317+
list_filter = ['is_correct', 'submitted_at', 'template__category', 'template__difficulty']
318+
search_fields = ['user__email', 'template__title', 'user_code']
319+
readonly_fields = ['submitted_at', 'execution_time']
320+
ordering = ['-submitted_at']
321+
322+
def get_readonly_fields(self, request, obj=None):
323+
if obj: # If editing existing object
324+
return ['user', 'template', 'user_code', 'is_correct', 'execution_time', 'submitted_at']
325+
return self.readonly_fields
326+
327+
328+
@admin.register(CompilerSettings)
329+
class CompilerSettingsAdmin(admin.ModelAdmin):
330+
list_display = ['max_execution_time', 'max_memory_limit', 'max_code_length', 'is_active', 'updated_at']
331+
list_filter = ['is_active', 'created_at', 'updated_at']
332+
readonly_fields = ['created_at', 'updated_at']
333+
334+
def has_add_permission(self, request):
335+
# Only allow one settings instance
336+
return not CompilerSettings.objects.exists()
337+
338+
def has_delete_permission(self, request, obj=None):
339+
# Prevent deletion of settings
340+
return False
341+
265342
@admin.register(Tip)
266343
class TipAdmin(admin.ModelAdmin):
267344
list_display = ("text", "is_active", "created_at")

home/apps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ def ready(self):
1515
insert_default_projects()
1616
insert_default_courses()
1717
except Exception as e:
18-
print(f"[ERROR] insert_defaults failed: {e}")
18+
print(f"[ERROR] insert_defaults failed: {e}")
19+
# Continue running even if inserts fail

home/context_processors.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
from django.utils.text import capfirst
4040
from django.utils.translation import gettext as _
4141
from django.conf import settings
42+
43+
from .models import UserScore
4244
import re
4345

4446
def _prettify_from_path(path: str) -> str:
@@ -47,6 +49,7 @@ def _prettify_from_path(path: str) -> str:
4749
slug = re.sub(r"\s+", " ", slug).strip()
4850
return capfirst(slug) if slug else "Home"
4951

52+
5053
def dynamic_page_title(request):
5154

5255
# Standardized path: Ensure that it ends with a slash to facilitate dictionary matching.
@@ -85,4 +88,21 @@ def dynamic_page_title(request):
8588
return {"dynamic_title": full_title}
8689

8790
def recaptcha_site_key(request):
91+
92+
return {
93+
'RECAPTCHA_SITE_KEY': settings.RECAPTCHA_SITE_KEY
94+
}
95+
96+
def user_scores(request):
97+
"""Add user scores to context for navigation display"""
98+
if request.user.is_authenticated:
99+
user_scores = UserScore.objects.filter(user=request.user).order_by('-score')
100+
total_score = sum(score.score for score in user_scores)
101+
return {
102+
'user_scores': user_scores,
103+
'user_total_score': total_score
104+
}
105+
return {}
106+
88107
return {'RECAPTCHA_SITE_KEY': settings.RECAPTCHA_SITE_KEY}
108+

0 commit comments

Comments
 (0)