Skip to content

Commit

Permalink
Merge pull request #636 from UnitapApp/feature/admin/autocomplete-user
Browse files Browse the repository at this point in the history
added autocomplete fields for admin panel
  • Loading branch information
ShayanShiravani authored Oct 26, 2024
2 parents 1bc12f3 + 3d9862e commit 215e620
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProfileAdmin(admin.ModelAdmin):

class WalletAdmin(admin.ModelAdmin):
list_display = ["pk", "wallet_type", "user_profile"]
autocomplete_fields = ["user_profile"]
search_fields = [
"user_profile__initial_context_id",
"wallet_type",
Expand All @@ -34,6 +35,7 @@ class WalletAdmin(admin.ModelAdmin):

class BrightIDConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "context_id", "age"]
autocomplete_fields = ["user_profile"]
search_fields = [
"context_id",
]
Expand All @@ -42,21 +44,25 @@ class BrightIDConnectionAdmin(admin.ModelAdmin):
class GitcoinPassportConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_wallet_address", "user_profile__username"]
autocomplete_fields = ["user_profile"]


class TwitterConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "oauth_token"]
search_fields = ["user_profile__username", "oauth_token"]
autocomplete_fields = ["user_profile"]


class EnsConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_profile__username", "user_wallet_address"]
autocomplete_fields = ["user_profile"]


class FarcasterConnectionAdmin(admin.ModelAdmin):
list_display = ["pk", "user_profile", "user_wallet_address"]
search_fields = ["user_profile__username", "user_wallet_address"]
autocomplete_fields = ["user_profile"]


admin.site.register(Wallet, WalletAdmin)
Expand Down
5 changes: 4 additions & 1 deletion authentication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,13 @@ def test_api_verify_login_signature_with_deleted_wallet(self):

class TestGitcoinPassportThirdPartyConnection(APITestCase):
def setUp(self) -> None:
self.address = "0x0cE49AF5d8c5A70Edacd7115084B2b3041fE4fF6"
self.address = "0x05204E317D25eb172115546297b056965bE2C74d"
self.user_profile = create_new_user()
create_new_wallet(
user_profile=self.user_profile, _address=self.address, wallet_type="EVM"
)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_gitcoin_passport_connection_successful(self):
self.client.force_authenticate(user=self.user_profile.user)
response = self.client.post(
Expand All @@ -697,6 +698,7 @@ def test_gitcoin_passport_connection_successful(self):
1,
)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_gitcoin_passport_not_exists(self):
address_does_not_have_gitcoin_passport = (
"0x0cE49AF5d8c5A70Edacd7115084B2b3041fE4fF5"
Expand All @@ -713,6 +715,7 @@ def test_gitcoin_passport_not_exists(self):
)
self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST)

@patch("authentication.models.submit_passport", lambda a, b: True)
def test_address_not_owned_by_user(self):
self.client.force_authenticate(user=self.user_profile.user)
response = self.client.post(
Expand Down
2 changes: 1 addition & 1 deletion core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_EAS_attest_constraints(self):
class TestGitcoinPassportConstraint(BaseTestCase):
def setUp(self):
super().setUp()
self.address = "0x0cE49AF5d8c5A70Edacd7115084B2b3041fE4fF6"
self.address = "0x05204E317D25eb172115546297b056965bE2C74d"
self.user_profile = self.user_profile
create_new_wallet(
user_profile=self.user_profile, _address=self.address, wallet_type="EVM"
Expand Down
5 changes: 3 additions & 2 deletions prizetap/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
class RaffleAdmin(admin.ModelAdmin):
list_display = ["pk", "name", "creator_name", "status"]
readonly_fields = ["vrf_tx_hash"]
autocomplete_fields = ["creator_profile"]


class RaffleٍEntryAdmin(admin.ModelAdmin):
class RaffleEntryAdmin(admin.ModelAdmin):
list_display = [
"pk",
"raffle",
Expand All @@ -24,6 +25,6 @@ class LineaRaffleEntriesAdmin(admin.ModelAdmin):


admin.site.register(Raffle, RaffleAdmin)
admin.site.register(RaffleEntry, RaffleٍEntryAdmin)
admin.site.register(RaffleEntry, RaffleEntryAdmin)
admin.site.register(Constraint, UserConstraintBaseAdmin)
admin.site.register(LineaRaffleEntries, LineaRaffleEntriesAdmin)
1 change: 1 addition & 0 deletions tokenTap/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TokenDistributionClaimAdmin(admin.ModelAdmin):
]
search_fields = ["user_wallet_address"]
list_filter = ["token_distribution", "status"]
autocomplete_fields = ["user_profile"]


class GlobalSettingsAdmin(admin.ModelAdmin):
Expand Down
2 changes: 1 addition & 1 deletion tokenTap/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(

def check_user_permissions(self, raise_exception=True):
try:
param_values = json.loads(self.td.constraint_params)
param_values = json.loads(self.td.constraint_params or "{}")
except Exception as e:
logging.error("Error parsing constraint params", e)
param_values = {}
Expand Down

0 comments on commit 215e620

Please sign in to comment.