Merge pull request #1 from DreamFreely/feat_apikey

API KEYS working
This commit is contained in:
2025-10-11 20:21:48 -05:00
committed by GitHub
7 changed files with 51 additions and 10 deletions

Binary file not shown.

View File

@@ -45,8 +45,10 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_filters', 'django_filters',
'corsheaders',
'rest_framework', 'rest_framework',
'rest_framework.authtoken', # 'rest_framework.authtoken',
"rest_framework_api_key",
'socials', 'socials',
'events', 'events',
# 'academia_nuts', # 'academia_nuts',
@@ -56,6 +58,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -178,3 +181,12 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOWED_ORIGINS = [
"https://digisnaxx.com",
"https://www.digisnaxx.com",
# "http://localhost:5173",
# "http://127.0.0.1:9000",
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2025-10-11 16:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0027_scraper_new_items'),
]
operations = [
migrations.AddField(
model_name='event',
name='live',
field=models.CharField(choices=[('live', 'Live & Direct'), ('virt', 'Virtually Served'), ('both', 'How you prefer.')], default='live', max_length=4),
),
migrations.AlterField(
model_name='event',
name='event_type',
field=models.CharField(choices=[('Ot', 'Other'), ('Mu', 'Music'), ('Va', 'Visual Art'), ('Gv', 'Government'), ('Ce', 'Civic Engagement'), ('Ed', 'Educational'), ('Ma', 'Mutual Aid'), ('Th', 'Theater'), ('Co', 'Comedy')], default='Mu', max_length=15),
),
]

View File

@@ -110,10 +110,16 @@ class Event(models.Model):
('Th', 'Theater'), ('Th', 'Theater'),
('Co', 'Comedy'), ('Co', 'Comedy'),
) )
EVENT_STATE = (
('live', 'Live & Direct'),
('virt', 'Virtually Served'),
('both', 'How you prefer.')
)
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE, blank=True, null=True) calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE, blank=True, null=True)
scraper = models.ForeignKey(Scraper, on_delete=models.CASCADE, null=True) scraper = models.ForeignKey(Scraper, on_delete=models.CASCADE, null=True)
venue = models.ForeignKey(Organization, on_delete=models.CASCADE) venue = models.ForeignKey(Organization, on_delete=models.CASCADE)
event_type = models.CharField(max_length=15, choices=EVENT_TYPE, default='0') live = models.CharField(max_length=4, choices=EVENT_STATE, default='live')
event_type = models.CharField(max_length=15, choices=EVENT_TYPE, default='Mu')
show_title = models.CharField(max_length=127, blank=True, null=True) show_title = models.CharField(max_length=127, blank=True, null=True)
show_link = models.URLField(blank=True, null=True) show_link = models.URLField(blank=True, null=True)
guests = models.CharField(max_length=255, blank=True, null=True) guests = models.CharField(max_length=255, blank=True, null=True)

View File

@@ -59,7 +59,6 @@ def splitLocation(event):
venue, created = Organization.objects.get_or_create( venue, created = Organization.objects.get_or_create(
name=venue_name, name=venue_name,
city="Medellin", city="Medellin",
website="https://idioki.com/",
) )
event['venue'] = venue event['venue'] = venue
return event return event
@@ -96,13 +95,7 @@ for component in gcal.walk():
days = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"] days = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"]
for day in rules['BYDAY']: for day in rules['BYDAY']:
day = days.index(day) day = days.index(day)
loc_split = event['strLocation'].split(",") createEvent(day, date, event, scraper, event['venue'], "Ed")
venue, created = Organization.objects.get_or_create(
name=loc_split[0],
city="Medellin",
website="https://idioki.com/",
)
createEvent(day, date, event, scraper, venue, "Ed")
digitools.updateScraper(scraper, item_count_start) digitools.updateScraper(scraper, item_count_start)

View File

@@ -20,6 +20,7 @@ from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters from rest_framework import filters
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework_api_key.permissions import HasAPIKey
td = timedelta(hours=7) td = timedelta(hours=7)
odt = datetime.now() - td odt = datetime.now() - td
@@ -31,10 +32,12 @@ class EventsAPIView(generics.ListAPIView):
filter_backends = [DjangoFilterBackend, filters.SearchFilter] filter_backends = [DjangoFilterBackend, filters.SearchFilter]
filterset_fields = ['show_title', 'event_type', 'venue__name', 'calendar__shortcode'] filterset_fields = ['show_title', 'event_type', 'venue__name', 'calendar__shortcode']
search_fields = ['show_title', 'event_type', 'venue__name'] search_fields = ['show_title', 'event_type', 'venue__name']
permission_classes = [HasAPIKey]
class PromoAPIView(generics.ListAPIView): class PromoAPIView(generics.ListAPIView):
serializer_class = PromoSerializer serializer_class = PromoSerializer
permission_classes = [HasAPIKey]
def get_queryset(self): def get_queryset(self):
promo_objects = list(Promo.objects.filter(published=True)) promo_objects = list(Promo.objects.filter(published=True))

View File

@@ -12,6 +12,7 @@ from rest_framework.decorators import authentication_classes, permission_classes
from rest_framework.authentication import SessionAuthentication, BasicAuthentication from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework_api_key.permissions import HasAPIKey
# from durin.auth import TokenAuthentication # from durin.auth import TokenAuthentication
# from durin.views import APIAccessTokenView # from durin.views import APIAccessTokenView
@@ -36,15 +37,18 @@ class FAQsAPIView(generics.ListAPIView):
class SocialPostsAPIView(generics.ListAPIView): class SocialPostsAPIView(generics.ListAPIView):
serializer_class = SocialPostSerializer serializer_class = SocialPostSerializer
queryset = SocialPost.objects.filter(published=True) queryset = SocialPost.objects.filter(published=True)
permission_classes = [HasAPIKey]
class SocialLinksAPIView(generics.ListAPIView): class SocialLinksAPIView(generics.ListAPIView):
serializer_class = SocialLinkSerializer serializer_class = SocialLinkSerializer
queryset = SocialLink.objects.all()[:50] queryset = SocialLink.objects.all()[:50]
permission_classes = [HasAPIKey]
class SocialImgsAPIView(generics.ListAPIView): class SocialImgsAPIView(generics.ListAPIView):
serializer_class = SocialImgsSerializer serializer_class = SocialImgsSerializer
queryset = SocialImg.objects.all()[:18] queryset = SocialImg.objects.all()[:18]
permission_classes = [HasAPIKey]