Homescreen Sort
parent
0bb24856c4
commit
578d053386
|
|
@ -3,12 +3,45 @@ import whois
|
|||
from app.models import Domain
|
||||
from app import db
|
||||
from app.utils import get_ssl_expiration, get_whois_expiration
|
||||
from datetime import datetime
|
||||
|
||||
domain_bp = Blueprint('domain', __name__)
|
||||
|
||||
@domain_bp.route('/')
|
||||
def home():
|
||||
return render_template('home.html')
|
||||
current_year = datetime.now().year
|
||||
all_domains = Domain.query.all()
|
||||
domains_expiring = []
|
||||
certs_expiring = []
|
||||
|
||||
for d in all_domains:
|
||||
# Filter and sort by WHOIS expiration date (expected format: mm/dd/yyyy)
|
||||
try:
|
||||
dt_whois = datetime.strptime(d.expiration_date, "%m/%d/%Y")
|
||||
if dt_whois.year == current_year:
|
||||
domains_expiring.append((dt_whois, d))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Filter and sort by SSL expiration date (expected format: mm/dd/yyyy)
|
||||
try:
|
||||
dt_ssl = datetime.strptime(d.ssl_expiration_date, "%m/%d/%Y")
|
||||
if dt_ssl.year == current_year:
|
||||
certs_expiring.append((dt_ssl, d))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Sort the lists in ascending order by the date
|
||||
domains_expiring.sort(key=lambda x: x[0])
|
||||
certs_expiring.sort(key=lambda x: x[0])
|
||||
|
||||
# Extract the domain objects from the sorted tuples
|
||||
domains_expiring = [item[1] for item in domains_expiring]
|
||||
certs_expiring = [item[1] for item in certs_expiring]
|
||||
|
||||
return render_template('home.html',
|
||||
domains_expiring=domains_expiring,
|
||||
certs_expiring=certs_expiring)
|
||||
|
||||
@domain_bp.route('/domains')
|
||||
def domains():
|
||||
|
|
|
|||
|
|
@ -1,6 +1,47 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Home{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Welcome to the Domain App</h1>
|
||||
<p>Use the navigation bar to view your domains or add new ones.</p>
|
||||
<h1>Domains Expiring this Year</h1>
|
||||
{% if domains_expiring and domains_expiring|length > 0 %}
|
||||
<table border="1" cellpadding="5" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>WHOIS Expiration</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for d in domains_expiring %}
|
||||
<tr>
|
||||
<td>{{ d.domain }}</td>
|
||||
<td>{{ d.expiration_date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No domains expiring this year.</p>
|
||||
{% endif %}
|
||||
|
||||
<h1>Certs Expiring this Year</h1>
|
||||
{% if certs_expiring and certs_expiring|length > 0 %}
|
||||
<table border="1" cellpadding="5" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>SSL Expiration</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for d in certs_expiring %}
|
||||
<tr>
|
||||
<td>{{ d.domain }}</td>
|
||||
<td>{{ d.ssl_expiration_date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No certificates expiring this year.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue