This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.shortcuts import redirect | |
def language_view(request, lang): | |
response = redirect(request.META.get('HTTP_REFERER', '/')) | |
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang) | |
return response | |
# © 2020 GitHub, Inc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name your.ip.address.or.domain.name; | |
root /var/www/project_name/; | |
location / { | |
try_files /static/index.html =404; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=gunicorn socket | |
[Socket] | |
ListenStream=/run/gunicorn.sock | |
[Install] | |
WantedBy=sockets.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=gunicorn daemon | |
Requires=gunicorn.socket | |
After=network.target | |
[Service] | |
User=user-name | |
Group=www-data | |
WorkingDirectory=/home/user-name/myprojectdir | |
ExecStart=/home/user-name/myprojectdir/myprojectenv/bin/gunicorn \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import requests | |
VALID_IMAGE_EXTENSIONS = ('.png', '.jpg', '.jpeg') | |
def image_uploader(url, directory): | |
images = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
from exponent_server_sdk import ( | |
PushClient, | |
PushMessage, | |
PushServerError, | |
) | |
from requests.exceptions import ConnectionError, HTTPError | |
def send_expo_message(tokens: List[str], message: str, extra=None): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.routers import SimpleRouter, Route, DynamicRoute | |
class LookupFreeRouter(SimpleRouter): | |
routes = [ | |
# CRUD route. | |
Route( | |
url=r'^{prefix}{trailing_slash}$', | |
mapping={ | |
'get': 'retrieve', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:latest-alpine | |
### dependencies on alpine image ### | |
#poetry installation/(runtime?) dependencies | |
RUN apk add gcc musl-dev libffi-dev | |
# Pillow installation dependencies | |
RUN apk add --no-cache jpeg-dev zlib-dev | |
# Pillow runtime dependencies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
import pydantic | |
class AllOptional(pydantic.main.ModelMetaclass): | |
def __new__(mcs, name, bases, namespaces, **kwargs): | |
annotations = namespaces.get('__annotations__', {}) | |
for base in bases: | |
annotations.update(base.__annotations__) |