Skip to content

Commit

Permalink
Merge pull request #50 from telminov/48
Browse files Browse the repository at this point in the history
48
  • Loading branch information
telminov committed Jun 10, 2017
2 parents 9df5ada + 344fb17 commit 722caf3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
23 changes: 23 additions & 0 deletions core/static/core/css/custom_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,26 @@ footer {
margin-top: 2rem;
}

th.sortable::after {
display: inline-block;
width: 10px;
height: 10px;
content: "";
background:url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIUnC2nKLnT4or00PvyrQwrPzUZshQAOw==) no-repeat;
}

th.sortable.desc::after {
display: inline-block;
width: 10px;
height: 13px;
content: "";
background:url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIPnI+py+0/hJzz0IruwjsVADs=) no-repeat;
}

th.sortable.asc::after {
display: inline-block;
width: 10px;
height: 7px;
content: "";
background:url(data:image/gif;base64,R0lGODlhCwALAJEAAAAAAP///xUVFf///yH5BAEAAAMALAAAAAALAAsAAAIRnC2nKLnT4or00Puy3rx7VQAAOw==) no-repeat;
}
7 changes: 4 additions & 3 deletions core/templates/core/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'core/base.html' %}
{% load bootstrap3 %}
{% load djutils %}

{% block title %}Certification authority interface{% endblock %}

Expand All @@ -25,9 +26,9 @@
<table class="table main-table">
<tr>
<th>#</th>
<th>Common Name</th>
<th>Created</th>
<th>Expiring date</th>
{% sort_th 'cn' 'Common Name' %}
{% sort_th 'date_start' 'Created' %}
{% sort_th 'date_end' 'Expiring date' %}
<th>Download</th>
</tr>
{% for object in object_list %}
Expand Down
8 changes: 2 additions & 6 deletions core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_auth(self):
def test_smoke(self):
self.client.force_login(user=self.user)

response = self.client.get(reverse('certificate_search'))
response = self.client.get(reverse('certificate_search'), {'sort': 'cn'})

self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'core/index.html')
Expand All @@ -295,7 +295,7 @@ def test_search(self):
factories.SiteCrt.create(cn='127.0.0.2')
self.client.force_login(user=self.user)

response = self.client.get(reverse('certificate_search'), {'cn': '127.0.0.1'})
response = self.client.get(reverse('certificate_search'), {'cn': '127.0.0.1', 'sort': 'cn'})

self.assertEqual(len(response.context['object_list']), 1)

Expand Down Expand Up @@ -333,7 +333,6 @@ def test_success_url(self):
self.client.force_login(user=self.user)
response = self.client.post(reverse('create_crt'), {'cn': '127.0.0.1', 'validity_period': '2019-05-29'})

self.assertRedirects(response, reverse('certificate_search'))
self.assertEqual(models.SiteCrt.objects.get().cn, '127.0.0.1')

def test_context(self):
Expand Down Expand Up @@ -387,15 +386,13 @@ def test_form_valid_files(self):
{'crt_file': SimpleUploadedFile('test.crt', factories.site_crt_all_fields),
'key_file': SimpleUploadedFile('test.key', factories.site_key_all_fields)})

self.assertRedirects(response, reverse('certificate_search'))
self.assertEqual(models.SiteCrt.objects.all().count(), 1)

def test_form_valid_text(self):
self.client.force_login(user=self.user)
response = self.client.post(reverse('upload_existing'), {'crt_text': factories.site_crt_all_fields.decode(),
'key_text': factories.site_key_all_fields.decode()})

self.assertRedirects(response, reverse('certificate_search'))
self.assertEqual(models.SiteCrt.objects.all().count(), 1)


Expand Down Expand Up @@ -498,7 +495,6 @@ def test_delete(self):
response = self.client.post(reverse('delete_crt', kwargs={'pk': '1'}))

self.assertEqual(models.SiteCrt.objects.all().count(), 0)
self.assertRedirects(response, reverse('certificate_search'))

def test_context(self):
self.client.force_login(user=self.user)
Expand Down
7 changes: 4 additions & 3 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from datetime import datetime, timedelta
from OpenSSL import crypto
from djutils.views.generic import SortMixin

from django.utils import timezone
from django.conf import settings
Expand Down Expand Up @@ -127,19 +128,19 @@ class Index(RedirectView):
url = reverse_lazy('certificate_search')


class SearchSiteCrt(BreadcrumbsMixin, FormMixin, ListView):
class SearchSiteCrt(BreadcrumbsMixin, SortMixin, FormMixin, ListView):
form_class = forms.SearchSiteCrt
model = models.SiteCrt
template_name = 'core/index.html'
data_method = None
sort_params = ['cn', 'date_start', 'date_end']

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['data'] = self.request.GET
return kwargs

def get_queryset(self):
queryset = super().get_queryset().order_by('-id')
queryset = super().get_queryset()
form = self.form_class(self.request.GET)
if form.is_valid():
cn = form.cleaned_data['cn']
Expand Down
2 changes: 2 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
'rest_framework',
'rest_framework.authtoken',

'djutils',

'core',
]

Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ factory-boy==2.8.1
raven==6.1.0
ipython
gunicorn==19.7.1
django_filter==1.0.4
django-filter==1.0.4
sw-django-utils==0.0.35
sw-python-utils==0.0.15

0 comments on commit 722caf3

Please sign in to comment.