## ![](home.png)
## HackInScience
## Hackinscience
Julien Palard
Paris.py 16
## Julien Palard - Python core dev / freelance - CPython documentation translator (french only) - Python teacher/coach, at - Makina Corpus - Center for Research and Interdisciplinarity - Sup'Internet - … julien@python.org, @sizeof, https://mdk.fr
## HackInScience Back in 2015, we started a project with the CRI of Paris Descartes: A one-week intensive Python class. ![](descartes-and-cri.jpg)
## Pedagogy We were aiming for 50 students per week, so we had to adapt, we needed: - A short Python introduction (slides and a teacher). - Lots of exercises, sorted by difficulty. - A bot to correct exercises, live. - 2 to 3 highly available teachers in the room. - Short optional lessons about very specific topics. - Rules, teaching best practices.
## 2015: Focus on content We started by focusing on exercises (needed to give a course) and the correction bot (needed to scale). Workflow from a student point of view: - Clone the exercise repo - Do exercises - git push - Receive a mail with the correction
## 2016: Focus on confort Antoine Angot developped a website so students do no longer needed to use git. Emails were no longer needed, which is nice too.
## 2017: Focus on content, again The year to enhance existing parts, to rely on them, this is also the year of... many repositories: - One for the website - One for the exercises (markdown files) - One for our internal documentation - One for the correction bot - One for the ansible playbook
## 2018: Migrating to Django Jérôme Schneider started to migrate the website to Django.
(So we could modify it more easily.)
## Show me the code! So what is it now? 181 lines of Python (first fully working version), it should fit in a few slides ;)
## Django models ```python class Exercise(models.Model): title = models.CharField(max_length=255) check = models.TextField() solution = models.TextField() wording = models.TextField() ```
## Django models Helps in generating: - DB migrations; - Admin pages; - Forms; - Views (Using class-based views); - API (Using DRF); - Queries ("ORM" as humans say).
## Django view ```python class ExerciseListView(LoginRequiredMixin, ListView): model = Exercise template_name = "hkis/exercises.html" ```
## Django view ![](exercises.png)
## Django view ```python class ExerciseView(LoginRequiredMixin, DetailView): model = Exercise template_name = "hkis/exercise.html" def get_context_data(self, **kwargs): """Add student answers. """ context = super().get_context_data(**kwargs) context["answers"] = self.object.answers.filter( user=self.request.user ).order_by("-id") return context ```
## Django view ![](exercise.png)
## Need an API now ```python class ExerciseSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Exercise fields = '__all__' class ExerciseViewSet(viewsets.ModelViewSet): queryset = Exercise.objects.all() serializer_class = ExerciseSerializer router = routers.DefaultRouter() router.register('exercises', ExerciseViewSet) ```
## Need an API now ![](api.png)
## Need an admin interface now ```python from django.contrib import admin from website.models import Answer, Exercise admin.site.register(Answer) admin.site.register(Exercise) ```
## Admin interface ![](admin.png)
## Admin interface ![](admin-markdown.png)
## ADmin interface ![](admin-check.png)
## The future Display exercises as a tree, with subjects like datascience, web, low-level, and so on as group of leafs of the tree.
## Questions? - julien@python.org - Twitter: @sizeof - IRC: mdk on #python-fr (freenode) - https://mdk.fr - https://hackinscience.org