Added PostListViewUngleichTest, Added PostDetailViewUngleich, Converted detail ungleich post view into Class Based Django view, Added translations to ungleich landing page

This commit is contained in:
Levi 2016-07-15 00:14:51 -05:00
parent 48650f33ce
commit 7cd5244fdc
11 changed files with 217 additions and 35 deletions

View file

@ -1,6 +1,6 @@
from unittest import mock from unittest import mock
from django.conf import settings from django.conf import settings
from django.test import TestCase, RequestFactory from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve from django.core.urlresolvers import resolve
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
@ -115,7 +115,7 @@ class HostingPricingViewTest(TestCase):
found = resolve(self.url) found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__) self.assertEqual(found.func.__name__, self.view.__name__)
def get(self): def test_get(self):
response = self.client.get(self.url) response = self.client.get(self.url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(self.view.get_context_data(), self.expected_context) self.assertEqual(self.view.get_context_data(), self.expected_context)

View file

@ -17,13 +17,13 @@
Posted Posted
{% if post.author %} {% if post.author %}
by by
<a href="{% url 'djangocms_blog:posts-author' post.author.get_username %}"> <!-- <a href="{% url 'djangocms_blog:posts-author' post.author.get_username %}"> -->
{% if post.author.get_full_name %} {% if post.author.get_full_name %}
{{ post.author.get_full_name }} {{ post.author.get_full_name }}
{% else %} {% else %}
{{ post.author }} {{ post.author }}
{% endif %} {% endif %}
</a> <!-- </a> -->
{% endif %} {% endif %}
on {{ post.date_published|date:"DATE_FORMAT" }} on {{ post.date_published|date:"DATE_FORMAT" }}
</p> </p>

114
ungleich/test_views.py Normal file
View file

@ -0,0 +1,114 @@
from utils.tests import BaseTestCase
from django.conf import settings
from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve
from django.utils.translation import get_language
from django.utils.translation import activate
from djangocms_blog.settings import get_setting
from djangocms_blog.models import Post
from model_mommy import mommy
from .views import PostListViewUngleich, PostDetailViewUngleich
class PostListViewUngleichTest(BaseTestCase):
DE_LANGUAGE_CODE = 'de'
EN_LANGUAGE_CODE = 'en-us'
def setUp(self):
super(PostListViewUngleichTest, self).setUp()
self.url = reverse('ungleich:post-list')
self.view = PostListViewUngleich
self.expected_template = 'djangocms_blog/post_list_ungleich.html'
en_post_titles = ['post-title-1', 'post-title-2']
self.en_posts = [mommy.make(Post, title=x, publish=True) for x in en_post_titles]
# activate DE language in order to create DE POSTS
activate(self.DE_LANGUAGE_CODE)
de_post_titles = ['post-title-3', 'post-title-4']
self.de_posts = [mommy.make(Post, title=x, publish=True) for x in de_post_titles]
self.expected_context = {
'TRUNCWORDS_COUNT': get_setting('POSTS_LIST_TRUNCWORDS_COUNT'),
'languages': settings.LANGUAGES,
'current_language': get_language()
}
def test_url_resolve_to_view_correctly(self):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__)
def test_queryset(self):
# testing EN-US Post queryset
activate(self.EN_LANGUAGE_CODE)
view = self.setup_view(self.view())
queryset = view.get_queryset()
self.assertEqual(self.en_posts, list(queryset.order_by('id')))
# testing DE Post queryset
activate(self.DE_LANGUAGE_CODE)
view = self.setup_view(self.view())
queryset = view.get_queryset()
self.assertEqual(self.de_posts, list(queryset.order_by('id')))
def test_get_context(self):
view = self.setup_view(self.view())
queryset = view.get_queryset()
view.object_list = queryset
context = view.get_context_data()
self.assertEqual(self.expected_context.get('current_language'),
context['current_language'])
class DetailsViewTest(BaseTestCase):
DE_LANGUAGE_CODE = 'de'
EN_LANGUAGE_CODE = 'en-us'
def setUp(self):
super(DetailsViewTest, self).setUp()
self.url = reverse('ungleich:post-list')
self.view = PostDetailViewUngleich
self.expected_template = 'djangocms_blog/post_detail.html'
self.en_post = mommy.make(Post, publish=True, title='post-title-en')
# activate DE language in order to create DE POSTS
activate(self.DE_LANGUAGE_CODE)
self.de_post = mommy.make(Post, publish=True, title='post-title-de')
self.en_post_kwargs = {
'slug': self.en_post.slug,
'year': self.en_post.date_created.year,
'month': self.en_post.date_created.month,
'day': self.en_post.date_created.day
}
self.en_post_url = reverse('ungleich:post-detail', kwargs=self.en_post_kwargs)
self.de_post_kwargs = {
'slug': self.de_post.slug,
'year': self.de_post.date_created.year,
'month': self.de_post.date_created.month,
'day': self.de_post.date_created.day
}
self.de_post_url = reverse('ungleich:post-detail', kwargs=self.de_post_kwargs)
def test_url_resolve_to_view_correctly(self):
found = resolve(self.en_post_url)
self.assertEqual(found.func.__name__, self.view.__name__)
found = resolve(self.de_post_url)
self.assertEqual(found.func.__name__, self.view.__name__)
def test_get_object(self):
# Testing get_object view method on an EN Post instance
activate(self.EN_LANGUAGE_CODE)
view = self.setup_view(self.view(), **self.en_post_kwargs)
obj = view.get_object()
self.assertEqual(self.en_post, obj)
# Testing get_object view method on an DE Post instance
activate(self.DE_LANGUAGE_CODE)
view = self.setup_view(self.view(), **self.de_post_kwargs)
obj = view.get_object()
self.assertEqual(self.de_post, obj)

View file

@ -1,9 +1,10 @@
from django.conf.urls import url from django.conf.urls import url
from . import views from . import views
from .views import PostDetailViewUngleich
urlpatterns = [ urlpatterns = [
url(r'^$', views.PostListViewUngleich.as_view()), url(r'^$', views.PostListViewUngleich.as_view(), name="post-list"),
# url(r'^$',views.PostListView.as_view()), # url(r'^$',views.PostListView.as_view()),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$', url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$',
views.details) PostDetailViewUngleich.as_view(), name="post-detail")
] ]

View file

@ -1,12 +1,13 @@
from django.conf import settings from django.conf import settings
from django.http import Http404
from django.shortcuts import render from django.shortcuts import render
from django.views.generic import DetailView
from django.utils.translation import get_language from django.utils.translation import get_language
from djangocms_blog.models import Post from djangocms_blog.models import Post
from djangocms_blog.views import PostListView from djangocms_blog.views import PostListView
from djangocms_blog.settings import get_setting from djangocms_blog.settings import get_setting
def blog(request): def blog(request):
posts = Post.objects.all() posts = Post.objects.all()
context = { context = {
@ -41,12 +42,39 @@ class PostListViewUngleich(PostListView):
return queryset return queryset
def details(request, year, month, day, slug): class PostDetailViewUngleich(DetailView):
#should be this way model = Post
language = get_language() template_name = 'ungleich/djangocms_blog/post_detail.html'
#but currently the posts are not trasnlated context_object_name = 'post'
# language = 'en-us' slug_field = 'slug'
post = Post.objects.translated(language, slug=slug).first() slug_url_kwarg = 'slug'
context = {'post': post}
return render(request, 'ungleich/djangocms_blog/post_detail.html', context=context)
def get_object(self, queryset=None):
# Use a custom queryset if provided; this is required for subclasses
# like DateDetailView
language = get_language()
if queryset is None:
queryset = self.get_queryset()
# Next, try looking up by primary key.
pk = self.kwargs.get(self.pk_url_kwarg)
slug = self.kwargs.get(self.slug_url_kwarg)
if pk is not None:
queryset = queryset.filter(pk=pk)
# Next, try looking up by slug.
if slug is not None and (pk is None or self.query_pk_and_slug):
slug_field = self.get_slug_field()
queryset = queryset.translated(language, **{slug_field: slug})
# If none of those are defined, it's an error.
if pk is None and slug is None:
raise AttributeError("Generic detail view %s must be called with "
"either an object pk or a slug."
% self.__class__.__name__)
try:
# Get the single item from the filtered queryset
obj = queryset.first()
except queryset.model.DoesNotExist:
raise Http404(_("No %(verbose_name)s found matching the query") %
{'verbose_name': queryset.model._meta.verbose_name})
return obj

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-09 16:47-0500\n" "POT-Creation-Date: 2016-07-11 22:04-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -159,20 +159,23 @@ msgstr ""
msgid "our services" msgid "our services"
msgstr "Unsere Dienstleistungen" msgstr "Unsere Dienstleistungen"
#: templates/ungleich_page/includes/_services.html:9 #: templates/ungleich_page/includes/_services.html:10
msgid "We support our clients in all areas of Unix infrastructure." msgid "We support our clients in all areas of Unix infrastructure."
msgstr "" msgstr ""
"Wir unterstützen unsere Klienten in allen Bereichen der Unix Infrastruktur."
#: templates/ungleich_page/includes/_services.html:10 #: templates/ungleich_page/includes/_services.html:11
msgid "" msgid ""
"Our top notch configuration management is refreshingly simple and reliable." "Our top notch configuration management is refreshingly simple and reliable."
msgstr "" msgstr ""
"Unser erstklassiges Konfigurationsmanagement ist erfrischend einfach und "
"zuverlässig."
#: templates/ungleich_page/includes/_services.html:18 #: templates/ungleich_page/includes/_services.html:20
msgid "Hosting" msgid "Hosting"
msgstr "Hosting" msgstr "Hosting"
#: templates/ungleich_page/includes/_services.html:20 #: templates/ungleich_page/includes/_services.html:22
msgid "" msgid ""
"Ruby on Rails. Java hosting, Django hosting, we make it everything run " "Ruby on Rails. Java hosting, Django hosting, we make it everything run "
"smooth and safe." "smooth and safe."
@ -180,11 +183,11 @@ msgstr ""
"Ruby on Rails. Java hosting, Django hosting, wir garantieren einen " "Ruby on Rails. Java hosting, Django hosting, wir garantieren einen "
"reibungslosen Ablauf" "reibungslosen Ablauf"
#: templates/ungleich_page/includes/_services.html:28 #: templates/ungleich_page/includes/_services.html:30
msgid "Configuration as a Service" msgid "Configuration as a Service"
msgstr "Konfiguration als Service" msgstr "Konfiguration als Service"
#: templates/ungleich_page/includes/_services.html:30 #: templates/ungleich_page/includes/_services.html:32
msgid "" msgid ""
"Ruby on Rails, Django, Java, Webserver, Mailserver, any infrastructure that " "Ruby on Rails, Django, Java, Webserver, Mailserver, any infrastructure that "
"needs to configured, we provide comprehensive solutions. Amazon, rackspace " "needs to configured, we provide comprehensive solutions. Amazon, rackspace "
@ -194,11 +197,11 @@ msgstr ""
"welche eine Konfiguration braucht, wir offerieren umfassende Lösungen, " "welche eine Konfiguration braucht, wir offerieren umfassende Lösungen, "
"Amazon, Rackspace oder Bare Metal Servers, wir konfigurieren alles." "Amazon, Rackspace oder Bare Metal Servers, wir konfigurieren alles."
#: templates/ungleich_page/includes/_services.html:38 #: templates/ungleich_page/includes/_services.html:40
msgid "Linux System Engineering" msgid "Linux System Engineering"
msgstr "Linux System Engineering" msgstr "Linux System Engineering"
#: templates/ungleich_page/includes/_services.html:41 #: templates/ungleich_page/includes/_services.html:43
msgid "" msgid ""
"Let your developers develop! We take care of your system administration. " "Let your developers develop! We take care of your system administration. "
"Gentoo, Archlinux, Debian, Ubuntu, and many more." "Gentoo, Archlinux, Debian, Ubuntu, and many more."
@ -230,7 +233,7 @@ msgid ""
"\t\t\t engineers to work more efficiently and comfortable\n" "\t\t\t engineers to work more efficiently and comfortable\n"
"\t\t\t than before.\"\n" "\t\t\t than before.\"\n"
"\t\t\t " "\t\t\t "
msgstr "" msgstr "\n ungleich half uns mit unserer internen Infrastruktur, gehostet auf physikalischen Servern, in einer gemeinsamen Unterbringung in einem Datenzentrum in Zürich. Von der Planung des Netzwerk-Layouts und der Virtualisierung der Einrichtung, Offertanfragen und Sicherstellung eines sehr guten Angebots von einem Hardwarelieferanten bis hin zur Installisierung von einfachen Dienstleistungen, wie DNS, VPN und Firewalls durch den Gebrauch der Konfigurationsmanagement-Software cdist, wir konnten auf den Support von ungleich zählen. Am Ende haben wir eine hochverfügbare Infrastruktur-Einrichtung erhalten, welche es unseren Technikern ermöglicht effizienter und bequemer zu arbeiten als zuvor."
#: templates/ungleich_page/includes/_team.html:51 #: templates/ungleich_page/includes/_team.html:51
msgid "" msgid ""
@ -242,7 +245,7 @@ msgid ""
"\t\t\t significantly not only in cost but also in time\n" "\t\t\t significantly not only in cost but also in time\n"
"\t\t\t saving, which is crucial for IT companies like ours.\"\n" "\t\t\t saving, which is crucial for IT companies like ours.\"\n"
"\t\t\t \t" "\t\t\t \t"
msgstr "" msgstr "\n Vielen Dank an das ungleich Team, welches unsere Firmen-Linux-Infrastruktur konfiguriert hat, unsere Systeme sind sehr einfach zu verwalten. Ihr innovatives Konfigurationsmanagement-System cdist half uns signifikant nicht nur in der Kosteneinsparung aber auch zur Zeiteinsparung, was für IT-Firmen sehr wichtig ist."
#: templates/ungleich_page/includes/_team.html:67 #: templates/ungleich_page/includes/_team.html:67
msgid "" msgid ""
@ -259,7 +262,7 @@ msgid ""
"\t\t\t recommend them to any companies with high demand in\n" "\t\t\t recommend them to any companies with high demand in\n"
"\t\t\t solid infrastructures.\"\n" "\t\t\t solid infrastructures.\"\n"
"\t\t\t " "\t\t\t "
msgstr "" msgstr "\n ungleich bietete einen exzellenten Service bei der Gestaltung unserer System-Architektur und erstellte sichere und stabile Geräte. Für uns ist es wichtig eine dauerhafte Stabilität in unserem System zu haben und das Konfigurationsmanagement-System cdist ist sehr einfach zu bedienen für die Systemadministration. Wir hatten eine erfolgreiche Kollaboration mit ungleich während einer Zeit mit einer sehr hohen Arbeitsauslastung und ihre Projektführung war hochqualifiziert und sehr zuverlässig. Ich würde sie allen Firmen empfehlen, bei denen eine solide Infrastruktur stark gefragt ist."
#: templates/ungleich_page/includes/_team.html:82 #: templates/ungleich_page/includes/_team.html:82
msgid "" msgid ""
@ -273,6 +276,32 @@ msgstr ""
msgid "*ungleich means not equal to (≠) U+2260." msgid "*ungleich means not equal to (≠) U+2260."
msgstr "*ungleich bedeutet nicht gleich wie (≠) U+2260." msgstr "*ungleich bedeutet nicht gleich wie (≠) U+2260."
#: templates/ungleich_page/landing.html:85
#, fuzzy
#| msgid "our services"
msgid "Services"
msgstr "Unsere Dienstleistungen"
#: templates/ungleich_page/landing.html:90
msgid "products"
msgstr "PRODUKTE"
#: templates/ungleich_page/landing.html:93
msgid "About"
msgstr "ÜBER"
#: templates/ungleich_page/landing.html:96
msgid "WHY UNGLEICH?"
msgstr "WARUM UNGLEICH?"
#: templates/ungleich_page/landing.html:99
msgid "BLOG"
msgstr "BLOG"
#: templates/ungleich_page/landing.html:102
msgid "CONTACT"
msgstr "KONTAKT"
#: urls.py:8 #: urls.py:8
#, fuzzy #, fuzzy
#| msgid "Contact Us" #| msgid "Contact Us"
@ -287,3 +316,8 @@ msgstr "Nachricht erfolgreich versendet"
msgid "If you have any question, just send us an email." msgid "If you have any question, just send us an email."
msgstr "" msgstr ""
"Wenn Sie irgendwelche Fragen haben, schicken Sie uns einfach eine E-Mail." "Wenn Sie irgendwelche Fragen haben, schicken Sie uns einfach eine E-Mail."
#, fuzzy
#~| msgid "Contact Us"
#~ msgid "Contact"
#~ msgstr "Kontaktieren Sie uns"

View file

@ -48,7 +48,7 @@
</div> </div>
<!-- Footer --><!-- jQuery --> <!-- Footer --><!-- jQuery -->
<script src="js/jquery.js"></script> <script src="{% static 'hosting/js/jquery.js' %}"></script>
<!-- Bootstrap Core JavaScript --> <!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script> <script src="js/bootstrap.min.js"></script>

View file

@ -6,7 +6,10 @@
<div class="row"> <div class="row">
<div class="col-lg-12 text-center wow fadeInDown"> <div class="col-lg-12 text-center wow fadeInDown">
<h2 class="section-heading">{% trans "our services" %}</h2> <h2 class="section-heading">{% trans "our services" %}</h2>
<h3 class="section-subheading text-muted">{% trans "" %}</h3> <h3 class="section-subheading text-muted">
{% trans "We support our clients in all areas of Unix infrastructure." %}<br/>
{% trans "Our top notch configuration management is refreshingly simple and reliable." %}
</h3>
</div> </div>
</div> </div>
<div class="row text-center"> <div class="row text-center">

View file

@ -1,5 +1,6 @@
{% load static %} {% load static %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load i18n %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -81,24 +82,24 @@
<a href="#page-top"></a> <a href="#page-top"></a>
</li> </li>
<li> <li>
<a class="page-scroll" href="#services">services</a></li> <a class="page-scroll" href="#services">{% trans "Services"%}</a></li>
<li></li> <li></li>
<li></li> <li></li>
<li></li> <li></li>
<li> <li>
<a class="page-scroll" href="#portfolio">products</a></li> <a class="page-scroll" href="#portfolio">{% trans "products"%}</a></li>
<li></li> <li></li>
<li> <li>
<a class="page-scroll" href="#about">About</a> <a class="page-scroll" href="#about">{% trans "About"%}</a>
</li> </li>
<li> <li>
<a class="page-scroll" href="#team">WHY UNGLEICH?</a> <a class="page-scroll" href="#team">{% trans "WHY UNGLEICH?"%}</a>
</li> </li>
<li> <li>
<a class="page-scroll" href="http://blog.ungleich.ch">BLOG</a> <a class="page-scroll" href="http://blog.ungleich.ch">{% trans "BLOG"%}</a>
</li> </li>
<li> <li>
<a class="page-scroll" href="#contact">Contact</a> <a class="page-scroll" href="#contact">{% trans "CONTACT"%} </a>
</li> </li>
</ul> </ul>
</div> </div>

View file

@ -81,4 +81,5 @@ class BaseTestCase(TestCase):
view.request = self.request view.request = self.request
view.args = args view.args = args
view.kwargs = kwargs view.kwargs = kwargs
view.config = None
return view return view