Commit 74f06350 authored by BERJON Matthieu's avatar BERJON Matthieu

Add display of README files for webapp

For each webapp when a README is registered in the database, I read the
file stored in the media directory and convert it using the mistune
library from markdown into HTML. I updated the dockerfile to be used in
the Django container as well.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent 3bdaa9bc
......@@ -5,7 +5,7 @@ RUN echo "deb http://ftp.debian.org/debian stretch-backports main" \
>> /etc/apt/sources.list.d/stretch.list
RUN apt-get update && apt-get -t stretch-backports install -y \
python3-django python3-django-allauth
python3-django python3-django-allauth python3-mistune
RUN apt-get install -y mysql-server default-libmysqlclient-dev \
nginx-light zip python3-dev python3-pip python3-mysqldb \
......
from django import template
import mistune
register = template.Library()
@register.filter
def markdown(value):
""" Convert markdown content into HTML. """
markdown = mistune.Markdown()
return markdown(value)
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
......@@ -6,11 +7,15 @@ from django.views.generic import (
DetailView,
UpdateView,
)
import os
from .models import Webapp, Job, AllgoUser
def index(request):
"""
Do nothing specific just return a specific template
"""
return render(request, "home.html")
......@@ -44,12 +49,36 @@ class WebappDetail(DetailView):
context_object_name = 'webapp'
def get_object(self):
"""recover data according the docker_name rather than the ID."""
data = self.kwargs.get('docker_name', None)
queryset = get_object_or_404(Webapp, docker_name=data)
return queryset
def get_context_data(self, **kwargs):
"""Recover the README file if exist and convert it from markdown to
HTML
"""
context = super(WebappDetail, self).get_context_data(**kwargs)
# Check if a readme is declared in the database
if self.object.readme:
readme_file = os.path.join(
settings.MEDIA_ROOT,
self.object.docker_name,
'Readme')
with open(readme_file, 'r') as md_data:
print(md_data)
context['readme'] = md_data.read()
else:
readme_file = None
return context
class JobList(LoginRequiredMixin, ListView):
"""
Display the list of jobs for a given identified user
"""
model = Job
pattern_name = 'job_list'
template_name = 'job_list.html'
......@@ -58,6 +87,7 @@ class JobList(LoginRequiredMixin, ListView):
redirect_field_name = 'redirect_to'
def get_queryset(self):
"""Filter jobs for a given user"""
queryset = Job.objects.filter(user_id=self.request.user.id)
return queryset
......
{% extends "base.html" %}
{% load markdownify %}
{% block title %}{{ webapp.name }}{% endblock %}
{% block content %}
<h2>{{ webapp.name }}</h2>
<p>{{ webapp.description }}</p>
{% if readme %}
{{ readme | markdown | safe }}
{% else %}
<p>No description available</p>
{% endif %}
{% endblock %}
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