-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Greg Lind
committed
Aug 22, 2024
1 parent
a5d8f89
commit 974009e
Showing
19 changed files
with
212 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
# This will make sure the app is always imported when | ||
# Django starts so that shared_task will use this app. | ||
from celery import app as celery_app | ||
|
||
__all__ = ('celery_app',) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ drf-yasg==1.21.7 | |
sendgrid | ||
django-cors-headers | ||
django-allauth | ||
django-import-export | ||
django-import-export | ||
qrcode |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This will make sure the app is always imported when |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .models import * | ||
from django.contrib import admin | ||
|
||
from import_export.admin import ImportExportModelAdmin | ||
from import_export import resources | ||
|
||
admin.site.register(Submission, SubmissionAdmin) | ||
admin.site.register(SubmissionLink, SubmissionLinkAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# submission/forms.py | ||
|
||
from django import forms | ||
from .models import Submission | ||
|
||
class SubmissionForm(forms.ModelForm): | ||
class Meta: | ||
model = Submission | ||
fields = ['name', 'email', 'description'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 3.2.25 on 2024-08-22 17:33 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SubmissionLink', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('unique_url', models.URLField(max_length=255, unique=True)), | ||
('qr_code', models.ImageField(blank=True, upload_to='qr_codes/')), | ||
('create_date', models.DateTimeField(blank=True, null=True)), | ||
('edit_date', models.DateTimeField(blank=True, null=True)), | ||
('admin_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Submission', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('email', models.EmailField(max_length=254)), | ||
('description', models.TextField()), | ||
('create_date', models.DateTimeField(blank=True, null=True)), | ||
('edit_date', models.DateTimeField(blank=True, null=True)), | ||
('submission_link', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='submission.submissionlink')), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from datetime import timedelta | ||
from decimal import Decimal | ||
import uuid | ||
import datetime | ||
|
||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from django.utils.crypto import get_random_string | ||
from django.contrib import admin | ||
from django.utils import timezone | ||
|
||
class SubmissionLink(models.Model): | ||
admin_user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
unique_url = models.URLField(max_length=255, unique=True) | ||
qr_code = models.ImageField(upload_to='qr_codes/', blank=True) | ||
create_date = models.DateTimeField(null=True, blank=True) | ||
edit_date = models.DateTimeField(null=True, blank=True) | ||
|
||
|
||
def save(self, *args, **kwargs): | ||
# onsave add create date or update edit date | ||
if self.create_date == None: | ||
self.create_date = timezone.now() | ||
self.edit_date = timezone.now() | ||
if not self.unique_url: | ||
self.unique_url = get_random_string(32) # Generates a random URL string | ||
super().save(*args, **kwargs) | ||
|
||
|
||
class SubmissionLinkAdmin(admin.ModelAdmin): | ||
list_display = ('admin_user','unique_url','create_date','edit_date') | ||
display = 'Submission Link Admin' | ||
|
||
class Submission(models.Model): | ||
submission_link = models.ForeignKey(SubmissionLink, on_delete=models.CASCADE) | ||
name = models.CharField(max_length=100) | ||
email = models.EmailField() | ||
description = models.TextField() | ||
create_date = models.DateTimeField(null=True, blank=True) | ||
edit_date = models.DateTimeField(null=True, blank=True) | ||
|
||
def save(self, *args, **kwargs): | ||
# onsave add create date or update edit date | ||
if self.create_date == None: | ||
self.create_date = timezone.now() | ||
self.edit_date = timezone.now() | ||
super(Submission, self).save(*args, **kwargs) | ||
|
||
|
||
class SubmissionAdmin(admin.ModelAdmin): | ||
list_display = ('submission_link','name','email','create_date','edit_date') | ||
display = 'Submission Admin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import generics | ||
from .models import * | ||
from .serializers import * | ||
from rest_framework.authentication import TokenAuthentication | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
|
||
class PositionList(generics.ListCreateAPIView): | ||
queryset = Position.objects.all() | ||
serializer_class = PositionSerializer | ||
|
||
class PositionDetail(generics.RetrieveUpdateDestroyAPIView): | ||
queryset = Position.objects.all() | ||
serializer_class = PositionSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import serializers | ||
from .models import * | ||
|
||
class PositionSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Position | ||
fields = '__all__' | ||
|
||
class BugSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Bug | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h2>Your unique submission link and QR code:</h2> | ||
<p>URL: <a href="{{ submission_link.unique_url }}">{{ submission_link.unique_url }}</a></p> | ||
<img src="{{ submission_link.qr_code.url }}" alt="QR Code"> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
|
||
<h2>Submit Your Information</h2> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit">Submit</button> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from . import views | ||
|
||
urlpatterns = [ | ||
path('generate/', views.generate_link, name='generate_link'), | ||
path('submit/<str:unique_url>/', views.submission_form, name='submission_form'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.shortcuts import render, redirect, get_object_or_404 | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse | ||
from .models import SubmissionLink, Submission | ||
from .forms import SubmissionForm | ||
import qrcode | ||
|
||
@login_required | ||
def generate_link(request): | ||
submission_link = SubmissionLink.objects.create(admin_user=request.user) | ||
|
||
# Generate QR code | ||
qr = qrcode.QRCode( | ||
version=1, | ||
error_correction=qrcode.constants.ERROR_CORRECT_L, | ||
box_size=10, | ||
border=4, | ||
) | ||
qr.add_data(submission_link.unique_url) | ||
qr.make(fit=True) | ||
|
||
img = qr.make_image(fill='black', back_color='white') | ||
img_path = f'media/qr_codes/{submission_link.unique_url}.png' | ||
img.save(img_path) | ||
|
||
submission_link.qr_code = img_path | ||
submission_link.save() | ||
|
||
return render(request, 'submission/link_generated.html', {'submission_link': submission_link}) | ||
|
||
def submission_form(request, unique_url): | ||
submission_link = get_object_or_404(SubmissionLink, unique_url=unique_url) | ||
if request.method == 'POST': | ||
form = SubmissionForm(request.POST) | ||
if form.is_valid(): | ||
submission = form.save(commit=False) | ||
submission.submission_link = submission_link | ||
submission.save() | ||
return HttpResponse('Submission successful.') | ||
else: | ||
form = SubmissionForm() | ||
|
||
return render(request, 'submission/submission_form.html', {'form': form}) |