Initial commit
This commit is contained in:
commit
7a053983a7
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/env/
|
||||
__pycache__/
|
||||
*.sqlite3
|
22
manage.py
Executable file
22
manage.py
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'scratch.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
django>=4.0,<5.0
|
0
scratch/__init__.py
Normal file
0
scratch/__init__.py
Normal file
16
scratch/asgi.py
Normal file
16
scratch/asgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for scratch project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'scratch.settings')
|
||||
|
||||
application = get_asgi_application()
|
124
scratch/settings.py
Normal file
124
scratch/settings.py
Normal file
|
@ -0,0 +1,124 @@
|
|||
"""
|
||||
Django settings for scratch project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.0.4.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-=pp_ny!1v^o7_mt15%ls=6y5i%isdz6nl@h9pz9d*%&_d&&2&2'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'scratch_show.apps.ScratchShowConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'scratch.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'scratch.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
22
scratch/urls.py
Normal file
22
scratch/urls.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""scratch URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('', include('scratch_show.urls'))
|
||||
]
|
16
scratch/wsgi.py
Normal file
16
scratch/wsgi.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for scratch project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'scratch.settings')
|
||||
|
||||
application = get_wsgi_application()
|
0
scratch_show/__init__.py
Normal file
0
scratch_show/__init__.py
Normal file
6
scratch_show/admin.py
Normal file
6
scratch_show/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Event, ScratchProject
|
||||
|
||||
admin.site.register(Event)
|
||||
admin.site.register(ScratchProject)
|
6
scratch_show/apps.py
Normal file
6
scratch_show/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ScratchShowConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'scratch_show'
|
9
scratch_show/forms.py
Normal file
9
scratch_show/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import forms
|
||||
from . import models
|
||||
|
||||
class ScratchProjectAddForm(forms.ModelForm):
|
||||
url = forms.URLField(label='Lien Scratch du projet (URL)')
|
||||
|
||||
class Meta:
|
||||
fields = ('name', 'author_name', 'url')
|
||||
model = models.ScratchProject
|
35
scratch_show/migrations/0001_initial.py
Normal file
35
scratch_show/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 4.0.4 on 2022-05-13 00:55
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Event',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128, verbose_name="Nom de l'évènement")),
|
||||
('date', models.DateField(default=datetime.date.today)),
|
||||
('accept_projects', models.BooleanField(default=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ScratchProject',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=128, verbose_name='Nom du projet')),
|
||||
('author_name', models.CharField(max_length=128, verbose_name='Auteur')),
|
||||
('project_id', models.PositiveBigIntegerField(unique=True, verbose_name='Scratch project id')),
|
||||
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='scratch_show.event')),
|
||||
],
|
||||
),
|
||||
]
|
0
scratch_show/migrations/__init__.py
Normal file
0
scratch_show/migrations/__init__.py
Normal file
19
scratch_show/models.py
Normal file
19
scratch_show/models.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from datetime import date
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
class Event(models.Model):
|
||||
name = models.CharField("Nom de l'évènement", max_length=128)
|
||||
date = models.DateField(default=date.today)
|
||||
accept_projects = models.BooleanField(default=True)
|
||||
|
||||
|
||||
class ScratchProject(models.Model):
|
||||
name = models.CharField('Nom du projet', max_length=128)
|
||||
author_name = models.CharField('Auteur', max_length=128)
|
||||
project_id = models.PositiveBigIntegerField('Scratch project id', unique=True)
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('scratch_show:project-detail', kwargs={'pk' : self.pk})
|
|
@ -0,0 +1,4 @@
|
|||
<h1>{{ object.name }}</h1>
|
||||
<p>Créateur : {{ object.author_name }}</p>
|
||||
|
||||
<iframe src="https://scratch.mit.edu/projects/{{ object.project_id }}/embed" allowtransparency="true" width="485" height="402" frameborder="0" scrolling="no" allowfullscreen></iframe>
|
|
@ -0,0 +1,4 @@
|
|||
<form method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
3
scratch_show/tests.py
Normal file
3
scratch_show/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
9
scratch_show/urls.py
Normal file
9
scratch_show/urls.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'scratch_show'
|
||||
|
||||
urlpatterns = [
|
||||
path('add', views.ScratchProjectAddView.as_view(), name='project-add'),
|
||||
path('project/<int:pk>', views.ScratchProjectDetailView.as_view(), name='project-detail'),
|
||||
]
|
34
scratch_show/views.py
Normal file
34
scratch_show/views.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import re
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils import timezone
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.detail import DetailView
|
||||
|
||||
from . import forms, models
|
||||
|
||||
|
||||
SCRATCH_ID_REGEX = re.compile(r'https://scratch\.mit\.edu/projects/([0-9]+)')
|
||||
|
||||
def get_scratch_id_from_url(url):
|
||||
match = SCRATCH_ID_REGEX.search(url)
|
||||
return int(match.group(1))
|
||||
|
||||
|
||||
class ScratchProjectAddView(CreateView):
|
||||
form_class = forms.ScratchProjectAddForm
|
||||
template_name = 'scratch_show/scratchproject_form.html'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.event = get_object_or_404(models.Event, date=timezone.now().date(), accept_projects=True)
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
url = form.cleaned_data['url']
|
||||
form.instance.project_id = get_scratch_id_from_url(url)
|
||||
form.instance.event = self.event
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ScratchProjectDetailView(DetailView):
|
||||
model = models.ScratchProject
|
Loading…
Reference in a new issue