From 974009e047d355a18f5a9a1e5318831677d9a3ee Mon Sep 17 00:00:00 2001 From: Greg Lind Date: Thu, 22 Aug 2024 10:34:04 -0700 Subject: [PATCH] submissions app --- mysite/settings/base.py | 1 + mysite/urls.py | 3 ++ punchlist/__init__.py | 3 -- punchlist/labs.py | 3 -- punchlist/templates/agency_showcase.html | 2 +- requirements.txt | 3 +- submission/.DS_Store | Bin 0 -> 6148 bytes submission/__init__.py | 1 + submission/admin.py | 8 ++++ submission/forms.py | 9 ++++ submission/migrations/0001_initial.py | 40 +++++++++++++++++ submission/migrations/__init__.py | 0 submission/models.py | 52 ++++++++++++++++++++++ submission/serializer_views.py | 14 ++++++ submission/serializers.py | 12 +++++ submission/templates/link_generated.html | 7 +++ submission/templates/submission_form.html | 12 +++++ submission/urls.py | 7 +++ submission/views.py | 43 ++++++++++++++++++ 19 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 submission/.DS_Store create mode 100644 submission/__init__.py create mode 100644 submission/admin.py create mode 100644 submission/forms.py create mode 100644 submission/migrations/0001_initial.py create mode 100644 submission/migrations/__init__.py create mode 100644 submission/models.py create mode 100644 submission/serializer_views.py create mode 100644 submission/serializers.py create mode 100644 submission/templates/link_generated.html create mode 100644 submission/templates/submission_form.html create mode 100644 submission/urls.py create mode 100644 submission/views.py diff --git a/mysite/settings/base.py b/mysite/settings/base.py index 3c19169..37d6808 100644 --- a/mysite/settings/base.py +++ b/mysite/settings/base.py @@ -38,6 +38,7 @@ 'django_celery_beat', 'django_filters', 'punchlist', + 'submission', 'mysite.templatetags.custom_filters', 'import_export', 'storages', diff --git a/mysite/urls.py b/mysite/urls.py index 2967be5..83ee810 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -33,6 +33,9 @@ path("logout", views.logout_request, name= "logout"), path("edit_profile/", views.edit_profile, name="edit_profile"), + # qr code submissions + path('submission/', include('submission.urls')), + # password reset path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'), path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'), diff --git a/punchlist/__init__.py b/punchlist/__init__.py index f3c5e8d..8b37ec7 100644 --- a/punchlist/__init__.py +++ b/punchlist/__init__.py @@ -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',) diff --git a/punchlist/labs.py b/punchlist/labs.py index a01fd8f..ae9fb66 100644 --- a/punchlist/labs.py +++ b/punchlist/labs.py @@ -12,8 +12,6 @@ def get_products(): url = "https://insights-api.buildly.io/product/product/" headers = { "Authorization ": f"Token {os.environ.get('INSIGHTS_API_KEY')}" } - # headers = { "Authorization ": "Token qiqMN09rftSmuTEhiuviA1tdHWlCe2" } - # headers = { "Authorization ": "Token 6y2lTVWR8EXMRwTAg6lnzOLhPrmHBo"} print(url) print(headers) response = requests.get(url, headers=headers) @@ -30,7 +28,6 @@ def get_products(): def get_releases(product_id): url = f"https://insights-api.buildly.io/release/release/?product_uuid={product_id}" headers = { "Authorization ": f"Token {os.environ.get('INSIGHTS_API_KEY')}" } - # headers = {"Authorization : Token qiqMN09rftSmuTEhiuviA1tdHWlCe2"} response = requests.get(url, headers=headers) if response.status_code == 200: diff --git a/punchlist/templates/agency_showcase.html b/punchlist/templates/agency_showcase.html index 2c1d0f0..db57952 100644 --- a/punchlist/templates/agency_showcase.html +++ b/punchlist/templates/agency_showcase.html @@ -60,7 +60,7 @@

Based on Skills Matching

{{ agency.agency_name }} {% if agency.certified %} - + {% endif %}

diff --git a/requirements.txt b/requirements.txt index 46ef85a..2ced3f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,5 @@ drf-yasg==1.21.7 sendgrid django-cors-headers django-allauth -django-import-export \ No newline at end of file +django-import-export +qrcode \ No newline at end of file diff --git a/submission/.DS_Store b/submission/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c1b88feafccfc110f362fed0987aee85ef131705 GIT binary patch literal 6148 zcmeHKu};H44E2=`sk(Gzyq&2NYg&ab=m!LvB08i>Bw#=Y=~jM(FF|7KA22ZU5%7Gr z+D1t$u~ZeZCEvUF?2Gd*ien;j)5pb_XhcK_l(9F!&>_6e+LE4Hc+tf@3c8_!mUK&b z%i9d6$N-<+5T}(>O;0$x?fK>9-FQ}1t6I{YT<-T=RarJKt2sQ9mvyrK{Cb}p@?QMG zyI$^Q5wI-{=mBro3K^Hkm*@A*Trc=d?(o{p^XL2R`Sl~_+3C5>@vvt{ew?F;F<=ZB z1EX#}8K?x_P&4<%FJMBXrnP;3^W-ylgkm;|EvA|e>2Fg zi~(cdUoqhN*({slk+in99*%3Rhh9Tj*e?ifLNJM?7`|MJ&!JIZ_dEfnia`(-i2Vpe L8f-8Ij>^CYour unique submission link and QR code: +

URL: {{ submission_link.unique_url }}

+QR Code +{% endblock %} \ No newline at end of file diff --git a/submission/templates/submission_form.html b/submission/templates/submission_form.html new file mode 100644 index 0000000..674f7e5 --- /dev/null +++ b/submission/templates/submission_form.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block content %} + +

Submit Your Information

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} diff --git a/submission/urls.py b/submission/urls.py new file mode 100644 index 0000000..082ade5 --- /dev/null +++ b/submission/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('generate/', views.generate_link, name='generate_link'), + path('submit//', views.submission_form, name='submission_form'), +] diff --git a/submission/views.py b/submission/views.py new file mode 100644 index 0000000..6649602 --- /dev/null +++ b/submission/views.py @@ -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})