Compare commits
6 Commits
c43c5c1e10
...
7158cef122
Author | SHA1 | Date |
---|---|---|
Sebastian Lohff | 7158cef122 | |
Sebastian Lohff | 4361c4f44a | |
Sebastian Lohff | ac29ea67c7 | |
Sebastian Lohff | 3fa752a354 | |
Sebastian Lohff | 75dd3ee413 | |
Sebastian Lohff | 2eb43f7118 |
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ApiConfig(AppConfig):
|
||||||
|
name = 'api'
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
|
@ -0,0 +1,63 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from contest.models import Contest, Band, Frequency, QSO, EntryCategory, User, ShadowCall, Reference
|
||||||
|
|
||||||
|
|
||||||
|
class ContestSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Contest
|
||||||
|
# FIXME: add callQrg
|
||||||
|
fields = ('id', 'shortName', 'deadline', 'qsoStartTime', 'qsoEndTime', 'callQrg')
|
||||||
|
|
||||||
|
|
||||||
|
class BandSerializer(serializers.ModelSerializer):
|
||||||
|
# contest = ContestSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Band
|
||||||
|
fields = ('id', 'name', 'contest')
|
||||||
|
|
||||||
|
|
||||||
|
class FrequencySerializer(serializers.ModelSerializer):
|
||||||
|
# band = BandSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Frequency
|
||||||
|
fields = ('id', 'channel', 'qrg', 'band', 'note')
|
||||||
|
|
||||||
|
|
||||||
|
class EntryCategorySerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = EntryCategory
|
||||||
|
fields = ('id', 'name', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class ReferenceSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Reference
|
||||||
|
fields = ('id', 'name', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
ref = ReferenceSerializer()
|
||||||
|
cat = EntryCategorySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = ('id', 'ref', 'cat', 'location', 'opName', 'regTime', 'dncall', 'qrv2m', 'qrv70cm', 'extra2m70cm')
|
||||||
|
|
||||||
|
|
||||||
|
class QSOSerializer(serializers.ModelSerializer):
|
||||||
|
# owner = UserSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = QSO
|
||||||
|
fields = ('id', 'owner', 'time', 'call', 'callRef', 'remarks')
|
||||||
|
|
||||||
|
|
||||||
|
class ShadowCallSerializer(serializers.ModelSerializer):
|
||||||
|
ref = ReferenceSerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ShadowCall
|
||||||
|
fields = ('id', 'username', 'ref', 'location', 'opName', 'regTime')
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -0,0 +1,20 @@
|
||||||
|
from django.conf.urls import include, url
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from .views import ContestViewSet, BandViewSet, FrequencyViewSet, EntryCategoryViewSet, ReferenceViewSet, QSOViewSet, \
|
||||||
|
ShadowCallViewSet, UserProfileView
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register('contests', ContestViewSet)
|
||||||
|
router.register('bands', BandViewSet)
|
||||||
|
router.register('frequencies', FrequencyViewSet)
|
||||||
|
router.register('entrycategories', EntryCategoryViewSet)
|
||||||
|
router.register('references', ReferenceViewSet)
|
||||||
|
router.register('qsos', QSOViewSet, basename='qso')
|
||||||
|
router.register('shadowcalls', ShadowCallViewSet)
|
||||||
|
router.register('profile', UserProfileView, basename='profile')
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^', include(router.urls)),
|
||||||
|
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
|
]
|
|
@ -0,0 +1,57 @@
|
||||||
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from .serializers import ContestSerializer, BandSerializer, FrequencySerializer, EntryCategorySerializer, \
|
||||||
|
ReferenceSerializer, QSOSerializer, ShadowCallSerializer, UserSerializer
|
||||||
|
from contest.models import Contest, Band, Frequency, EntryCategory, Reference, QSO, ShadowCall
|
||||||
|
|
||||||
|
|
||||||
|
class ContestViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Contest.objects.all()
|
||||||
|
serializer_class = ContestSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class BandViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Band.objects.all()
|
||||||
|
serializer_class = BandSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class FrequencyViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = Frequency.objects.all()
|
||||||
|
serializer_class = FrequencySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class EntryCategoryViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
queryset = EntryCategory.objects.all()
|
||||||
|
serializer_class = EntryCategorySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ReferenceViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
permission_classes = [IsAdminUser]
|
||||||
|
queryset = Reference.objects.all()
|
||||||
|
serializer_class = ReferenceSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class QSOViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
serializer_class = QSOSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return QSO.objects.filter(owner=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
|
class UserProfileView(APIView):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request, format=None):
|
||||||
|
user = request.user
|
||||||
|
serializer = UserSerializer(user)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
|
class ShadowCallViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
permission_classes = [IsAdminUser]
|
||||||
|
queryset = ShadowCall.objects.all()
|
||||||
|
serializer_class = ShadowCallSerializer
|
|
@ -1,8 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
# prepare environment
|
# prepare environment
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("..")
|
sys.path.append("..")
|
||||||
|
@ -11,11 +9,15 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cqtu.settings")
|
||||||
import django
|
import django
|
||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
confirm = raw_input("Do are you sure you want to clear all contest data? Answer with uppercase YES: ")
|
confirm_msg = "Do are you sure you want to clear all contest data? Answer with uppercase YES: "
|
||||||
|
try:
|
||||||
|
confirm = raw_input(confirm_msg)
|
||||||
|
except NameError:
|
||||||
|
confirm = input(confirm_msg)
|
||||||
|
|
||||||
if confirm != "YES":
|
if confirm != "YES":
|
||||||
print("Aborting")
|
print("Aborting")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
from contest.models import QSO, ShadowCall, Reference, User
|
from contest.models import QSO, ShadowCall, Reference, User
|
||||||
|
|
|
@ -53,7 +53,7 @@ class User(AbstractUser):
|
||||||
|
|
||||||
location = models.CharField(max_length=128, default="", blank=True)
|
location = models.CharField(max_length=128, default="", blank=True)
|
||||||
opName = models.CharField(max_length=128, default="", blank=True)
|
opName = models.CharField(max_length=128, default="", blank=True)
|
||||||
regTime = models.DateTimeField(null=True, default=None)
|
regTime = models.DateTimeField(null=True, default=None, blank=True)
|
||||||
|
|
||||||
# because of cbr parsing bug, we sometimes have users who only have 70cm qsos
|
# because of cbr parsing bug, we sometimes have users who only have 70cm qsos
|
||||||
# we ignore the band for them when checking QSOs
|
# we ignore the band for them when checking QSOs
|
||||||
|
|
|
@ -41,9 +41,11 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'crispy_forms',
|
'crispy_forms',
|
||||||
|
'rest_framework',
|
||||||
|
|
||||||
# local
|
# local
|
||||||
'contest',
|
'contest',
|
||||||
|
'api',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
@ -34,6 +34,7 @@ urlpatterns = [
|
||||||
url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'),
|
url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'),
|
||||||
url(r'^register/$', register, name='register'),
|
url(r'^register/$', register, name='register'),
|
||||||
url(r'^profile/$', profile, name='profile'),
|
url(r'^profile/$', profile, name='profile'),
|
||||||
|
url(r'^api/', include('api.urls')),
|
||||||
#url(r'^register/$', CreateView.as_view(
|
#url(r'^register/$', CreateView.as_view(
|
||||||
# template_name='registration/register.html',
|
# template_name='registration/register.html',
|
||||||
# form_class=CustomUserCreationForm,
|
# form_class=CustomUserCreationForm,
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
Django==1.10
|
Django==1.11
|
||||||
django-crispy-forms
|
django-crispy-forms
|
||||||
|
|
|
@ -10,8 +10,11 @@
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p>
|
<p>
|
||||||
Please register with your (uppercase) Callsign as Usernames.
|
Please register with your (uppercase) Callsign as Usernames.
|
||||||
For DN-Calls, -[0-9] is allowed.
|
For DN-Calls, -[0-9] is allowed (e.g. DN1ABC-2 for the second group).
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Note: If you are a <strong>Ham/OM/YL</strong> please with your <strong>own</strong> callsign (e.g. DL7DOC). If you are a <strong>SWL</strong>, please use the <strong>DN-Call provided</strong> by your operator.
|
||||||
|
</p>
|
||||||
<form method="POST" action="{% url 'register' %}">
|
<form method="POST" action="{% url 'register' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form|crispy }}
|
{{ form|crispy }}
|
||||||
|
|
Loading…
Reference in New Issue