parent
948997835e
commit
4072a1524c
Binary file not shown.
Binary file not shown.
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.1.2 on 2020-11-07 00:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('download', '0010_downloadattempt'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='downloadattempt',
|
||||
name='geolocation',
|
||||
field=models.CharField(default='', max_length=64),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
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.
@ -1,5 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RequestConfig(AppConfig):
|
||||
name = 'request'
|
@ -1,5 +0,0 @@
|
||||
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)
|
Binary file not shown.
Binary file not shown.
@ -1,9 +0,0 @@
|
||||
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')
|
@ -1,10 +0,0 @@
|
||||
{% 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 %}
|
@ -1,6 +0,0 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='request')
|
||||
]
|
@ -1,38 +0,0 @@
|
||||
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.
@ -0,0 +1,32 @@
|
||||
{% extends 'common/master.html' %}
|
||||
{% block body %}
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td {
|
||||
padding: 20px;
|
||||
border: 1px solid black;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
<h1>View Download Attempts</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Address</th>
|
||||
<th>IP</th>
|
||||
<th>Geolocation</th>
|
||||
<th>Timestamp</th>
|
||||
</tr>
|
||||
{% for req in requests %}
|
||||
<tr>
|
||||
<td>{{ req.user.email }}</td>
|
||||
<td>{{ req.pdf.address.address }}</td>
|
||||
<td>{{ req.ip }}</td>
|
||||
<td>{{ req.geolocation }}</td>
|
||||
<td>{{ req.timestamp }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
@ -1,12 +1,9 @@
|
||||
from django.shortcuts import render, HttpResponse
|
||||
from request.models import QuoteRequest
|
||||
from download.models import DownloadAttempt
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
# TODO: Allow search
|
||||
return render(request, 'viewrequests/requests.html', {
|
||||
'requests': QuoteRequest.objects.all()
|
||||
'requests': DownloadAttempt.objects.all().order_by('-timestamp')[:100]
|
||||
})
|
||||
|
||||
def delete(request):
|
||||
print(request.POST)
|
||||
pass
|
Binary file not shown.
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -1,31 +0,0 @@
|
||||
{% 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 %}
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
Loading…
Reference in new issue