Skip to content

Instantly share code, notes, and snippets.

@Alexx-G
Alexx-G / notification_clients.py
Created October 31, 2016 14:23
Interchangeable clients for sending notifications (in context of a Django app)
'''
This module contains interchangeable clients for sending notifications.
Use cases for those helpers:
- send notifications using a common interface;
- change the client in a transparent way (based on settings);
'''
from __future__ import unicode_literals
import logging
@Alexx-G
Alexx-G / sitemaps.py
Last active February 26, 2016 11:38
Helper for autodiscovering of sitemaps modules based on Django's sitemap
# app/sitemaps.py
'''
Example of sitemaps module for a list of products.
For more info about sitemaps check out django docs
https://docs.djangoproject.com/en/stable/ref/contrib/sitemaps/
'''
from django.contrib.sitemaps import Sitemap
from .models import Product
@Alexx-G
Alexx-G / deployment.log
Created February 18, 2016 22:40
Heroku-like deployments on dedicated servers using git-deploy
emote: HEAD is now at e766da0 Move confirmed booking rendering in the same view.
remote: files changed: 5
remote: ============================================
remote: Exporting needed config variables (from .env)
remote: ============================================
remote: ============================================
remote: Installing nodejs dependencies
remote: ============================================
....
remote: [00:25:56] Using gulpfile /var/www/bakimli/gulpfile.js
@Alexx-G
Alexx-G / login.html
Last active January 24, 2022 14:30
Login redirect with user friendly alerts
{% for message in messages %}
{# Login redirect alert.#}
{# We have to display only the last message. Other are irelevant, but must be iterated #}
{% if 'login_required' in message.tags and forloop.last %}
<div class="alert alert-info alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
{{ message }}
</div>
@Alexx-G
Alexx-G / middlewares.py
Last active October 12, 2018 09:30
A Django middleware for logging exceptions.
# -*- coding: utf8 -*-
from __future__ import unicode_literals
import logging
import sys
import traceback
LOGGER = logging.getLogger(__name__)
@Alexx-G
Alexx-G / django-startproject.sh
Last active August 29, 2015 14:23
A bash script for easier setup of the new django project.
#!/bin/bash
read -p "Project's folder (press Enter to install in current folder): " project_folder </dev/tty ;
read -p "Project name (required - letters, numbers underscore): " project_name </dev/tty ;
if [ -n "$project_folder" ]; then
mkdir $project_folder; cd $project_folder;
fi
@Alexx-G
Alexx-G / settings.py
Last active August 29, 2015 14:19
Simple django logging configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s | %(asctime)s | %(name)s:%(funcName)s | %(process)d | %(thread)d | %(message)s'
},
'simple': {
'format': '%(levelname)s | %(name)s | %(message)s'
},
@Alexx-G
Alexx-G / serializers.py
Last active August 18, 2022 00:28
Mixin for creating serializers with configurable fields (for the django rest framework).
"""
Some helper serializer mixins.
Helps to reuse serializers for different purposes.
"""
import logging
from rest_framework import serializers
LOGGER = logging.getLogger(__name__)
@Alexx-G
Alexx-G / .gitignore
Created March 10, 2015 11:20
My gitignore file for django projects
# Python
*.py[cod]
venv/
__pycache__/
# Packages
dist/
lib/
lib64/
@Alexx-G
Alexx-G / postgreSQL_configuration.rst
Last active August 29, 2015 14:14
PostgreSQL configuration tutorial

Install PostgreSQL

  1. Install dependencies

    sudo apt-get install libpq-dev python-dev

    Note: If you're using python3, then use python-dev for python 3.

  2. Install PostgreSQL