Repository navigation
Add initial implementations for result types and user events #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a072305
Add initial implementations for result types, runners, splits, stages…
udernaeb 0cce1aa
Refactor models and admin configurations to replace 'klass' with 'ent…
udernaeb 588fc8c
Fix usersevents admin search_fields to use user__email instead of use…
Copilot 5bd3dac
Regenerate Pipfile.lock to include bcrypt dependency
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from django.contrib import admin | ||
| from django.utils import timezone | ||
|
|
||
|
|
||
| class TimestampedModelAdmin(admin.ModelAdmin): | ||
| timestamp_fields = ("created", "modified", "deleted") | ||
|
|
||
| def get_readonly_fields(self, request, obj=None): | ||
| readonly_fields = list(super().get_readonly_fields(request, obj)) | ||
| for field_name in self.timestamp_fields: | ||
| if ( | ||
| field_name in {field.name for field in self.model._meta.fields} | ||
| and field_name not in readonly_fields | ||
| ): | ||
| readonly_fields.append(field_name) | ||
| return readonly_fields | ||
|
|
||
| def save_model(self, request, obj, form, change): | ||
| now = timezone.now() | ||
| field_names = {field.name for field in self.model._meta.fields} | ||
|
|
||
| if ( | ||
| "created" in field_names | ||
| and not change | ||
| and getattr(obj, "created", None) is None | ||
| ): | ||
| obj.created = now | ||
| if "modified" in field_names: | ||
| obj.modified = now | ||
| if "deleted" in field_names and getattr(obj, "deleted", None) is None: | ||
| obj.deleted = None | ||
|
|
||
| super().save_model(request, obj, form, change) | ||
|
|
||
| def delete_model(self, request, obj): | ||
| field_names = {field.name for field in self.model._meta.fields} | ||
| if "deleted" in field_names: | ||
| now = timezone.now() | ||
| obj.deleted = now | ||
| if "modified" in field_names: | ||
| obj.modified = now | ||
| obj.save( | ||
| update_fields=[ | ||
| field for field in ("deleted", "modified") if field in field_names | ||
| ] | ||
| ) | ||
| return | ||
|
|
||
| super().delete_model(request, obj) | ||
|
|
||
| def delete_queryset(self, request, queryset): | ||
| field_names = {field.name for field in self.model._meta.fields} | ||
| if "deleted" in field_names: | ||
| now = timezone.now() | ||
| update_fields = {"deleted": now} | ||
| if "modified" in field_names: | ||
| update_fields["modified"] = now | ||
| queryset.update(**update_fields) | ||
| return | ||
|
|
||
| super().delete_queryset(request, queryset) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from apps.admin_base import TimestampedModelAdmin | ||
| from django.contrib import admin | ||
|
|
||
| from .models import Classes, ClassesControls | ||
|
|
||
|
|
||
| @admin.register(Classes) | ||
| class ClassesAdmin(TimestampedModelAdmin): | ||
| list_display = [ | ||
| "id", | ||
| "event", | ||
| "stage", | ||
| "short_name", | ||
| "long_name", | ||
| "oe_key", | ||
| "course", | ||
| "created", | ||
| ] | ||
| search_fields = ["short_name", "long_name", "oe_key"] | ||
| list_filter = ["event", "stage"] | ||
| list_select_related = ["event", "stage", "course"] | ||
| list_per_page = 50 | ||
| show_full_result_count = False | ||
| ordering = ["-created"] | ||
|
|
||
|
|
||
| @admin.register(ClassesControls) | ||
| class ClassesControlsAdmin(TimestampedModelAdmin): | ||
| list_display = [ | ||
| "event", | ||
| "stage", | ||
| "control_class", | ||
| "control", | ||
| "order_number", | ||
| "created", | ||
| ] | ||
| search_fields = ["order_number"] | ||
| list_filter = ["event", "stage", "order_number"] | ||
|
Comment on lines
+35
to
+38
|
||
| list_select_related = ["event", "stage", "control_class", "control"] | ||
| list_per_page = 50 | ||
| show_full_result_count = False | ||
| ordering = ["-created"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class ClassesConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "apps.classes" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| from apps.shared_models import BaseUnmanagedModel | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Classes(BaseUnmanagedModel): | ||
| event = models.ForeignKey( | ||
| "events.Events", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="event_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_rows", | ||
| ) | ||
| stage = models.ForeignKey( | ||
| "stages.Stages", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="stage_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_rows", | ||
| ) | ||
| oe_key = models.CharField(max_length=50, null=True, blank=True) | ||
| short_name = models.CharField(max_length=100, null=True, blank=True) | ||
| long_name = models.CharField(max_length=255, null=True, blank=True) | ||
| course = models.ForeignKey( | ||
| "courses.Courses", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="course_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_rows", | ||
| ) | ||
| upload_hash = models.CharField(max_length=255, null=True, blank=True) | ||
|
|
||
| class Meta(BaseUnmanagedModel.Meta): | ||
| db_table = "classes" | ||
|
|
||
| def __str__(self): | ||
| return self.short_name or self.long_name or f"Class {self.id}" | ||
|
|
||
|
|
||
| class ClassesControls(BaseUnmanagedModel): | ||
| id = None | ||
| event = models.ForeignKey( | ||
| "events.Events", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="event_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_controls_rows", | ||
| ) | ||
| stage = models.ForeignKey( | ||
| "stages.Stages", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="stage_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_controls_rows", | ||
| ) | ||
| control_class = models.ForeignKey( | ||
| "Classes", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="class_id", | ||
| primary_key=True, | ||
| related_name="classes_controls_rows", | ||
| ) | ||
| control = models.ForeignKey( | ||
| "controls.Controls", | ||
| on_delete=models.DO_NOTHING, | ||
| db_column="control_id", | ||
| null=True, | ||
| blank=True, | ||
| related_name="classes_controls_rows", | ||
| ) | ||
| order_number = models.IntegerField(null=True, blank=True) | ||
|
|
||
| class Meta(BaseUnmanagedModel.Meta): | ||
| db_table = "classes_controls" | ||
|
|
||
| def __str__(self): | ||
| return f"ClassControl {self.control_class_id}:{self.control_id}:{self.order_number}" |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from django.urls import path | ||
|
|
||
| app_name = "classes" | ||
|
|
||
| urlpatterns = [] |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from apps.admin_base import TimestampedModelAdmin | ||
| from django.contrib import admin | ||
|
|
||
| from .models import Clubs | ||
|
|
||
|
|
||
| @admin.register(Clubs) | ||
| class ClubsAdmin(TimestampedModelAdmin): | ||
| list_display = [ | ||
| "id", | ||
| "short_name", | ||
| "long_name", | ||
| "oe_key", | ||
| "event", | ||
| "stage", | ||
| "created", | ||
| ] | ||
| search_fields = ["short_name", "long_name", "oe_key"] | ||
| list_filter = ["event", "stage"] | ||
| list_select_related = ["event", "stage"] | ||
| list_per_page = 50 | ||
| show_full_result_count = False | ||
| ordering = ["-created"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 5bd3dac. Regenerated
Pipfile.lock—bcryptis now included in thedefaultsection with pinned hashes for consistent installs.