Skip to content

Commit

Permalink
Creating html files for articles and save url
Browse files Browse the repository at this point in the history
  • Loading branch information
aminatadjer committed May 16, 2020
1 parent 32e54d5 commit a721ec9
Show file tree
Hide file tree
Showing 54 changed files with 147 additions and 13 deletions.
Binary file modified API/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified API/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file modified API/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified API/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions API/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down Expand Up @@ -115,7 +115,7 @@
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
'default': dj_database_url.config(conn_max_age=600) or {
'default': dj_database_url.config(conn_max_age=600) or {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DB_NAME', 'coronawatch'),
'USER': os.environ.get('DB_USER', 'root'),
Expand All @@ -125,8 +125,8 @@
}
}

REST_FRAMEWORK={
'DEFAULT_AUTHENTICATION_CLASSES': (
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (

'rest_framework.authentication.TokenAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
Expand Down
9 changes: 4 additions & 5 deletions API/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
path('admin/', admin.site.urls),

path('', include('coronawatch.urls')),
path('',include('report.urls')),
path('',include('article.urls')),

path('', include('report.urls')),
path('', include('article.urls')),
path('api/token/obtain', MyTokenObtainPairView.as_view(), name='token_create'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
Expand All @@ -51,5 +50,5 @@


if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
9 changes: 5 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
dependecies:
dependecies:

pip install djangorestframework
pip install markdown # Markdown support for the browsable API.
pip install django-filter # Filtering support
pip install markdown # Markdown support for the browsable API.
pip install django-filter # Filtering support

pip install mysqlclient


pip install djoser

pip install django-cors-headers

pip install djangorestframework-simplejwt

pip install dj_database_url
Binary file modified article/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified article/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified article/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified article/__pycache__/serializers.cpython-38.pyc
Binary file not shown.
Binary file modified article/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified article/__pycache__/views.cpython-38.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions article/migrations/0002_article_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.4 on 2020-05-16 07:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('article', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='article',
name='url',
field=models.CharField(default='', max_length=200),
),
]
Binary file modified article/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file modified article/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


class Article(models.Model):
url = models.CharField(max_length=200, default="")
date = models.DateTimeField(auto_now_add=True)
valide = models.BooleanField(default=False)
supprime = models.BooleanField(default=False)
Expand Down
23 changes: 23 additions & 0 deletions article/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Tuto2</title>
</head>
<body>
<center width="80%" height="80%">
<h3>
{% block includes %}
{{ Title| safe }}

</h3>

{{ media | safe}}

<p>

{{ content| safe }}
{% endblock includes %}
</p>
</center>
</body>
</html>
46 changes: 46 additions & 0 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from article.serializers import *
from rest_framework.response import Response
from rest_framework.decorators import api_view, action
from django.core.files import File

from django.http import JsonResponse
from django.shortcuts import render
from django.template.loader import render_to_string

from datetime import datetime
# Create your views here.
Expand All @@ -16,6 +21,47 @@ class ArticleViewSet(viewsets.ModelViewSet):
]
serializer_class = ArticleSerializer

@action(methods=['post', 'get', 'put'], detail=False)
def ArticleAdd(self, request):

if(request.method == "GET"):
data = Article.objects.all()
serializers = ArticleSerializer(data, many=True)
return Response(serializers.data)
elif (request.method == "POST"):
serializers = ArticleSerializer(data=request.data)
print(str(request.data))
if(serializers.is_valid()):
media = ""
media = str(request.data['media'])
content = request.data['contenu']
title = request.data['titre']
displayMedia = ""
if media.endswith("mp4"):
displayMedia = """<video width="80%" height="80%" controls><source src ="../""" + \
media + """ \" type=\"video/mp4\"\></video>"""

else:
displayMedia = """<img width="80%" height="80%" src="../""" + \
media+""" \" ></img>"""

aaa = render_to_string(
'index.html', {'media': displayMedia, 'Title': title, 'content': content})
print(aaa)
instance = serializers.save()
instance_id = instance.id
nameF = 'media/articles/article' + str(instance_id)+'.html'
mydata = request.data
mydata['url'] = nameF
serializers = ArticleSerializer(data=mydata)
if(serializers.is_valid()):
serializers.save()
f = open(nameF, 'w')
f.write(aaa)
f.close()
return Response(serializers.data, status=status.HTTP_201_CREATED)
return Response(serializers.errors, status=status.HTTP_400_BAD_REQUEST)

@action(methods=['put'], detail=True)
def ArticleSupprimer(self, request, pk=None):
try:
Expand Down
Binary file modified coronawatch/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified coronawatch/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified coronawatch/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified coronawatch/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified coronawatch/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified coronawatch/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/__pycache__/serializers.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified customauth/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added media/BBHTUf6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/BBHTUf6_2WpDfdp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/BBHTUf6_L9EI0ME.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/Event_org_chart_example_-_Page_3.png
Binary file not shown.
Binary file removed media/Event_org_chart_example_-_Page_3_DZPpIAm.png
Binary file not shown.
Binary file removed media/Event_org_chart_example_-_Page_3_Wc7ZbuK.png
Binary file not shown.
23 changes: 23 additions & 0 deletions media/articles/article44.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Tuto2</title>
</head>
<body>
<center width="80%" height="80%">
<h3>

dsq

</h3>

<video width="80%" height="80%" controls><source src ="../h.mp4 " type="video/mp4"\></video>

<p>

qsd

</p>
</center>
</body>
</html>
23 changes: 23 additions & 0 deletions media/articles/article46.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Tuto2</title>
</head>
<body>
<center width="80%" height="80%">
<h3>

fza

</h3>

<img width="80%" height="80%" src="../BBHTUf6.jpg " ></img>

<p>

faz

</p>
</center>
</body>
</html>
Binary file added media/h.mp4
Binary file not shown.
Binary file added report/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added report/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added report/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added report/__pycache__/serializers.cpython-38.pyc
Binary file not shown.
Binary file added report/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added report/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified report/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified report/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added sendMail/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added sendMail/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added sendMail/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added sendMail/__pycache__/views.cpython-38.pyc
Binary file not shown.

0 comments on commit a721ec9

Please sign in to comment.