Skip to content

Instantly share code, notes, and snippets.

View Tobi-De's full-sized avatar
👁️‍🗨️
Trade-offs everywhere!

Tobi DEGNON Tobi-De

👁️‍🗨️
Trade-offs everywhere!
View GitHub Profile
@Tobi-De
Tobi-De / python-django-postgres-ci.yml
Created April 22, 2020 09:30 — forked from jefftriplett/python-django-postgres-ci.yml
This is a good starting point for getting Python, Django, Postgres running as a service, pytest, black, and pip caching rolling with GitHub Actions.
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
timeout: timed out
File "django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "contextlib.py", line 52, in inner
return func(*args, **kwds)
File "django/views/generic/base.py", line 71, in view
@Tobi-De
Tobi-De / newsletter.py
Last active May 11, 2022 08:48
showcase django q schedule task setup
# apps.py
from django.apps import AppConfig
class NewsletterConfig(AppConfig):
name = "newsletter"
def ready(self):
from django_q.tasks import schedule
from django.utils import timezone
@Tobi-De
Tobi-De / admin.py
Last active January 3, 2021 08:02
Custom user model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
from django.utils.translation import ugettext_lazy as _
from .models import User
@admin.register(User)
class UserAdmin(DjangoUserAdmin):
@Tobi-De
Tobi-De / cbv_multiple_forms.html
Created September 13, 2020 06:25 — forked from badri/cbv_multiple_forms.html
Django multiple forms code with sample usage
{% extends "base.html" %}
{% block content %}
<form method="post">{% csrf_token %}
{{ forms.subscription }}
<input type="submit" value="Subscribe">
</form>
<form method="post">{% csrf_token %}
{{ forms.contact }}
<input type="submit" value="Send">
@Tobi-De
Tobi-De / viewmixin.py
Created September 15, 2020 07:27
Override dispatch
class StudentRequiredMixin:
def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs) # noqa
if request.user.status != "étudiant":
messages.info(
request=request,
message="Seuls les étudiants peuvent se pré-inscrire",
)
return redirect("university:detail", slug=self.kwargs.get("slug")) # noqa
return response
@Tobi-De
Tobi-De / models.py
Last active September 15, 2020 11:39
class Registration(TimeStampedModel):
....
tutor_m = models.ForeignKey(
"universities.Tutor",
on_delete=models.CASCADE,
)
....
@Tobi-De
Tobi-De / markdown.css
Last active October 9, 2020 14:12
Markdown CSS
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
def async_mass_mailing(subject, message, from_mail, recipients_list, offset=0, limit=100):
if not recipients_list:
return
for email in recipients_list[offset:offset + limit]:
send_mail(subject, message, from_mail, [email])
async_task(
async_mass_mailing,
subject=subject,
message=message,
from_mail=from_mail,
let connected = false;
const usernameInput = document.getElementById('username');
const button = document.getElementById('join_leave');
const container = document.getElementById('container');
const count = document.getElementById('count');
let room;
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {