Skip to content
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

feat(api): updates django admin views to use ScorerModelAdmin class w… #375

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
15 changes: 7 additions & 8 deletions api/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
from django.urls import reverse
from django.utils.safestring import mark_safe
from rest_framework_api_key.admin import APIKeyAdmin
from scorer.scorer_admin import ScorerModelAdmin
from scorer_weighted.models import Scorer

from .models import Account, AccountAPIKey, Community, RateLimits


class AccountAdmin(admin.ModelAdmin):
@admin.register(Account)
class AccountAdmin(ScorerModelAdmin):
list_display = ("id", "address", "user")
search_fields = ("address", "user__username")
raw_id_fields = ("user",)


class CommunityAdmin(admin.ModelAdmin):
@admin.register(Community)
class CommunityAdmin(ScorerModelAdmin):
list_display = (
"id",
"name",
Expand Down Expand Up @@ -55,6 +58,7 @@ def scorer_link(self, obj):
scorer_link.short_description = "Scorer Link"


@admin.register(AccountAPIKey)
class AccountAPIKeyAdmin(APIKeyAdmin):
raw_id_fields = ("account",)
search_fields = (
Expand Down Expand Up @@ -97,10 +101,5 @@ def edit_selected(modeladmin, request, queryset):
actions = [edit_selected]


class APIKeyPermissionsAdmin(admin.ModelAdmin):
class APIKeyPermissionsAdmin(ScorerModelAdmin):
list_display = ("id", "submit_passports", "read_scores", "create_scorers")


admin.site.register(Account, AccountAdmin)
admin.site.register(Community, CommunityAdmin)
admin.site.register(AccountAPIKey, AccountAPIKeyAdmin)
9 changes: 4 additions & 5 deletions api/ceramic_cache/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
Admin for the ceramic cache app
"""
from django.contrib import admin
from scorer.scorer_admin import ScorerModelAdmin

from .models import CeramicCache


class CeramicCacheAdmin(admin.ModelAdmin):
@admin.register(CeramicCache)
class CeramicCacheAdmin(ScorerModelAdmin):
list_display = ("id", "address", "provider", "stamp")
search_fields = ("address",)
search_help_text = "This will perform a search by 'address'"
show_full_result_count = False


class AccountAPIKeyAdmin(admin.ModelAdmin):
class AccountAPIKeyAdmin(ScorerModelAdmin):
list_display = ("id", "name", "prefix", "created", "expiry_date", "revoked")
search_fields = ("id", "name", "prefix")


admin.site.register(CeramicCache, CeramicCacheAdmin)
23 changes: 11 additions & 12 deletions api/registry/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.contrib import admin
from registry.models import Event, HashScorerLink, Passport, Score, Stamp
from scorer.scorer_admin import ScorerModelAdmin


class PassportAdmin(admin.ModelAdmin):
@admin.register(Passport)
class PassportAdmin(ScorerModelAdmin):
list_display = ["address", "community"]
search_fields = ["address"]

Expand All @@ -12,7 +14,8 @@ def get_queryset(self, request):
return queryset


class StampAdmin(admin.ModelAdmin):
@admin.register(Stamp)
class StampAdmin(ScorerModelAdmin):
list_display = ["passport", "community", "provider", "hash"]
search_fields = ["hash__exact"]
search_help_text = "This will perform an exact case sensitive search by 'hash'"
Expand All @@ -28,7 +31,8 @@ def get_queryset(self, request):
return queryset


class ScoreAdmin(admin.ModelAdmin):
@admin.register(Score)
class ScoreAdmin(ScorerModelAdmin):
list_display = [
"passport",
"community",
Expand All @@ -49,7 +53,8 @@ def get_queryset(self, request):
return queryset


class EventAdmin(admin.ModelAdmin):
@admin.register(Event)
class EventAdmin(ScorerModelAdmin):
list_display = [
"action",
"created_at",
Expand All @@ -68,18 +73,12 @@ class EventAdmin(admin.ModelAdmin):
]


class HashScorerLinkAdmin(admin.ModelAdmin):
@admin.register(HashScorerLink)
class HashScorerLinkAdmin(ScorerModelAdmin):
list_display = ["hash", "community", "address", "expires_at"]

search_fields = [
"hash",
"community",
"address",
]


admin.site.register(Passport, PassportAdmin)
admin.site.register(Stamp, StampAdmin)
admin.site.register(Score, ScoreAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(HashScorerLink, HashScorerLinkAdmin)
15 changes: 8 additions & 7 deletions api/scorer_apu/admin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
from django.contrib import admin
from scorer.scorer_admin import ScorerModelAdmin
from scorer_apu.models import ApuScorer, Combo, NumInfo

# Register your models here.


class ApuScorerAdmin(admin.ModelAdmin):
list_display = ["start_time", "end_time", "accepted_providers"]


class ScoreAdmin(admin.ModelAdmin):
class ScoreAdmin(ScorerModelAdmin):
list_display = ["passport", "scorer"]
search_fields = ["passport__did"]


class ComboAdmin(admin.ModelAdmin):
class ApuScorerAdmin(ScorerModelAdmin):
list_display = ["start_time", "end_time", "accepted_providers"]


class ComboAdmin(ScorerModelAdmin):
list_display = ["scorer", "passport", "combo", "count"]
search_fields = ["passport__did"]


class NumInfoAdmin(admin.ModelAdmin):
class NumInfoAdmin(ScorerModelAdmin):
list_display = ["scorer", "stamp_count", "count"]


Expand Down
9 changes: 5 additions & 4 deletions api/scorer_weighted/admin.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from django.contrib import admin
from scorer_weighted.models import WeightedScorer, BinaryWeightedScorer, Scorer
from scorer.scorer_admin import ScorerModelAdmin
from scorer_weighted.models import BinaryWeightedScorer, Scorer, WeightedScorer

# Register your models here.


# @admin.register(Scorer)
class ScorerAdmin(admin.ModelAdmin):
class ScorerAdmin(ScorerModelAdmin):
list_display = [
"type",
"id",
]


@admin.register(WeightedScorer)
class WeightedScorerAdmin(admin.ModelAdmin):
class WeightedScorerAdmin(ScorerModelAdmin):
list_display = ["id", "type"]


@admin.register(BinaryWeightedScorer)
class BinaryWeightedScorerAdmin(admin.ModelAdmin):
class BinaryWeightedScorerAdmin(ScorerModelAdmin):
list_display = ["id", "threshold", "type"]