As an admin I want to be able to create a custom use. As an user I want to see listed only posts in the current selected language. As an user I want to be able to switch languages between EN-DE

This commit is contained in:
Levi 2016-06-23 21:32:51 -05:00
parent ad035af28c
commit 2b50f9fdd9
7 changed files with 49 additions and 12 deletions

View file

@ -1,9 +1,9 @@
{% load i18n menu_tags %} {% load i18n menu_tags %}
{% if languages|length > 1 %} {% if languages|length > 1 %}
<div class="center-block""> <div class="center-block">
<ul class="list-inline center-block language-chooser-list"> <ul class="list-inline center-block language-chooser-list">
{% for language in languages %} {% for language in languages %}
<li class="lang{% if current_language == language.0 %} active{% endif %}"> <li class="lang{% if current_language == language.0 %} active{% endif %} white">
<a href="{% page_language_url language.0 %}" <a href="{% page_language_url language.0 %}"
title="{% trans "Change to language:" %} {{ language.1 }}">{{ language.1 }}</a> title="{% trans "Change to language:" %} {{ language.1 }}">{{ language.1 }}</a>
</li> </li>

View file

@ -70,7 +70,8 @@ def letscowork(request):
def blog(request): def blog(request):
tags = ["digitalglarus"] tags = ["digitalglarus"]
posts = Post.objects.filter_by_language(get_language()).filter(tags__name__in=tags, publish=True) posts = Post.objects.filter(tags__name__in=tags, publish=True).translated(get_language())
# posts = Post.objects.filter_by_language(get_language()).filter(tags__name__in=tags, publish=True)
context = { context = {
'post_list': posts, 'post_list': posts,
} }

View file

@ -10,7 +10,7 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">
<title>Payment</title> <title>nngleich</title>
<!-- Bootstrap Core CSS --> <!-- Bootstrap Core CSS -->
<link href="{% static 'hosting/css/bootstrap.min.css' %}" rel="stylesheet"> <link href="{% static 'hosting/css/bootstrap.min.css' %}" rel="stylesheet">

View file

@ -1,4 +1,20 @@
from django.contrib import admin from django.contrib import admin
from .models import CustomUser from .models import CustomUser
from django.contrib.auth.hashers import make_password
admin.site.register(CustomUser)
class CustomUserAdmin(admin.ModelAdmin):
fields = ('password', 'user_permissions', 'email', 'is_admin')
def save_model(self, request, obj, form, change):
password = form.cleaned_data.get('password')
if not change:
obj.validation_slug = make_password(None)
obj.set_password(password)
obj.save()
return obj
admin.site.register(CustomUser, CustomUserAdmin)

View file

@ -1,4 +1,4 @@
{% load cms_tags staticfiles %} {% load i18n cms_tags staticfiles menu_tags sekizai_tags %}
<!-- Page Header --> <!-- Page Header -->
<!-- Set your background image for this header on the line below. --> <!-- Set your background image for this header on the line below. -->
<header class="intro-header" <header class="intro-header"
@ -12,11 +12,26 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="site-heading"> <div class="site-heading">
<h1> {% page_attribute 'page_title' %} </h1>
<hr class="small"> {% if languages|length > 1 %}
<span class="subheading"> {% page_attribute 'meta_description' %}</span> <div class="center-block">
</div> <ul class="list-inline center-block language-chooser-list">
{% for language in languages %}
<li class="lang{% if current_language == language.0 %} active{% endif %}">
<a href="{% page_language_url language.0 %}" style="color:white;font-size:16px;"
title="{% trans "Change to language:" %} {{ language.1 }}">{{ language.1 }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
<h1> {% page_attribute 'page_title' %} </h1>
<hr class="small">
<span class="subheading"> {% page_attribute 'meta_description' %}</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -36,10 +36,12 @@
{% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %} {% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %}
</head> </head>
<body> <body>
{% cms_toolbar %} {% cms_toolbar %}
{% show_menu 0 0 0 1 "cms/ungleichch/_menu.html" %} {% show_menu 0 0 0 1 "cms/ungleichch/_menu.html" %}
<!-- body --> <!-- body -->
<!-- Main Content --> <!-- Main Content -->
{% block base_header %} {% block base_header %}
{% include "cms/ungleichch/_header_base.html" %} {% include "cms/ungleichch/_header_base.html" %}
{% endblock %} {% endblock %}

View file

@ -1,3 +1,4 @@
from django.conf import settings
from django.shortcuts import render from django.shortcuts import render
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
@ -8,7 +9,6 @@ from djangocms_blog.settings import get_setting
def blog(request): def blog(request):
posts = Post.objects.all() posts = Post.objects.all()
print(posts)
context = { context = {
'post_list': posts 'post_list': posts
} }
@ -26,6 +26,9 @@ class PostListViewUngleich(PostListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(PostListView, self).get_context_data(**kwargs) context = super(PostListView, self).get_context_data(**kwargs)
context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT') context['TRUNCWORDS_COUNT'] = get_setting('POSTS_LIST_TRUNCWORDS_COUNT')
context['languages'] = settings.LANGUAGES
context['current_language'] = get_language()
return context return context
def get_paginate_by(self, queryset): def get_paginate_by(self, queryset):