Add request tracker; request tracker view; remove upload, request tracker from normal view. Must be logged in now.
parent
4cfaa02df9
commit
948997835e
@ -1,5 +1,9 @@
|
||||
{% extends 'common/master.html' %}
|
||||
{% block body %}
|
||||
<a href="{% url 'upload' %}">Upload</a>
|
||||
<a href="{% url 'download' %}">Download</a>
|
||||
{% if user.is_authenticated %}
|
||||
<a href="{% url 'upload' %}">Upload</a>
|
||||
<a href="{% url 'requests_view' %}">View Requests</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'download' %}">Download</a>
|
||||
<a href="{% url 'request' %}">Request</a>
|
||||
{% endblock %}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RequestConfig(AppConfig):
|
||||
name = 'request'
|
@ -0,0 +1,5 @@
|
||||
from django import forms
|
||||
|
||||
class RequestForm(forms.Form):
|
||||
email = forms.EmailField(label='Email', max_length=32, required=True)
|
||||
address = forms.CharField(label='Address', max_length=64, required=True)
|
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.2 on 2020-11-06 18:06
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('download', '0009_auto_20201106_1718'),
|
||||
('core', '0002_quoteuser'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='QuoteRequest',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('timestamp', models.DateTimeField(auto_now_add=True)),
|
||||
('address', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quote_requests', to='download.address')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quote_requests', to='core.quoteuser')),
|
||||
],
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
from django.db import models
|
||||
from core.models import QuoteUser
|
||||
from download.models import Address
|
||||
|
||||
# Create your models here.
|
||||
class QuoteRequest(models.Model):
|
||||
timestamp = models.DateTimeField(auto_now_add=True, editable=False, null=False, blank=False)
|
||||
address = models.ForeignKey(Address, on_delete=models.CASCADE, related_name='quote_requests')
|
||||
user = models.ForeignKey(QuoteUser, on_delete=models.CASCADE, related_name='quote_requests')
|
@ -0,0 +1,10 @@
|
||||
{% extends 'common/master.html' %}
|
||||
{% block body %}
|
||||
<h1>Request A Quote</h1>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<p>{{ message }}</p>
|
||||
{% endblock %}
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='request')
|
||||
]
|
@ -0,0 +1,38 @@
|
||||
from django.shortcuts import render, HttpResponse
|
||||
from .forms import RequestForm
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
|
||||
from core.models import QuoteUser
|
||||
from download.models import Address
|
||||
from .models import QuoteRequest
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
if request.method == 'POST':
|
||||
form = RequestForm(request.POST)
|
||||
if form.is_valid():
|
||||
to_addr = form.cleaned_data['email']
|
||||
address = form.cleaned_data['address']
|
||||
email = EmailMultiAlternatives()
|
||||
email.to = [to_addr]
|
||||
email.bcc = [settings.REQUEST_BBC]
|
||||
email.body = 'Somebody has requested a quote'
|
||||
try:
|
||||
email.send()
|
||||
except:
|
||||
return HttpResponse('Error', code=500)
|
||||
# if all went all, add user, address, and request to database
|
||||
# TODO: add messages
|
||||
user, user_created = QuoteUser.objects.get_or_create(username=to_addr, email=to_addr)
|
||||
addr, addr_created = Address.objects.get_or_create(address=address)
|
||||
qr, qr_created = QuoteRequest.objects.get_or_create(user=user, address=addr)
|
||||
return render(request, 'request/request.html', {
|
||||
'form': RequestForm(),
|
||||
'message': 'Thank you for requesting a quote. We will get back to you soon.'
|
||||
})
|
||||
else:
|
||||
return render(request, 'request/request.html', {
|
||||
'form': RequestForm()
|
||||
})
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ViewrequestsConfig(AppConfig):
|
||||
name = 'viewrequests'
|
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
@ -0,0 +1,31 @@
|
||||
{% extends 'common/master.html' %}
|
||||
{% block body %}
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td {
|
||||
padding: 20px;
|
||||
border: 1px solid black;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Address</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
{% for req in requests %}
|
||||
<tr>
|
||||
<td>{{ req.user.email }}</td>
|
||||
<td>{{ req.address.address }}</td>
|
||||
<td><input type="checkbox" value="{{ req.id }}" name="req_ids" id="req_ids_{{ req.id }}"></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<input type="submit" value="Delete">
|
||||
</form>
|
||||
{% endblock %}
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='requests_view'),
|
||||
path('delete/', views.delete, name='requests_delete')
|
||||
]
|
@ -0,0 +1,12 @@
|
||||
from django.shortcuts import render, HttpResponse
|
||||
from request.models import QuoteRequest
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
return render(request, 'viewrequests/requests.html', {
|
||||
'requests': QuoteRequest.objects.all()
|
||||
})
|
||||
|
||||
def delete(request):
|
||||
print(request.POST)
|
||||
pass
|
Loading…
Reference in new issue