Commit 78cfd8f3 authored by Calcul Bot's avatar Calcul Bot
Browse files

Updating scripts.

parent 05642c40
import datetime
import gitlab
import os
import re
import cgi
# General configuration
gitlab_url = "https://gitlab.math.unistra.fr"
......@@ -46,13 +48,24 @@ class JobOffer(object):
def __str__(self):
return job_offer_to_markdown(self)
def escape_markdown(text, replace_newline=None):
""" Escapes all special characters of HTML and Markdown syntax. """
text = cgi.escape(text)
if replace_newline is not None:
text = re.sub('[\r\n]+', replace_newline, text)
return re.sub('([' + re.escape(r'\`*_{}[]()#>+-.!') + '])', r'\\\1', text)
def job_offer_to_markdown(job_offer, attachment=None, slug=None):
""" Formats a job offer to a Markdown file. """
if attachment is None:
attachment = job_offer.attachment
if attachment is not None and job_offer.has_attachment():
attachment_md = "[attachment]({{filename}}{})".format(attachment)
attachment_md = "[attachment]({{filename}}{})".format(espace_markdown(attachment, ''))
else:
attachment_md = ''
......@@ -62,11 +75,11 @@ def job_offer_to_markdown(job_offer, attachment=None, slug=None):
slug_md = ''
return (
"Title: {}\n".format(job_offer.title) +
"Title: {}\n".format(escape_markdown(job_offer.title, ', ')) +
"Date: {}\n".format(job_offer.date.strftime('%Y-%m-%d %H:%M')) +
slug_md +
"\n" +
"{}\n".format(job_offer.description) +
"{}\n".format(escape_markdown(job_offer.description)) +
attachment_md
)
......@@ -77,8 +90,6 @@ def create_job_request(gl, job_offer):
TODO: generates job id in this function.
"""
# TODO: html and pelican special chars
# Generating job id
job_id = gen_job_id(job_offer)
base_name = 'job_{}'.format(job_id)
......
......@@ -12,13 +12,12 @@
$title = $contact_name = $email = $website = $description = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Extract and cleaning parameters
// TODO: trim
$contact_name = $_POST["contact_name"];
$email = $_POST["email"];
$website = $_POST["website"];
$title = $_POST["title"];
$description = $_POST["description"];
// Extracting and cleaning parameters
$contact_name = trim($_POST["contact_name"]);
$email = trim($_POST["email"]);
$website = trim($_POST["website"]);
$title = trim($_POST["title"]);
$description = trim($_POST["description"]);
// Checking parameters validity
// TODO
......@@ -42,8 +41,6 @@
$cmd_line .= ' --attachment ' . escapeshellarg($_FILES['file']['tmp_name']);
$cmd_line .= ' --attachment_ext ' . escapeshellarg($attachment_ext);
// TODO: quid des caractères spéciaux Pelican dans le nom de fichier ?! Dans le script python ?
// TODO: tout échapper mardown & html dans python !
}
......@@ -52,7 +49,7 @@
// DEBUG
echo '<p>Command line: ' . htmlspecialchars($cmd_line) . '</p><br>';
echo '<p>Output: ' . htmlspecialchars(join('<br>', $output)) . '</p><br>';
echo '<p>Output: ' . join('<br>', array_map("htmlspecialchars", $output)) . '</p><br>';
echo '<p>Return code: ' . htmlspecialchars($return_var) . '</p><br>';
// Checking return code or/and output
......
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