Skip to content

Commit

Permalink
submissions app
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Lind committed Aug 22, 2024
1 parent a5d8f89 commit 974009e
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 8 deletions.
1 change: 1 addition & 0 deletions mysite/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'django_celery_beat',
'django_filters',
'punchlist',
'submission',
'mysite.templatetags.custom_filters',
'import_export',
'storages',
Expand Down
3 changes: 3 additions & 0 deletions mysite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
3 changes: 0 additions & 3 deletions punchlist/__init__.py
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',)
3 changes: 0 additions & 3 deletions punchlist/labs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion punchlist/templates/agency_showcase.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2>Based on Skills Matching</h2>
<h5 class="card-title">
{{ agency.agency_name }}
{% if agency.certified %}
<i class="bi bi-patch-check-fill text-success" title="Certified Agency"></i>
<i class="bi bi-patch-check-fill text-success" title="Buildly Certified Agency" name="Buildly Certified"></i>
{% endif %}
</h5>
<p class="card-text">
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ drf-yasg==1.21.7
sendgrid
django-cors-headers
django-allauth
django-import-export
django-import-export
qrcode
Binary file added submission/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions submission/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This will make sure the app is always imported when
8 changes: 8 additions & 0 deletions submission/admin.py
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)
9 changes: 9 additions & 0 deletions submission/forms.py
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']
40 changes: 40 additions & 0 deletions submission/migrations/0001_initial.py
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.
52 changes: 52 additions & 0 deletions submission/models.py
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'
14 changes: 14 additions & 0 deletions submission/serializer_views.py
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
12 changes: 12 additions & 0 deletions submission/serializers.py
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__'
7 changes: 7 additions & 0 deletions submission/templates/link_generated.html
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 %}
12 changes: 12 additions & 0 deletions submission/templates/submission_form.html
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 %}
7 changes: 7 additions & 0 deletions submission/urls.py
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'),
]
43 changes: 43 additions & 0 deletions submission/views.py
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})

0 comments on commit 974009e

Please sign in to comment.