Skip to content

Commit

Permalink
remove django-ajax-selects (#715)
Browse files Browse the repository at this point in the history
[#188227079]
  • Loading branch information
uraniumanchor authored Sep 9, 2024
1 parent 6d50307 commit 85c2f10
Show file tree
Hide file tree
Showing 29 changed files with 340 additions and 596 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ Add the `daphne` app **to the top of** the `INSTALLED_APPS` section of `tracker_
'tracker',
'rest_framework',
'timezone_field',
'ajax_select',
'mptt',
```

Expand All @@ -154,8 +153,6 @@ NOTE: The analytics middleware is only a client, and does not track any informat
Add the following chunk somewhere in `settings.py`:

```python
from tracker import ajax_lookup_channels
AJAX_LOOKUP_CHANNELS = ajax_lookup_channels.AJAX_LOOKUP_CHANNELS
ASGI_APPLICATION = 'tracker_development.routing.application'
CHANNEL_LAYERS = {'default': {'BACKEND': 'channels.layers.InMemoryChannelLayer'}}

Expand Down Expand Up @@ -196,10 +193,8 @@ from django.contrib import admin
from django.urls import path, include

import tracker.urls
import ajax_select.urls

urlpatterns = [
path('admin/lookups/', include(ajax_select.urls)),
path('admin/', admin.site.urls),
path('tracker/', include(tracker.urls, namespace='tracker')),
]
Expand Down
15 changes: 15 additions & 0 deletions bundles/public/spinner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.tracker--spinner {
animation-name: spin;
animation-duration: 2s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
}
10 changes: 8 additions & 2 deletions bundles/public/spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';

import { useConstants } from '@common/Constants';

import './spinner.css';

function Spinner({
children,
imageFile = 'ajax_select/images/loading-indicator.gif',
imageFile = 'admin/img/search.svg',
spinning = true,
}: {
children?: React.ReactNode;
Expand All @@ -13,7 +15,11 @@ function Spinner({
}) {
const { STATIC_URL } = useConstants();

return spinning ? <img data-test-id="spinner" src={STATIC_URL + imageFile} alt="loading" /> : <>{children}</>;
return spinning ? (
<img className="tracker--spinner" data-test-id="spinner" src={STATIC_URL + imageFile} alt="loading" />
) : (
<>{children}</>
);
}

export default Spinner;
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def get_package_name(name):
'celery~=5.0',
'channels>=4.0',
'Django>=4.2,<5.2',
'django-ajax-selects~=2.1', # publish error, see: https://github.com/crucialfelix/django-ajax-selects/issues/306
'django-ical~=1.7',
'django-mptt~=0.10',
'django-paypal~=1.1',
Expand Down
1 change: 0 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
celery==5.4.0
channels==4.1.0
# django explicitly not listed here because azure installs a particular series immediately after
django-ajax-selects==2.1.0 # publish error, see: https://github.com/crucialfelix/django-ajax-selects/issues/306
django-ical==1.9.2
django-paypal==1.1.2
django-mptt==0.14.0 ; python_version<"3.9"
Expand Down
25 changes: 25 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def setUp(self):
'super@example.com',
'password',
)
self.search_user = User.objects.create(username='search', is_staff=True)
self.search_user.user_permissions.add(
Permission.objects.get(codename='can_search_for_user')
)
self.other_user = User.objects.create(username='other', is_staff=True)
self.event = randgen.build_random_event(self.rand)
self.session = self.client.session
self.session.save()
Expand Down Expand Up @@ -197,3 +202,23 @@ def test_automail_prize_shipping_notifications(self):
)
)
self.assertEqual(response.status_code, 200)

def test_user_autocomplete(self):
# needs to look real or the view will reject it
data = {
'app_label': 'tracker',
'model_name': 'event',
'field_name': 'prizecoordinator',
}

self.client.force_login(self.search_user)
response = self.client.get(
reverse('admin:tracker_user_autocomplete'), data=data
)
self.assertEqual(response.status_code, 200)

self.client.force_login(self.other_user)
response = self.client.get(
reverse('admin:tracker_user_autocomplete'), data=data
)
self.assertEqual(response.status_code, 403)
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ def test_donor_visibilities(self):
msg=f'Visibility {visibility} gave an incorrect result',
)

@skip('disabled for now')
def test_search_by_donor(self):
donation = randgen.generate_donation(
self.rand, donor=self.donor, event=self.event
Expand Down
26 changes: 12 additions & 14 deletions tests/test_donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.auth.models import Permission, User
from django.test import RequestFactory, TestCase, override_settings
from django.urls import reverse
from django.utils.translation import gettext as _

from tracker import admin, models

Expand Down Expand Up @@ -291,29 +292,26 @@ def test_donation_admin(self):
)
self.assertFalse(response.context['has_change_permission'])
self.assertFalse(response.context['has_delete_permission'])
response = self.client.post(
reverse('admin:tracker_donation_change', args=(self.donation.id,))
)
self.assertEqual(response.status_code, 403)
with self.subTest('should not be able to add a donation to a locked event'):
response = self.client.post(
reverse('admin:tracker_donation_add'),
data=(
{
'donor': self.donor.id,
'event': self.event.id,
'amount': 5,
'timereceived_0': self.donation.timereceived.strftime(
'%Y-%m-%d'
),
'timereceived_1': self.donation.timereceived.strftime(
'%H:%M:%S'
),
'readstate': self.donation.readstate,
'commentstate': self.donation.commentstate,
'currency': 'USD',
'requestedvisibility': 'CURR',
'requestedsolicitemail': 'CURR',
}
),
)
self.assertEqual(response.status_code, 403)
self.assertFormError(
response.context['adminform'],
'event',
_(
'Select a valid choice. That choice is not one of the available choices.'
),
)

def test_donation_admin_form(self):
# testing both get_form and get_readonly_fields, as they will not be in
Expand Down
4 changes: 0 additions & 4 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

from tracker import ajax_lookup_channels

DOMAIN = 'testserver'
SECRET_KEY = 'ForTestingPurposesOnly'
INSTALLED_APPS = [
Expand All @@ -17,7 +15,6 @@
'paypal.standard.ipn',
'tracker',
'timezone_field',
'ajax_select',
'mptt',
]
DATABASES = {
Expand Down Expand Up @@ -63,7 +60,6 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware',
)
AJAX_LOOKUP_CHANNELS = ajax_lookup_channels.AJAX_LOOKUP_CHANNELS
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
Expand Down
2 changes: 0 additions & 2 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ajax_select.urls
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.http import HttpResponse
Expand All @@ -13,7 +12,6 @@ def empty(request):

urlpatterns = [
path('tracker/', include(tracker.urls)),
path('admin/lookups/', include(ajax_select.urls)),
path('admin/', admin.site.urls),
path('favicon.ico', empty),
]
Expand Down
1 change: 0 additions & 1 deletion tracker/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from . import bid, country, donation, event, interstitial, log, prize # noqa: F401

# plain admin
admin.site.register(models.Country)
admin.site.register(models.WordFilter)
admin.site.register(models.AmountFilter)
admin.site.register(models.Submission)
Expand Down
19 changes: 14 additions & 5 deletions tracker/admin/bid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
from tracker import forms, logutil, models, search_filters, viewutil

from .filters import BidListFilter, BidParentFilter
from .forms import BidForm, DonationBidForm
from .inlines import BidChainedInline, BidDependentsInline, BidOptionInline
from .util import CustomModelAdmin, DonationStatusMixin, EventLockedMixin


@register(models.Bid)
class BidAdmin(EventLockedMixin, CustomModelAdmin):
form = BidForm
autocomplete_fields = (
'speedrun',
'event',
'biddependency',
)
list_display = (
'__str__',
'speedrun',
Expand Down Expand Up @@ -54,6 +57,12 @@ class BidAdmin(EventLockedMixin, CustomModelAdmin):
'total',
)

def get_search_results(self, request, queryset, search_term):
parent_view = self.get_parent_view(request)
if parent_view and parent_view[0] in ('donationbid', 'donation'):
queryset = queryset.filter(istarget=True)
return super().get_search_results(request, queryset, search_term)

@display(description='Effective Parent')
def effective_parent(self, obj):
targetObject = None
Expand Down Expand Up @@ -272,7 +281,7 @@ def get_actions(self, request):

@register(models.DonationBid)
class DonationBidAdmin(EventLockedMixin, DonationStatusMixin, CustomModelAdmin):
form = DonationBidForm
autocomplete_fields = ('bid',)
list_display = (
'bid',
'event',
Expand All @@ -289,7 +298,7 @@ class DonationBidAdmin(EventLockedMixin, DonationStatusMixin, CustomModelAdmin):
'bid',
'donation',
)
readonly_fields = ('donation',)
readonly_fields = ('donation',) # only allow adding via the donation's bid inline

def get_queryset(self, request):
queryset = (
Expand All @@ -305,6 +314,6 @@ def transactionstate(self, obj):
def testdonation(self, obj):
return obj.donation.testdonation

# add directly to donations
# only allow adding via the donation's bid inline
def has_add_permission(self, request):
return False
8 changes: 6 additions & 2 deletions tracker/admin/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

from tracker import models

from .forms import CountryRegionForm
from .util import CustomModelAdmin


@register(models.Country)
class CountryAdmin(CustomModelAdmin):
search_fields = ('name',)


@register(models.CountryRegion)
class CountryRegionAdmin(CustomModelAdmin):
form = CountryRegionForm
autocomplete_fields = ('country',)
list_display = (
'name',
'country',
Expand Down
Loading

0 comments on commit 85c2f10

Please sign in to comment.