diff --git a/hosting/test_views.py b/hosting/test_views.py index 99bc0427..c3777840 100644 --- a/hosting/test_views.py +++ b/hosting/test_views.py @@ -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) diff --git a/ungleich/templates/ungleich/djangocms_blog/includes/blog_item.html b/ungleich/templates/ungleich/djangocms_blog/includes/blog_item.html index 0ec8535a..50c1b0ce 100644 --- a/ungleich/templates/ungleich/djangocms_blog/includes/blog_item.html +++ b/ungleich/templates/ungleich/djangocms_blog/includes/blog_item.html @@ -17,13 +17,13 @@ Posted {% if post.author %} by - + {% if post.author.get_full_name %} {{ post.author.get_full_name }} {% else %} {{ post.author }} {% endif %} - + {% endif %} on {{ post.date_published|date:"DATE_FORMAT" }}

diff --git a/ungleich/test_views.py b/ungleich/test_views.py new file mode 100644 index 00000000..09375894 --- /dev/null +++ b/ungleich/test_views.py @@ -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) diff --git a/ungleich/urls.py b/ungleich/urls.py index afdef4de..e833f03d 100644 --- a/ungleich/urls.py +++ b/ungleich/urls.py @@ -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\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', - views.details) + PostDetailViewUngleich.as_view(), name="post-detail") ] diff --git a/ungleich/views.py b/ungleich/views.py index 5e829693..8f73a8cb 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -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 diff --git a/ungleich_page/locale/de/LC_MESSAGES/django.mo b/ungleich_page/locale/de/LC_MESSAGES/django.mo index b44e0c32..4af4e241 100644 Binary files a/ungleich_page/locale/de/LC_MESSAGES/django.mo and b/ungleich_page/locale/de/LC_MESSAGES/django.mo differ diff --git a/ungleich_page/locale/de/LC_MESSAGES/django.po b/ungleich_page/locale/de/LC_MESSAGES/django.po index f8b938ce..a34ca6e6 100644 --- a/ungleich_page/locale/de/LC_MESSAGES/django.po +++ b/ungleich_page/locale/de/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \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" diff --git a/ungleich_page/templates/ungleich_page/404.html b/ungleich_page/templates/ungleich_page/404.html index c3cd260d..4d817937 100644 --- a/ungleich_page/templates/ungleich_page/404.html +++ b/ungleich_page/templates/ungleich_page/404.html @@ -48,7 +48,7 @@ - + diff --git a/ungleich_page/templates/ungleich_page/includes/_services.html b/ungleich_page/templates/ungleich_page/includes/_services.html index d07e1336..5a0ef848 100644 --- a/ungleich_page/templates/ungleich_page/includes/_services.html +++ b/ungleich_page/templates/ungleich_page/includes/_services.html @@ -6,7 +6,10 @@

{% trans "our services" %}

-

{% trans "" %}

+

+ {% trans "We support our clients in all areas of Unix infrastructure." %}
+ {% trans "Our top notch configuration management is refreshingly simple and reliable." %} +

diff --git a/ungleich_page/templates/ungleich_page/landing.html b/ungleich_page/templates/ungleich_page/landing.html index 59bb8fd3..0eaf0a2c 100644 --- a/ungleich_page/templates/ungleich_page/landing.html +++ b/ungleich_page/templates/ungleich_page/landing.html @@ -1,5 +1,6 @@ {% load static %} {% load bootstrap3 %} +{% load i18n %} @@ -81,24 +82,24 @@
  • - services
  • + {% trans "Services"%}
  • - products
  • + {% trans "products"%}
  • - About + {% trans "About"%}
  • - WHY UNGLEICH? + {% trans "WHY UNGLEICH?"%}
  • - BLOG + {% trans "BLOG"%}
  • - Contact + {% trans "CONTACT"%}
  • diff --git a/utils/tests.py b/utils/tests.py index 42831050..d40f2c40 100644 --- a/utils/tests.py +++ b/utils/tests.py @@ -81,4 +81,5 @@ class BaseTestCase(TestCase): view.request = self.request view.args = args view.kwargs = kwargs + view.config = None return view