Skip to content

Instantly share code, notes, and snippets.

View gitllermopalafox's full-sized avatar
🏠
127.0.0.1

Guillermo Palafox gitllermopalafox

🏠
127.0.0.1
View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# install pyftpdlib
# (shell) > easy_install https://pyftpdlib.googlecode.com/files/pyftpdlib-1.0.1.tar.gz
# tutorial
# https://code.google.com/p/pyftpdlib/wiki/Tutorial
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
@gitllermopalafox
gitllermopalafox / Django model dependent image size validation
Last active September 13, 2021 13:03
Django model dependent image size validation
# Model dependent image size validation
# forms.py
from django import forms
from .models import *
from django.core.files.images import get_image_dimensions
class ValidateImageForm(forms.ModelForm):
class Meta:

Django-celery + Redis notes

Installation and Setup

  1. Install redis on OSX (10.7) Lion I used:

     $ brew install redis
    
  2. In the project and virtualenv I wanted to use django-celery in I installed the following.

#!/bin/bash
#update an A record in digital Ocean. Dynamic DNS style.
#API info here:
#https://developers.digitalocean.com/#domains-list
#your domain ID
domain_id="XXX"
#record to update
record_id="XXX"
#digitalocean client_id
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import (AbstractBaseUser,
BaseUserManager as DjBaseUserManager)
from model_utils.managers import InheritanceManager
class BaseUserManager(DjBaseUserManager, InheritanceManager):
"""
from django.conf import settings
import re
class SubdominiosMiddleware:
def process_request(self, request):
request.domain = request.META['HTTP_HOST']
request.subdomain = ''
parts = request.domain.split('.')
if len(parts) == 3 or (re.match("^localhost", parts[-1]) and len(parts) == 2):
# Example logging configuration that will restrict console logging to
# at most 2 repeated messages per 30 seconds.
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'simple': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s'
},
},
{% if is_paginated %}
<div class="pagination">
<ul>
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}">
{% else %}
<li class="disabled"><a href="#">
{% endif %}
Prev</a></li>
{% for p in page_obj.paginator.page_range %}
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'),
# When a use case comes up that a month needs to be involved as
# well, you add an argument in your regex:
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'),
# That works fine, unless of course you want to show something
# different for just the year, in which case the following case can be
# used, making separate views based on the arguments as djangoproject