Commit f9b52e62 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Remove app news de l'intranet

parent c05ce7c2
# -*- coding: utf-8 -*-
"""Webnews"""
from django.conf import settings
newsgroups_list =[
"^crans\.general$",
"^crans\.crans$",
"^crans\.crans\.annonces$",
"^crans\.tele$",
"^crans\.web-sympas$",
"^crans\.radio-ragots$",
"^crans\.petites-annonces$",
"^crans\.politique$",
"^crans\.culture$",
"^crans\.dino$",
"^crans\.sports$",
"^crans\.stages$",
"^crans\.informatique$",
"^crans\.informatique\..*$",
"^crans\.ratp$",
"^tac\.dpt\..*$",
"^tac\.bde$",
"^tac\.crous$",
"^crans\.cns$",
"^crans\.club\..*$",
"^crans\.test$",
"^tac\.test$",
]
last_news_group = [
"crans.general",
"crans.crans",
"crans.petites-annonces",
]
_DEFAULTS = {
'NEWS_SERVER':"news.crans.org",
'LIST_GROUP': newsgroups_list,
'MESSAGES_BY_PAGE': 25,
'LAST_NEWS_GROUP': last_news_group,
'LAST_NEWS_NUMBER':3,
}
for key,value in list(_DEFAULTS.items()):
try:
getattr(settings, key)
except AttributeError:
setattr(settings, key, value)
# Suppress errors from DJANGO_SETTINGS_MODULE not being set
except ImportError:
pass
from django.contrib import admin
# Register your models here.
news_server = "news.crans.org"
news_by_page = 25
newsgroups_list =[
"^crans\.general$",
"^crans\.crans$",
"^crans\.crans\.annonces$",
"^crans\.tele$",
"^crans\.web-sympas$",
"^crans\.radio-ragots$",
"^crans\.petites-annonces$",
"^crans\.politique$",
"^crans\.culture$",
"^crans\.dino$",
"^crans\.sports$",
"^crans\.stages$",
"^crans\.informatique$",
"^crans\.informatique\..*$",
"^crans\.ratp$",
"^tac\.dpt\..*$",
"^tac\.bde$",
"^tac\.crous$",
"^crans\.cns$",
"^crans\.club\..*$",
"^crans\.test$",
"^tac\.test$",
]
# -*- coding: utf-8 -*-
from django import forms
from news import gestion_nntp
class MessageForm(forms.Form):
groups_choices = [(group, group) for group,_ in gestion_nntp.get_groups_list()]
name = forms.CharField(label="nom")
sender = forms.EmailField(label="adresse")
subject = forms.CharField(label="sujet")
body = forms.CharField(label="message",widget=forms.Textarea(), required=False)
newsgroups = forms.ChoiceField(label="Newsgroups", choices=groups_choices)
class CrossMessageForm(MessageForm):
newsgroups = forms.MultipleChoiceField(label="NewsGroups", choices=MessageForm.groups_choices)
followupto = forms.ChoiceField(label="Followup-To", choices=MessageForm.groups_choices, required=True)
This diff is collapsed.
from django.db import models
# Create your models here.
{% extends "template.html" %}
{% load news_extras %}
{% block title %}WebNews{% endblock %}
{% block h1 %}WebNews{% endblock %}
{% block content %}
<h2>Groupe {{ group }}</h2>
<form class="form-full-width" method="get">
<div class="row">
<div class="four columns">
<a class="button" href="{% url 'news:index' %}">Liste des groupes</a>
</div>
<div class="two columns">
<label for="group_page">Aller à la page :</label>
<select id="group_page" name="group_page">
{% for i in max_page|get_range %}
<option value="{{ i|add:"1" }}">{{ i|add:"1" }}</option>
{% endfor %}
</select>
</div>
<div class="two columns">
<input type="submit" value="Go">
</div>
<div class="four columns">
<a class="button" href="{% url 'news:new_message' group %}">Nouveau message</a>
</div>
</div>
</form>
<nav class="tab">
<ul>
{% if current_page != 1 and current_page != 2 %}
<li><a href="{% url 'news:group' group %}">1</a></li>
<li>...</li>
{% endif %}
{% if current_page > 1 %}
<li><a href="{% url 'news:group' group current_page|add:"-1" %}">{{ current_page|add:"-1" }}</a></li>
{% endif %}
<li>{{ current_page }}</li>
{% if current_page < max_page %}
<li><a href="{% url 'news:group' group current_page|add:"1" %}">{{ current_page|add:"1" }}</a></li>
{% endif %}
{% if current_page != max_page and current_page.number != max_page|add:"-1" %}
<li>...</li>
<li><a href="{% url 'news:group' group max_page %}">{{ max_page }}</a></li>
{% endif %}
</ul>
</nav>
<table class="mobile-friendly">
<thead>
<tr>
<th>Sujet</th>
<th>From</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for message in messages_list %}
<tr>
<td mobile-header=Sujet>{% for i in message.depth|get_range %}
&nbsp;&nbsp;&nbsp;
{% endfor %}
{% if message.depth > 0 %}
<img src="/static/img/webnews_bar_L.gif">&nbsp;
{% endif %}
<a href="{% url 'news:message' group current_page message.message_number %}">
{{ message.subject }}
</a>
</td>
<td mobile-header=From><a href="mailto:{{ message.exp.1 }}">
{% if message.exp.0 != "" %}{{ message.exp.0 }}{% else %}{{ message.exp.1 }}{% endif %}</a></td>
<td mobile-header=Date>{{ message.date }}</td>
</tr>
{% empty %}
<tr>
<td colspan='4'>Aucune news</td>
</tr>
{% endfor %}
</tbody>
</table>
<footer>
<div class="row">
<div class="six columns">
<a class="button" href="{% url 'news:index' %}">Liste des groupes</a>
</div>
</div>
</footer>
{% endblock content %}
{% extends "template.html" %}
{% load news_extras %}
{% block title %}WebNews{% endblock %}
{% block h1 %}WebNews{% endblock %}
{% block content %}
<h2>Les derniers messages</h2>
{% for group, messages in lasts %}
<h3><a href="{% url 'news:group' group %}">{{ group }}</a></h3>
<table class="mobile-friendly">
<thead>
<tr>
<th>Sujet</th>
<th>From</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for message in messages %}
<tr>
<td mobile-header=Sujet>{% for i in message.depth|get_range %}
&nbsp;&nbsp;&nbsp;
{% endfor %}
{% if message.depth > 0 %}
<img src="/static/img/webnews_bar_L.gif">&nbsp;
{% endif %}
<a href="{% url 'news:message' group 1 message.message_number %}">
{{ message.subject }}
</a>
</td>
<td mobile-header=From><a href="mailto:{{ message.exp.1 }}">
{% if message.exp.0 != "" %}{{ message.exp.0 }}{% else %}{{ message.exp.1 }}{% endif %}</a></td>
<td mobile-header=Date>{{ message.date }}</td>
</tr>
{% empty %}
<tr>
<td colspan='4'>Aucune news</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
{% if groups %}
<h2>News Groups</h2>
<table class="mobile-friendly">
<thead>
<tr>
<th>Nom</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% for group,desc in groups %}
<tr>
<td mobile-header="Nom"><a href="{% url 'news:group' group %}">{{ group }}</a></td>
<td mobile-header="Description">{{ desc }}</td>
</tr>
{% endfor %}
</tbody>
{% else %}
<p>No groups are available.</p>
{% endif %}
{% endblock content %}
{% extends "template.html" %}
{% load news_extras %}
{% block title %}WebNews{% endblock %}
{% block h1 %}WebNews{% endblock %}
{% block content %}
<div class="row">
<div class="ten columns">
<a class="button" href="{% url 'news:group' group page %}">Retour à {{ group }}</a>
<a class="button" href="{% url 'news:index' %}">Retour à la liste des newsgroups</a>
<a class="button" href="{% url 'news:source' group page message.message_number %}">Voir les sources</a>
</div>
</div>
<h2>Headers</h2>
<table class="mobile-friendly">
<tbody>
<tr>
<td>Subjet</td>
<td>{{ message.subject }}</td>
</tr>
<tr>
<td>De</td>
<td><a href="mailto:{{ message.exp.1 }}">
{{ message.exp.0 }} &lsaquo;{{ message.exp.1 }}&rsaquo;</a> {% if message.xwebnews %}(depuis le webnews){% endif %}
</td>
</tr>
<tr>
<td>Date</td>
<td>{{ message.date }}</td>
</tr>
<tr>
<td>Newsgroups</td>
<td>
{% for g in message.newsgroups %}
<a href="{% url 'news:group' g %}">{{ g }}</a>
{% endfor %}
</td>
</tr>
{% if message.followupto %}
<tr>
<td>Followup-To</td>
<td><a href="{% url 'news:group' message.followupto %}">{{ message.followupto }}</a></td>
</tr>
{% endif %}
</tbody>
</table>
<h2>Body</h2>
{% for part in message.body %}
<p>
{{ part|urlize|linebreaks }}
</p>
{% endfor %}
{% if message.piece_jointe %}
{% for p in message.piece_jointe %}
{% if p.main_type == "image" %}
<img src="{% url 'news:attachment' group message.message_number p.number %}" alt="attachment number {{ p.number }}">
{% endif %}
{% endfor %}
<h2>Pièces jointes</h2>
<ul>
{% for p in message.piece_jointe %}
<li><a href="{% url 'news:attachment' group message.message_number p.number %}">{{ p.name }}</a></li>
{% endfor%}
</ul>
{% endif %}
<h2>Message récent de cette discussion</h2>
<table class="mobile-friendly">
<thead>
<tr>
<th>Sujet</th>
<th>From</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for family_message in message.family_tree %}
<tr>
<td mobile-header=Sujet>{% for i in family_message.depth|get_range %}
&nbsp;&nbsp;&nbsp;
{% endfor %}
{% if family_message.depth > 0 %}
<img src="/static/img/webnews_bar_L.gif">&nbsp;
{% endif %}
{% if family_message.message_id == message.message_id %}
<b>
{% endif %}
<a href="{% url 'news:message' group page family_message.message_number %}">
{{ family_message.subject }}
</a>
{% if family_message.message_id == message.message_id %}
</b>
{% endif %}
</td>
<td mobile-header=From><a href="mailto:{{ family_message.exp.1 }}">
{% if family_message.exp.0 != "" %}{{ family_message.exp.0 }}{% else %}{{ family_message.exp.1 }}{% endif %}</a></td>
<td mobile-header=Date>{{ family_message.date }}</td>
</tr>
{% empty %}
<tr>
<td colspan='4'>Aucune news</td>
</tr>
{% endfor %}
</tbody>
</table>
<footer>
<div class="row">
<div class="six columns">
<a class="button" href="{% url 'news:group' group page %}">Retour à {{ group }}</a>
</div>
</div>
</footer>
{% endblock %}
{% extends "template.html" %}
{% block title %}WebNews{% endblock %}
{% block h1 %}<h1>Nouveau message dans {{ group }}</h1>{% endblock %}
{% block head %}
<script type="text/javascript" src="/static/js/webnews.js"></script>
{% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Entêtes</h2>
<div class="row">
<div class="four columns">
{{ messageform.name.label_tag }}
{{ messageform.name }}
{{ messageform.name.errors }}
{{ messageform.name.help_text }}
</div>
<div class="four columns">
{{ messageform.sender.label_tag }}
{{ messageform.sender }}
{{ messageform.sender.errors }}
{{ messageform.sender.help_text }}
</div>
<div class="four columns">
{{ messageform.subject.label_tag }}
{{ messageform.subject }}
{{ messageform.subject.errors }}
{{ messageform.subject.help_text }}
</div>
</div>
<div class="row">
<div class="four columns">
{{ messageform.newsgroups.label_tag }}
{{ messageform.newsgroups }}
{{ messageform.newsgroups.errors }}
{{ messageform.newsgroups.help_text }}
</div>
{% if crosspost %}
<div class="four columns">
{{ messageform.followupto.label_tag }}
{{ messageform.followupto }}
{{ messageform.followupto.errors }}
{{ messageform.followupto.help_text }}
</div>
{% endif %}
</div>
<div class="row">
<div class="four columns">
{% if crosspost %}
<input type="submit" name="simplepost" class="button" value="Poster simplement">
{% else %}
<input type="submit" name="crosspost" class="button" value="Cross-Poster">
{% endif %}
</div>
</div>
<h2>Corps</h2>
<div class="row">
<div class="twelve columns">
{{ messageform.body.label_tag }}
{{ messageform.body }}
{{ messageform.body.errors }}
{{ messageform.body.help_text }}
</div>
</div>
<footer>
<input type="submit" {% if crosspost %}name="crosssubmit"{% endif %}name="submit" class="button-add" value="Envoyer">
</footer>
</form>
{% endblock content %}
from django.template import Library
register = Library()
@register.filter
def get_range( value ):
return range( value )
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from news import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<group>[a-zA-Z.\-]+)/$', views.group, name='group'),
url(r'^(?P<group>[a-zA-Z.\-]+)/newmessage$', views.new_message, name='new_message'),
url(r'^(?P<group>[a-zA-Z.\-]+)/page(?P<page>[0-9]+)/$', views.group, name='group'),
url(r'^(?P<group>[a-zA-Z.\-]+)/page(?P<page>[0-9]+)/(?P<message_number>[0-9]+)/$', views.message, name='message'),
url(r'^(?P<group>[a-zA-Z.\-]+)/page([0-9]+)/(?P<message_number>[0-9]+)/source/$', views.source, name='source',),
url(r'^(?P<group>[a-zA-Z.\-]+)/page[0-9]+/(?P<message_number>[0-9]+)/attachment(?P<attachment>[0-9]+)$', views.attachment, name='attachment'),
]
# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from news import gestion_nntp
from forms import MessageForm, CrossMessageForm
# Traite correctement les erreurs renvoyées par gestion_nntp
def handle_nntp_exception(func):
def _decorected(request, *args, **kwargs):
try:
return func(request, *args, **kwargs)
except gestion_nntp.ConnexionError as e:
messages.error(request, u"Impossible de se connecter au serveur de news : %s" % e.server_name)
return redirect("index", permanent=False)
except gestion_nntp.GroupError as e:
messages.error(request, u"Group \"%s\" does not exist on this server." % e.group_name)
return redirect("news:index", permanent=False)
except gestion_nntp.MessageError as e:
messages.error(request, u"Article number %s does not exist in the group \"%s\"." % (e.message_number, e.group_name))
return redirect("news:group", permanent=False, group=e.group_name)
except gestion_nntp.PageError as e:
messages.error(request, u"Numéro de page invalide \"%i\"" % e.page_number)
return redirect("news:group", permanent=False, group=e.group_name)
except gestion_nntp.SendError as e:
messages.error(request, u"Erreur pendant l'envoie du message : \"%s\"" % e.message_error)
return redirect("news:index", permanent=False,)
return _decorected
def restricted_access(func):
def _decorected(request, *args, **kwargs):
if not request.user.has_perm('auth.crans_cableur'):
messages.error(request, u""" Accès interdit, droits insuffisants """ )
return HttpResponseRedirect("/")
return func(request, *args, **kwargs)
return _decorected
# Afficher les différents newsgroups, les news groups à afficher sont configurable
# dans settings.py en définissant NEWS_SERVER
@restricted_access
@login_required
@handle_nntp_exception
def index(request):
groups = gestion_nntp.get_groups_list()
lasts = gestion_nntp.get_last_messages()
return render(request, "news/index.html", {"groups":groups,
"lasts":lasts,})
@restricted_access
@login_required
@handle_nntp_exception
def group(request, group, page=1):
# Si la page est dans le get on redirige
if "group_page" in request.GET:
if request.GET["group_page"].isdigit:
return redirect("news:group", permanent=False, group=group, page=int(request.GET["group_page"]))
page = int(page)
(max_page, messages_list) = gestion_nntp.get_messages_list(group, page)
return render(request, "news/group.html", {"messages_list":messages_list,
"current_page":page,
"max_page": max_page,
"group":group,})
@restricted_access
@login_required
@handle_nntp_exception
def message(request, group, page, message_number):
return render(request, "news/message.html", {"message":gestion_nntp.get_message(group, message_number),
"group":group,
"page":page})
@restricted_access
@login_required
@handle_nntp_exception
def source(request, group, message_number):
source = gestion_nntp.get_raw_message(group, message_number)
response = HttpResponse(source,content_type="txt")
response['Content-Disposition'] = 'inline'
return response
@restricted_access
@login_required
@handle_nntp_exception
def attachment(request, group, message_number, attachment):
part = gestion_nntp.get_attachment(group, message_number, int(attachment))
response = HttpResponse(part.get_payload(decode=True),content_type=part.get_content_type())
response['Content-Disposition'] = 'inline; filename="%s"' % part.get_filename()
return response
@restricted_access
@login_required
@handle_nntp_exception
def new_message(request, group):
if request.method == "POST":
if "crosspost" in request.POST:
messageform = CrossMessageForm(initial={"newsgroups":(request.POST["newsgroups"],),
"followupto":request.POST["newsgroups"], "name":request.POST["name"],
"sender":request.POST["sender"], "subject":request.POST["subject"],
"body":request.POST["body"]})
context = {"group":group, "messageform":messageform, "crosspost":True}
return render(request, "news/new_message.html", context)
elif "simplepost" in request.POST:
messageform = MessageForm(initial={"newsgroups":request.POST["newsgroups"],
"name":request.POST["name"], "sender":request.POST["sender"],
"subject":request.POST["subject"], "body":request.POST["body"]})
context = {"group":group, "messageform":messageform, "crosspost":False}
return render(request, "news/new_message.html", context)
crosspost = "crosssubmit" in request.POST
if crosspost:
messageform = CrossMessageForm(request.POST)
else:
messageform = MessageForm(request.POST)
if messageform.is_valid():
subject = messageform.cleaned_data["subject"]
name = messageform.cleaned_data["name"]
sender = messageform.cleaned_data["sender"]
body = messageform.cleaned_data["body"]
if crosspost:
newsgroups = messageform.cleaned_data["newsgroups"]
else:
newsgroups= [messageform.cleaned_data["newsgroups"]]
messages.success(request, "Message envoyé")
return redirect("news:group", permanent=False, group=newsgroups[0])
else:
context = {"group":group, "messageform":messageform}
return render(request, "news/new_message.html", context)
else:
messageform = MessageForm(initial={"newsgroups":group})
context = {"group":group, "messageform":messageform, "crosspost":False}
return render(request, "news/new_message.html", context)
Markdown is supported
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