Commit 239ff2c9 authored by Conv Troll's avatar Conv Troll
Browse files

Rework for 25th edition

parents
from django.db import models
from django.contrib import admin
from markdownx.models import MarkdownxField
from markdownx.widgets import AdminMarkdownxWidget
from ordered_model.admin import OrderedModelAdmin
from .models import Article, Page
class ArticleAdmin(admin.ModelAdmin):
formfield_overrides = {
MarkdownxField: {'widget': AdminMarkdownxWidget},
}
list_display = ('title', 'published', 'date')
# list_editable = ('title', 'published')
ordering = ('-date', )
search_fields = ['title', 'content', 'date']
class PageAdmin(OrderedModelAdmin):
formfield_overrides = {
MarkdownxField: {'widget': AdminMarkdownxWidget},
}
list_display = ('title', 'published', 'date', 'move_up_down_links')
# list_editable = ('title', 'published')
search_fields = ['title', 'content', 'date']
admin.site.register(Article, ArticleAdmin)
admin.site.register(Page, PageAdmin)
from django.apps import AppConfig
class BlogConfig(AppConfig):
name = 'blog'
# Generated by Django 2.1.5 on 2019-01-28 17:37
from django.db import migrations, models
import markdownx.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, verbose_name='Titre')),
('slug', models.SlugField(editable=False, max_length=150, unique=True)),
('content', markdownx.models.MarkdownxField(verbose_name='Contenu')),
('published', models.BooleanField(default=False, verbose_name='Publication')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Date de parution')),
],
),
migrations.CreateModel(
name='Page',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order', models.PositiveIntegerField(db_index=True, editable=False, verbose_name='order')),
('title', models.CharField(max_length=100, verbose_name='Titre')),
('slug', models.SlugField(editable=False, max_length=150, unique=True)),
('content', markdownx.models.MarkdownxField(verbose_name='Contenu')),
('published', models.BooleanField(default=False, verbose_name='Publication')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Date de parution')),
],
options={
'ordering': ('order',),
'abstract': False,
},
),
]
import re
from django.template.defaultfilters import slugify
def unique_slugify(instance, value, slug_field_name='slug', queryset=None,
slug_separator='-'):
"""
Calculates and stores a unique slug of ``value`` for an instance.
``slug_field_name`` should be a string matching the name of the field to
store the slug in (and the field to check against for uniqueness).
``queryset`` usually doesn't need to be explicitly provided - it'll default
to using the ``.all()`` queryset from the model's default manager.
"""
slug_field = instance._meta.get_field(slug_field_name)
slug = getattr(instance, slug_field.attname)
slug_len = slug_field.max_length
# Sort out the initial slug, limiting its length if necessary.
slug = slugify(value)
if slug_len:
slug = slug[:slug_len]
slug = _slug_strip(slug, slug_separator)
original_slug = slug
# Create the queryset if one wasn't explicitly provided and exclude the
# current instance from the queryset.
if queryset is None:
queryset = instance.__class__._default_manager.all()
if instance.pk:
queryset = queryset.exclude(pk=instance.pk)
# Find a unique slug. If one matches, at '-2' to the end and try again
# (then '-3', etc).
next = 2
while not slug or queryset.filter(**{slug_field_name: slug}):
slug = original_slug
end = '%s%s' % (slug_separator, next)
if slug_len and len(slug) + len(end) > slug_len:
slug = slug[:slug_len-len(end)]
slug = _slug_strip(slug, slug_separator)
slug = '%s%s' % (slug, end)
next += 1
setattr(instance, slug_field.attname, slug)
def _slug_strip(value, separator='-'):
"""
Cleans up a slug by removing slug separator characters that occur at the
beginning or end of a slug.
If an alternate separator is used, it will also replace any instances of
the default '-' separator with the new separator.
"""
separator = separator or ''
if separator == '-' or not separator:
re_sep = '-'
else:
re_sep = '(?:-|%s)' % re.escape(separator)
# Remove multiple instances and if an alternate separator is provided,
# replace the default '-' separator.
if separator != re_sep:
value = re.sub('%s+' % re_sep, separator, value)
# Remove separator from the beginning and end of the slug.
if separator:
if separator != '-':
re_sep = re.escape(separator)
value = re.sub(r'^%s+|%s+$' % (re_sep, re_sep), '', value)
return value
\ No newline at end of file
{% load staticfiles %}
{% load set_var %}
<!DOCTYPE html>
<html lang="fr">
<head>
<title>XXVe Convention du Troll Penché</title>
<meta charset="utf-8">
<link href="{% static "blog/css/style.css" %}" rel="stylesheet">
<link rel="stylesheet" href="{% static "blog/css/font-awesome.css" %}">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="{% static "blog/js/countdown.js" %}"></script>
</head>
<body>
{% include "blog/nav.html" %}
{% block body %}
{% endblock %}
{% include "blog/footer.html" %}
</body>
</html>
{% extends "BaseBlog.html" %}
{% load markdown_deux_tags %}
{% block body %}
<br><br>
<h2 class="titre-principal">{{article.title}}</h2>
<article>{{article.content|markdown:"trusted"}}</article>
{% endblock %}
{% extends "BaseBlog.html" %}
{% load markdown_deux_tags %}
{% load static %}
{% block body %}
<header>
<img src="{% static "blog/img/affiche.jpg" %}"/>
<!-- Timer -->
{# <div id="gala-countdown" class="countdown d-flex flex-wrap align-items-center justify-content-between"></div> #}
<!-- /Timer -->
</header>
<div id="header-ghost">
</div>
<div id="articles">
<h1 align="center">News</h1>
{% for article in articles %}
<hr>
<div class="article">
<a href="{{article.get_absolute_url}}">
<h2>{{article.title|title}}</h2>
</a>
<div class="article-preview">{{article.content|markdown:"trusted"}}</div>
</div>
{% endfor %}
</div>
{% endblock %}
<div class="row">
<div class="row">
<div class="col-lg-offset-2 col-lg-8 col-lg-offset-2">
<div class="chronoBloc chrono">
<div align="center" class="row">
<i>J-<span class="days">0</span></i>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
<!-- Footer -->
<footer class="text-center">
<a class="up-arrow" href="#top" data-toggle="tooltip" data-placement="top" title="TO TOP">
<i class="fa fa-2x fa-angle-up" aria-hidden="true"></i>
</a>
<div class="social-icons">
<a class="facebook" href="https://www.facebook.com/ConvTroll"><i class="fa fa-facebook"></i></a>
<a class="twitter" href="https://twitter.com/convtroll"><i class="fa fa-twitter"></i></a>
{# <a class="youtube" href="https://www.youtube.com/channel/UC3xXQkDoDNigyeOg1nvwl9g"><i class="fa fa-youtube"></i></a> #}
</div>
<p class="credit"><a href="http://sene.ovh" data-toggle="tooltip" title="https://sene.ovh">Victor SENE</a> -- Paul TREHIOU -- <a href="https://klmp200.net" data-toogle="tooltip" title="https://klmp200.net">Antoine BARTUCCIO</a> --  <a href="https://krophil.fr" data-toogle="tooltip" title="https://krophil.fr">Pierre BRUNET</a> -- Nicolas Ballet</p>
<p class="github"><a href="https://ae-dev.utbm.fr/sli/site-conv">Github</a></p>
</footer>
{% load staticfiles %}
{% load set_var %}
<nav>
<a class="navbar-brand" href="../"><img src="{% static "blog/img/troll-cyberpunk.png" %}" /></a>
<ul>
{% for page in nav.pages %}
{% set active = "" %}
{% if nav.path == page.get_absolute_url %}
{% set active = "active" %}
{% endif %}
<li class="{{active}} nav-item"><a class="nav-link" href="{{page.get_absolute_url}}">{{page.title}}</a></li>
{% endfor %}
</ul>
</nav>
{% extends "BaseBlog.html" %}
{% load markdown_deux_tags %}
{% block body %}
<div id="articles">
<h1 class="titre-principal">{{content.title}}</h1>
<article>{{content.content|markdown:"trusted"}}</article>
</div>
</div>
{% endblock %}
from django import template
register = template.Library()
class SetVarNode(template.Node):
def __init__(self, var_name, var_value):
self.var_name = var_name
self.var_value = var_value
def render(self, context):
try:
value = template.Variable(self.var_value).resolve(context)
except template.VariableDoesNotExist:
value = ""
context[self.var_name] = value
return u""
def set_var(parser, token):
"""
{% set <var_name> = <var_value> %}
"""
parts = token.split_contents()
if len(parts) < 4:
raise template.TemplateSyntaxError("'set' tag must be of the form: {% set <var_name> = <var_value> %}")
return SetVarNode(parts[1], parts[3])
register.tag('set', set_var)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment