Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Whois bar, Domain Lookup #234

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
scrapy==2.11.0
psycopg2==2.9.6
psycopg2-binary==2.9.6
django==4.1.7
django-debug-toolbar==4.0.0
aiogram==3.0.0b8
python-dotenv==1.0.0
python-whois==0.8.0
13 changes: 13 additions & 0 deletions src/website/catalog/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django import forms
from django.core.validators import RegexValidator

URL_VALIDATOR_MESSAGE = 'Недопустимый URL.'
URL_VALIDATOR = RegexValidator(regex=r'^(https?://)?(www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/[a-zA-Z0-9._%+-]*)*$', message=URL_VALIDATOR_MESSAGE)

SORT_BY_CHOICES = [
("CN", "Имя компании"),
Expand Down Expand Up @@ -28,3 +32,12 @@ class CompaniesSortForm(forms.Form):
label="Поиск",
max_length=50,
required=False,)


class DomainLookupForm(forms.Form):
domain = forms.CharField(
label="Домен:",
max_length=253,
required=False,
validators=[URL_VALIDATOR]
)
37 changes: 27 additions & 10 deletions src/website/catalog/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.shortcuts import render
from django.http import HttpResponseNotFound
from django.db.models import Q
from django.contrib import messages

from .models import Price, Registrator
from .forms import CompaniesSortForm
from .forms import CompaniesSortForm, DomainLookupForm

import whois


SORT_FIELD_NAMES = {
Expand All @@ -17,18 +20,32 @@


def registrator_list(request):
search = ''
sort_by = 'id'
if request.method == "POST":
form = CompaniesSortForm(request.POST)
if form.is_valid():
sort_by = (form.cleaned_data['reverse_order']
+ SORT_FIELD_NAMES.get(
form.cleaned_data['sort_by'], 'name'))
search = form.cleaned_data['search']
if 'search_sub' in request.POST:
form = CompaniesSortForm(request.POST)
domain_lookup_form = DomainLookupForm()
if form.is_valid():
sort_by = form.cleaned_data['reverse_order'] + SORT_FIELD_NAMES.get(form.cleaned_data['sort_by'], 'name')
search = form.cleaned_data['search']

elif 'whois_sub' in request.POST:
domain_lookup_form = DomainLookupForm(request.POST)
form = CompaniesSortForm()
if domain_lookup_form.is_valid():
domain = domain_lookup_form.cleaned_data.get('domain')
try:
whois.whois(domain)
messages.success(request, f"Домен: {domain} занят.")
except whois.parser.PywhoisError:
messages.success(request, f"Домен: {domain} свободен.")
else:
messages.error(request, "Недопустимый URL.")

else:
form = CompaniesSortForm()
sort_by = 'id'
search = ''
domain_lookup_form = DomainLookupForm()

if search:
companies = Price.objects.filter(Q(registrator__name__icontains=search) | Q(
Expand All @@ -40,7 +57,7 @@ def registrator_list(request):
companies = Price.objects.filter(id__in=companies).distinct('registrator_id')
companies = Price.objects.filter(id__in=companies).order_by(sort_by)

return render(request, 'registrator-list.html', {'companies': companies, 'form': form})
return render(request, 'registrator-list.html', {'companies': companies, 'form': form, 'domain_lookup_form': domain_lookup_form})


def registrator_details(request, id):
Expand Down
2 changes: 1 addition & 1 deletion src/website/website/templates/companies-sort.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<form class="forma mb-3" action="{% url 'registrator_list' %}" method="post">
{% csrf_token %}
{{ form }}
<input class="btn btn-primary ml-2" type="submit" value="Показать">
<input class="btn btn-primary ml-2" type="submit" name="search_sub" value="Показать">
</form>
</div>

Expand Down
120 changes: 120 additions & 0 deletions src/website/website/templates/domain-lookup-form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Mulish&display=swap" rel="stylesheet">

<div class="wrapper-whois">
<form class="forma-whois mb-3" action="{% url 'registrator_list' %}" method="post">
{% csrf_token %}
{{ domain_lookup_form.domain.label }}
{{ domain_lookup_form.domain }}
<input class="btn btn-primary ml-2" type="submit" name="whois_sub" value="Проверить">
{% if messages %}
<ul class="messages" style="list-style-type: none;">
{% for message in messages %}
<li {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
</form>

</div>
<style>
@import url('https://fonts.googleapis.com/css2?family=Mulish&display=swap');

.wrapper-whois {
margin-top: 20px !important;
display: flex !important;
width: 1730px;
margin: 10px auto;
padding: 20px;
align-items: center;
}

.forma-whois {
margin-top: 17px;
margin-left: 600px;
font-family: 'Mulish';
font-style: normal;
font-weight: 700;
font-size: 16px;
color: #333;
flex: 1;
}

.forma-whois input[type="text"] {
width: 600px;
height: 70px;
margin-left: 5px;
box-sizing: border-box;
background: #FFFFFF;
border: 1px solid #C1C1C1;
border-radius: 10px;
font-family: 'Mulish';
font-style: normal;
font-weight: 400;
font-size: 20px;
line-height: 24px;
padding-left: 40px;
color: rgba(45, 45, 45, 0.7);
margin-right: 20px;
}

.forma-whois input[type="text"]::placeholder {
color: rgba(45, 45, 45, 0.7);
}

.forma-whois input[type="text"]:focus {
border: 1px solid #14D563;
outline: none;
}


.input {
font-family: 'Mulish';
font-style: normal;
font-weight: 400;
font-size: 20px;
color: #666;
flex: 3;
}

.btn {
width: 166px;
height: 55px;
font-family: 'Mulish';
font-style: normal;
font-weight: 500;
font-size: 20px;
line-height: 24px;
text-align: center;
color: #FFFFFF;
background: #14D563;
border: none;
border-radius: 10px;
cursor: pointer;
margin-bottom: 10px;
}

.submit:hover {
background: #0f9b4b;
}

.forma select {
height: 70px;
padding: 11px;
background: #FAFAFA;
border: 1px solid #C1C1C1;
border-radius: 10px;
box-sizing: border-box;
font-family: 'Mulish';
font-style: normal;
font-weight: 400;
font-size: 20px;
color: #2D2D2D;
position: relative;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin-right: 45px;
}
</style>
1 change: 1 addition & 0 deletions src/website/website/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<a class="navbar-brand" href="/list" style="position: absolute; left: 130px; top: 18px;">
<img src="{% static 'ecoIcons/Логотип (light).svg'%}" width="264" height="72" class="logo d-inline-block align-top" alt="Логотип" style="width: 264px; height: 72px;">
</a>
{% include 'domain-lookup-form.html' with form=form %}
<div class="projbutton ml-auto">
<a href="/project">Проект</a>
</div>
Expand Down