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 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 resolve
from django.contrib.auth.tokens import default_token_generator
@ -115,7 +115,7 @@ class HostingPricingViewTest(TestCase):
found = resolve(self.url)
self.assertEqual(found.func.__name__, self.view.__name__)
def get(self):
def test_get(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.view.get_context_data(), self.expected_context)

View file

@ -17,13 +17,13 @@
Posted
{% if post.author %}
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 %}
{{ post.author.get_full_name }}
{% else %}
{{ post.author }}
{% endif %}
</a>
<!-- </a> -->
{% endif %}
on {{ post.date_published|date:"DATE_FORMAT" }}
</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 . import views
from .views import PostDetailViewUngleich
urlpatterns = [
url(r'^$', views.PostListViewUngleich.as_view()),
url(r'^$', views.PostListViewUngleich.as_view(), name="post-list"),
# 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]*)/$',
views.details)
PostDetailViewUngleich.as_view(), name="post-detail")
]

View file

@ -1,12 +1,13 @@
from django.conf import settings
from django.http import Http404
from django.shortcuts import render
from django.views.generic import DetailView
from django.utils.translation import get_language
from djangocms_blog.models import Post
from djangocms_blog.views import PostListView
from djangocms_blog.settings import get_setting
def blog(request):
posts = Post.objects.all()
context = {
@ -41,12 +42,39 @@ class PostListViewUngleich(PostListView):
return queryset
def details(request, year, month, day, slug):
#should be this way
language = get_language()
#but currently the posts are not trasnlated
# language = 'en-us'
post = Post.objects.translated(language, slug=slug).first()
context = {'post': post}
return render(request, 'ungleich/djangocms_blog/post_detail.html', context=context)
class PostDetailViewUngleich(DetailView):
model = Post
template_name = 'ungleich/djangocms_blog/post_detail.html'
context_object_name = 'post'
slug_field = 'slug'
slug_url_kwarg = 'slug'
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 ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -159,20 +159,23 @@ msgstr ""
msgid "our services"
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."
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 ""
"Our top notch configuration management is refreshingly simple and reliable."
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"
msgstr "Hosting"
#: templates/ungleich_page/includes/_services.html:20
#: templates/ungleich_page/includes/_services.html:22
msgid ""
"Ruby on Rails. Java hosting, Django hosting, we make it everything run "
"smooth and safe."
@ -180,11 +183,11 @@ msgstr ""
"Ruby on Rails. Java hosting, Django hosting, wir garantieren einen "
"reibungslosen Ablauf"
#: templates/ungleich_page/includes/_services.html:28
#: templates/ungleich_page/includes/_services.html:30
msgid "Configuration as a Service"
msgstr "Konfiguration als Service"
#: templates/ungleich_page/includes/_services.html:30
#: templates/ungleich_page/includes/_services.html:32
msgid ""
"Ruby on Rails, Django, Java, Webserver, Mailserver, any infrastructure that "
"needs to configured, we provide comprehensive solutions. Amazon, rackspace "
@ -194,11 +197,11 @@ msgstr ""
"welche eine Konfiguration braucht, wir offerieren umfassende Lösungen, "
"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"
msgstr "Linux System Engineering"
#: templates/ungleich_page/includes/_services.html:41
#: templates/ungleich_page/includes/_services.html:43
msgid ""
"Let your developers develop! We take care of your system administration. "
"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 than before.\"\n"
"\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
msgid ""
@ -242,7 +245,7 @@ msgid ""
"\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 \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
msgid ""
@ -259,7 +262,7 @@ msgid ""
"\t\t\t recommend them to any companies with high demand in\n"
"\t\t\t solid infrastructures.\"\n"
"\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
msgid ""
@ -273,6 +276,32 @@ msgstr ""
msgid "*ungleich means not equal to (≠) 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
#, fuzzy
#| msgid "Contact Us"
@ -287,3 +316,8 @@ msgstr "Nachricht erfolgreich versendet"
msgid "If you have any question, just send us an email."
msgstr ""
"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>
<!-- Footer --><!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="{% static 'hosting/js/jquery.js' %}"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>

View file

@ -6,7 +6,10 @@
<div class="row">
<div class="col-lg-12 text-center wow fadeInDown">
<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 class="row text-center">

View file

@ -1,5 +1,6 @@
{% load static %}
{% load bootstrap3 %}
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
@ -81,24 +82,24 @@
<a href="#page-top"></a>
</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>
<a class="page-scroll" href="#portfolio">products</a></li>
<a class="page-scroll" href="#portfolio">{% trans "products"%}</a></li>
<li></li>
<li>
<a class="page-scroll" href="#about">About</a>
<a class="page-scroll" href="#about">{% trans "About"%}</a>
</li>
<li>
<a class="page-scroll" href="#team">WHY UNGLEICH?</a>
<a class="page-scroll" href="#team">{% trans "WHY UNGLEICH?"%}</a>
</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>
<a class="page-scroll" href="#contact">Contact</a>
<a class="page-scroll" href="#contact">{% trans "CONTACT"%} </a>
</li>
</ul>
</div>

View file

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