Skip to content

Commit

Permalink
Add callsign autocomplete view, allow adding members to a club
Browse files Browse the repository at this point in the history
  • Loading branch information
elnappo committed May 2, 2019
1 parent 028552e commit a1715e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 5 additions & 1 deletion project_novis/callsign/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dal import autocomplete
from django.contrib.gis import forms

from .models import Callsign, Repeater, Club
Expand Down Expand Up @@ -25,4 +26,7 @@ class ClubForm(forms.ModelForm):

class Meta:
model = Club
fields = ["website", "description"]
fields = ["website", "description", "members"]
widgets = {
'members': autocomplete.ModelSelect2Multiple(url='callsign:callsign-autocomplete')
}
4 changes: 3 additions & 1 deletion project_novis/callsign/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.urls import path

from .views import CallsignDetailView, CallsignCreate, CallsignUpdate, CallsignClaimView, RepeaterUpdate, ClubUpdate
from .views import CallsignDetailView, CallsignCreate, CallsignUpdate, CallsignClaimView, RepeaterUpdate, ClubUpdate,\
CallsignAutocomplete

app_name = "callsign"

urlpatterns = [
path('add/', CallsignCreate.as_view(), name='callsign-html-create'),
path('autocomplete/', CallsignAutocomplete.as_view(), name='callsign-autocomplete'),

path('<slug>/', CallsignDetailView.as_view(), name='callsign-html-detail'),
path('<slug>/change', CallsignUpdate.as_view(), name='callsign-html-update'),
Expand Down
19 changes: 17 additions & 2 deletions project_novis/callsign/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from csp.decorators import csp_update
from dal import autocomplete
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseForbidden
from django.http import HttpResponseForbidden, Http404
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.detail import SingleObjectMixin
Expand All @@ -14,14 +17,26 @@
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly
from rest_framework_gis.filters import DistanceToPointFilter
from django.urls import reverse

from .forms import CallsignForm, RepeaterForm, ClubForm
from .models import Country, DXCCEntry, Callsign, DMRID, CallsignPrefix, Repeater, Club
from .serializers import CountrySerializer, DXCCEntrySerializer, CallsignSerializer, \
DMRIDSerializer, CallsignPrefixSerializer, RepeaterSerializer, APRSPasscodeSerializer


class CallsignAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_authenticated:
return Callsign.objects.none()

qs = Callsign.objects.all()

if self.q:
qs = qs.filter(name__istartswith=self.q)

return qs


class DefaultPagination(LimitOffsetPagination):
default_limit = 50
max_limit = 100
Expand Down

0 comments on commit a1715e9

Please sign in to comment.