Add output language support

This commit is contained in:
Gregory Soutade 2022-10-08 16:08:02 +02:00
parent c5744585c7
commit 27bd360abe
9 changed files with 31 additions and 11 deletions

View File

@ -19,6 +19,7 @@
"""
from django.contrib.auth.models import User
from dynastie.models import Language
class UserProfile(models.Model):
# This field is required.
@ -26,3 +27,6 @@ class UserProfile(models.Model):
# Other fields here
editor = models.CharField(max_length=20, default="TinyMCE")
default_language = models.ForeignKey(Language, on_delete=models.CASCADE)

View File

@ -38,6 +38,7 @@ class PostForm(ModelForm):
def __init__(self, *args, **kwargs):
super(PostForm, self).__init__(*args, **kwargs)
self.fields['category'].choices = [(cat.id, cat.name) for cat in Category.objects.all()]
self.fields['language'].choices = [(lang.id, lang.name) for lang in Language.objects.all()]
class DraftForm(PostForm):
class Meta:

View File

@ -319,6 +319,9 @@ class Index(DynastieGenerator):
except:
pass
if post.language != None:
post_elem.setAttribute('lang', post.language.abbrev)
self.parent_posts = []
post_content = self._loadPostContent(post)
if not post_content: return None

View File

@ -134,6 +134,12 @@ class Post(Index):
new_elem = self.createMeta(dom, name, post.author.first_name + ' ' + post.author.last_name)
except:
return None
elif name == 'lang':
meta_elem.removeChild(root)
# Add attribute lang in <html> tag
if post.language != None:
meta_elem.parentNode.setAttribute('lang', post.language.abbrev)
return None
if not new_elem is None:
root.parentNode.replaceChild(new_elem, root)

View File

@ -41,6 +41,10 @@ def slugify(name):
name = sub('-+', '-', name)
return name
class Language(models.Model):
name = models.CharField(max_length=255, unique=True)
abbrev = models.CharField(max_length=4, unique=True)
class Blog(models.Model):
name = models.CharField(max_length=255, unique=True)
title = models.CharField(max_length=255)
@ -281,12 +285,13 @@ class Post(models.Model):
keywords = models.TextField(blank=True)
tags = models.ManyToManyField(Tag, blank=True, null=True)
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
language = models.ForeignKey(Language, null=True, on_delete=models.CASCADE)
CONTENT_HTML = 0
CONTENT_TEXT = 1
CONTENT_FORMAT = (
(CONTENT_HTML, 'HTML'),
(CONTENT_TEXT, 'Text'))
content_format = models.IntegerField(choices=CONTENT_FORMAT, default=CONTENT_HTML, blank=False, null=False)
content_format = models.IntegerField(choices=CONTENT_FORMAT, default=CONTENT_TEXT, blank=False, null=False)
post_type = models.CharField(max_length=1, default='P')
def getPath(self):

View File

@ -1,4 +1,4 @@
<html xmlns:dyn="http://indefero.soutade.fr/p/dynastie" xmlns="http://www.w3.org/1999/xhtml">
<html xmlns:dyn="http://indefero.soutade.fr/p/dynastie" xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<meta content="index, follow" name="robots"/>
@ -35,7 +35,7 @@
<img id="hamburger_logo" alt="Menu" src="/images/hamburger.png"/>
</a>
</div>
<div class="menu" id="menu">
<div class="menu" id="menu" lang="fr">
<div class="menu_content">
<div class="menu_content_header">Recherche</div>
<div class="menu_main">

View File

@ -6,6 +6,7 @@
<dyn:meta name="keywords"/>
<dyn:meta name="title"/>
<dyn:meta name="author"/>
<dyn:meta name="lang"/>
<meta content="Dynastie" name="generator"/>
<meta name="viewport" content="width=width, initial-scale=1"/>
<title>Blog de Grégory Soutadé</title>
@ -36,7 +37,7 @@
<img id="hamburger_logo" alt="Menu" src="/images/hamburger.png"/>
</a>
</div>
<div class="menu" id="menu">
<div class="menu" id="menu" lang="fr">
<div class="menu_content">
<div class="menu_content_header">Recherche</div>
<div class="menu_main">

View File

@ -23,16 +23,16 @@
<dyn:comment_content/>
<dyn:replace div_name="a" href="javascript:void(0);" onClick="javascript:display('response_dyn:comment_index');">Répondre</dyn:replace><br/>
<dyn:replace div_name="form" id="response_dyn:comment_index" class="response" method="POST" action="/comment/add/dyn:post_id/dyn:comment_id" onsubmit="return validateComment('response_dyn:comment_index');">
Auteur :<br/><input type="required" name="author"/><br/><br/>
Auteur :<br/><input required="1" name="author"/><br/><br/>
e-mail* :<br/><input id="email" type="email" name="email"/><input type="email" name="mel"/><br/><br/>
Le commentaire :<br/><textarea type="required" name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
Le commentaire :<br/><textarea required="1" name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
<input type="submit" value="Commenter"/>
</dyn:replace>
</dyn:comments>
<dyn:replace div_name="form" id="response_0" method="POST" action="/comment/add/dyn:post_id/0" onsubmit="return validateComment('response_0');">
Auteur :<br/><input type="required" name="author"/><br/><br/>
Auteur :<br/><input required="1" name="author"/><br/><br/>
e-mail* :<br/><input id="email" type="email" name="email"/><input type="email" name="mel"/><br/><br/>
Le commentaire :<br/><textarea type="required" name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
Le commentaire :<br/><textarea required="1" name="the_comment" cols="80" rows="10"> </textarea><br/><br/>
<input type="submit" value="Commenter"/><br/><br/>
* Seulement pour être notifié d'une réponse à cet article
</dyn:replace>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<meta content="index, follow" name="robots"/>