Skip to content

Instantly share code, notes, and snippets.


Bob Belderbos bbelderbos

View GitHub Profile
import collections
import bs4
import requests
import requests_cache
URL = ""
View django-is_new-filter
def is_new(added, days=7):
days_new_deadline = - timezone.timedelta(days=days)
return added > days_new_deadline
# use in template
<a {% with obj.added|is_new as is_new %}
{% if is_new %}class="is_new newLeft"{% endif %}
{% endwith %} href="{% url 'app:view' pk %}">link</a>
View for-empty
{% for book in books %}
<li>{{ book }}</li>
{% empty %}
<li>Sorry, there are no books.</li>
{% endfor %}
class TermsEnforcerMiddleware:
"""Django Middleware (add to MIDDLEWARE) to enforce users to sign the terms"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
# only relevant for logged in users
from import BaseCommand
# import ORM objects
class Command(BaseCommand):
help = 'help text'
def add_arguments(self, parser):
bbelderbos /
Created Jul 11, 2018
has a topic been discussed on python bytes?
# caches python bytes podcast links to a file and searches links on first cli
# arg string (case insensitive)
import os
import re
import sys
import time
import feedparser
from cfonts import render, say
bbelderbos /
Created Dec 28, 2017 — forked from zulhfreelancer/
How to upgrade Heroku Postgres database plan?
  1. Assuming you have multiple Heroku apps and Git remote like so:
development (fetch)
development (push)
origin  (fetch)
origin  (push)
production (fetch)
production (push)
staging (fetch)