Commit 6d1309cd authored by Calcul Bot's avatar Calcul Bot
Browse files

Tests

parent d81ed0ad
......@@ -26,17 +26,6 @@ class JobOffer(object):
def __hash__(self):
return hash((self.title, self.description, self.date))
def to_markdown(self, attachment_stored_name=None):
attachment_md = "[attachment]({{filename}}{})".format(attachment_stored_name) if attachment_stored_name is not None and self.has_attachment() else ''
return (
"Title: {}\n".format(self.title) +
"Date: {}\n".format(self.date.strftime('%Y-%m-%d %H:%M')) +
"\n" +
"{}\n".format(self.description) +
attachment_md
)
def has_attachment(self):
return self.attachment is not None
......@@ -49,7 +38,32 @@ class JobOffer(object):
return fh.read()
def __str__(self):
return self.to_markdown()
return job_offer_to_markdown(self)
def job_offer_to_markdown(job_offer, attachment=None, slug=None):
if attachment is None:
attachment = job_offer.attachment
if attachment is not None and job_offer.has_attachment():
attachment_md = "[attachment]({{filename}}{})".format(attachment)
else:
attachment_md = ''
if slug is not None:
slug_md = "Slug: {}\n".format(slug)
else:
slug_md = ''
return (
"Title: {}\n".format(job_offer.title) +
"Date: {}\n".format(job_offer.date.strftime('%Y-%m-%d %H:%M')) +
slug_md +
"\n" +
"{}\n".format(job_offer.description) +
attachment_md
)
def create_job_request(gl, job_offer):
""" Creates a merge request for the given job offer.
......@@ -59,13 +73,14 @@ def create_job_request(gl, job_offer):
# Generating job id
job_id = gen_job_id(job_offer)
branch_name = 'job_{}'.format(job_id)
job_name = 'job_{}.md'.format(job_id)
base_name = 'job_{}'.format(job_id)
branch_name = base_name
job_name = '{}.md'.format(base_name)
if job_offer.has_attachment():
attachment_name = 'job_{}_attachment{}'.format(job_id, job_offer.get_attachment_extension())
attachment = '{}_attachment{}'.format(base_name, job_offer.get_attachment_extension())
else:
attachment_name = None
attachment = None
# Accessing project
project = gl.projects.get(gitlab_source_id)
......@@ -81,7 +96,7 @@ def create_job_request(gl, job_offer):
{
"action" : "create",
"file_path" : "content/job_offers/{}".format(job_name),
"content" : job_offer.to_markdown(attachment_name)
"content" : job_offer_to_markdown(job_offer, attachment, base_name)
}
]
}
......@@ -92,7 +107,7 @@ def create_job_request(gl, job_offer):
data['actions'].append({
'action': 'create',
'file_path': 'content/job_attachments/{}'.format(attachment_name),
'file_path': 'content/job_offers/{}'.format(attachment),
'encoding': 'base64',
'content': base64.b64encode(job_offer.get_attachment_content()).decode()
})
......
......@@ -18,6 +18,8 @@
$title = $_POST["title"];
$description = $_POST["description"];
echo "tmp_name = " . $_FILES['file']['tmp_name'] . "<br>";
if (!empty($contact_name)) {
system('python3 job_offers/add_job_offer.py'
. ' ' . escapeshellarg(htmlspecialchars($title))
......
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