• Stars
    star
    917
  • Rank 47,842 (Top 1.0 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A django application that tries to eliminate annoying things in the Django framework. ⛺

Description

Code Shelter

This django application eliminates certain annoyances in the Django framework.

Features

Installation instructions

  • Copy the annoying directory to your django project or put in on your PYTHONPATH.
  • You can also run python setup.py install, easy_install django-annoying, or pip install django-annoying.
  • Add "annoying" under INSTALLED_APPS in your settings.py file.
  • Django-annoying requires Django 1.11 or later.

Examples

render_to decorator

from annoying.decorators import render_to

# 1. Template name in decorator parameters

@render_to('template.html')
def foo(request):
    bar = Bar.object.all()
    return {'bar': bar}

# equals to
def foo(request):
    bar = Bar.object.all()
    return render(request, 'template.html', {'bar': bar})


# 2. Template name as TEMPLATE item value in return dictionary

@render_to()
def foo(request, category):
    template_name = '%s.html' % category
    return {'bar': bar, 'TEMPLATE': template_name}

#equals to
def foo(request, category):
    template_name = '%s.html' % category
    return render(request, template_name, {'bar': bar})

signals decorator

Note: signals is deprecated and will be removed in a future version. Django now includes this by default.

from annoying.decorators import signals

# connect to registered signal
@signals.post_save(sender=YourModel)
def sighandler(instance, **kwargs):
    pass

# connect to any signal
signals.register_signal(siginstance, signame) # and then as in example above

#or

@signals(siginstance, sender=YourModel)
def sighandler(instance, **kwargs):
    pass

#In any case defined function will remain as is, without any changes.

ajax_request decorator

The ajax_request decorator converts a dict or list returned by a view to a JSON or YAML object, depending on the HTTP Accept header (defaults to JSON, requires PyYAML if you want to accept YAML).

from annoying.decorators import ajax_request

@ajax_request
def my_view(request):
    news = News.objects.all()
    news_titles = [entry.title for entry in news]
    return {'news_titles': news_titles}

autostrip decorator

Note: autostrip is deprecated and will be removed in a future version. Django now includes this by default.

from annoying.decorators import autostrip

@autostrip
class PersonForm(forms.Form):
    name = forms.CharField(min_length=2, max_length=10)
    email = forms.EmailField()

get_object_or_None function

from annoying.functions import get_object_or_None

def get_user(request, user_id):
    user = get_object_or_None(User, id=user_id)
    if not user:
        ...

AutoOneToOneField

from annoying.fields import AutoOneToOneField


class MyProfile(models.Model):
    user = AutoOneToOneField(User, primary_key=True)
    home_page = models.URLField(max_length=255, blank=True)
    icq = models.IntegerField(blank=True, null=True)

JSONField

Note that if you're using Postgres you can use the built-in django.contrib.postgres.fields.JSONField, or if you're using MySQL/MariaDB you can use Django-MySQL's JSONField.

from annoying.fields import JSONField


#model
class Page(models.Model):
    data = JSONField(blank=True, null=True)



# view or another place..
page = Page.objects.get(pk=5)
page.data = {'title': 'test', 'type': 3}
page.save()

get_config function

from annoying.functions import get_config

ADMIN_EMAIL = get_config('ADMIN_EMAIL', '[email protected]')

StaticServer middleware

Add this middleware as first item in MIDDLEWARE_CLASSES(or MIDDLEWARE)

example:

MIDDLEWARE_CLASSES = (  # MIDDLEWARE if you're using the new-style middleware
    'annoying.middlewares.StaticServe',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

It will serve static files in debug mode. Also it helps when you debug one of your middleware by responding to static requests before they get to debugged middleware and will save you from constantly typing "continue" in debugger.

get_object_or_this function

from annoying.functions import get_object_or_this

def get_site(site_id):
    base_site = Site.objects.get(id=1)

    # Get site with site_id or return base site.
    site = get_object_or_this(Site, base_site, id=site_id)

    ...
    ...
    ...

    return site

More Repositories

1

catt

Cast All The Things allows you to send videos from many, many online sources to your Chromecast.
Python
3,257
star
2

shortuuid

A generator library for concise, unambiguous and URL-safe UUIDs.
Python
1,905
star
3

expounder

A library for explaining things in HTML.
JavaScript
504
star
4

tbvaccine

A small utility to pretty-print Python tracebacks. ⛺
Python
376
star
5

django-loginas

"Log in as user" for the Django admin.
Python
355
star
6

python-yeelight

A Python library for controlling YeeLight WiFi RGB bulbs (mirror of https://gitlab.com/stavros/python-yeelight).
Python
262
star
7

goatfish

A small, schemaless Python ORM that is backed by SQLite. ⛺
Python
233
star
8

netproxy

A Netflix/Hulu/Pandora/etc proxy in a box.
Python
230
star
9

python-fuse-sample

A sample FUSE filesystem in Python.
Python
169
star
10

django-project-template

The Django project template I use, for installation with django-admin.
Python
161
star
11

gr8w8upd8m8

Gr8W8Upd8M8 is a script to automatically read your weight from a Wii Balance Board. ⛺
Python
145
star
12

imdbapi

An API for the IMDB site. ⛺
Python
131
star
13

A6lib

An ESP8266/Arduino library for communicating with the A6 GSM module. ⛺
C++
127
star
14

jsane

A saner way to traverse JSON in Python
Python
125
star
15

encbup

Encrypted backups (without the backups)
Python
121
star
16

sysaidmin

A GPT-powered sysadmin.
Python
115
star
17

tiny-ESP8266-breakout

A very small and basic ESP8266 breakout board
110
star
18

omnisync

omnisync is a universal file synchroniser and backup program (think rsync) that supports multiple transport systems (such as plain files, sftp, s3 and virtual, currently, and support for ftp, http, et al is planned). It is designed to be fast, small, extensible, portable and bandwidth-efficient. It is available for Linux, Windows and Mac. ⛺
Python
87
star
19

iRotary

One man's quest to turn an old rotary phone into a mobile phone.
Arduino
83
star
20

django-cloudflare-push

A piece of middleware that uses Cloudflare's HTTP/2 Push to push static media to the clients. ⛺
Python
75
star
21

gweet

A message queue for the abhorrently named Internet of Things
Go
70
star
22

static-appengine-hoster

An App Engine application for hosting static sites under multiple domains in a single app.
Python
66
star
23

django-tokenauth

Django authentication backend that uses tokens sent over email.
Python
63
star
24

arduino-irrigation

A GSM-based Arduino remote controller for an irrigation system.
Arduino
62
star
25

esplights

A home automation sensor and controller based on an ESP8266.
Arduino
48
star
26

yeecli

A command-line utility for a YeeLight RGB lamp. (mirror of https://gitlab.com/stavros/yeecli)
Python
42
star
27

episode-renamer

Episode renamer is a simple python script that renames folders of TV episode video files to their proper names.
Python
41
star
28

kicad-lib

My KiCad components library.
35
star
29

Spamnesty

A service that tries to have some fun with spam (mirror of https://gitlab.com/stavros/Spamnesty/)
Python
33
star
30

captainwebhook

Captain Webhook eats webhooks and executes commands.
Python
30
star
31

spamgpt

SpamGPT, a bot that wastes spammers' damn time, like they waste mine.
Python
25
star
32

pastebinit

pastebinit is a command-line tool to send data to a "pastebin", a web site which allows its users to upload snippets of text for public viewing. ⛺
Python
25
star
33

apache-config

A script for configuring apache with Django+wsgi/fcgi+virtualenv+etc.
Python
23
star
34

ArduiRC

Remotely control IR/RF devices from a computer with Arduino.
Arduino
18
star
35

docker-fgallery

A Dockerfile for installing fgallery. ⛺
Shell
18
star
36

ez-openai

Ez API, ez life.
Python
16
star
37

landing-page

A very simple landing page app for AppEngine.
Python
15
star
38

stringphone

String phone is a secure communications protocol and library geared towards embedded devices.
Python
14
star
39

bakeit

A command-line utility for pastery, the best pastebin in the world.
Python
12
star
40

pythess-files

The code files/presentations/everything else used in the PyThess meetup
Jupyter Notebook
11
star
41

lektor-shortcodes

A shortcodes plugin for lektor
Python
11
star
42

shufflecast

A TV channel with all your favorite shows.
Python
11
star
43

photocopy

A script to archive photos off a camera to a directory.
Python
10
star
44

nxt-python

NXT-Python is a python driver/interface for the Lego Mindstorms NXT robot based on NXT_python.
Python
10
star
45

Reverend

A clone of Reverend, the naive Bayesian classifier written in Python.
Python
10
star
46

A6-ESP8266-breakout

A breakout board that includes an ESP8266 and an A6 GSM module, for easily making GSM-enabled applications (mirror)
Shell
9
star
47

Pythia

High quality & fast "true random" number generator (shuffling system)
JavaScript
9
star
48

lektor-thumbnail-generator

A thumbnail generator for Lektor content
Python
9
star
49

pastery.vim

A Vim plugin for the sweetest pastebin in the world, pastery.net.
Vim Script
9
star
50

apt-btrfs-snapshot

A fork of apt-btrfs-snapshot.
Python
8
star
51

gamelights

An RGB LED strip WiFi controller, complete with code and PCB designs.
KiCad Layout
8
star
52

mediacenter-in-a-box

A media center in a box, compatible with Harbormaster for one-line deployments.
Python
8
star
53

pylast

A clone of Amr Hassan's pylast: a python interface to last.fm (and other api-compatible websites)
Python
6
star
54

awesomeblog-club

An easily self hostable curation site for collecting blogs and links.
TypeScript
5
star
55

django-project-templates

Some Django project templates for various things.
4
star
56

requests-guard

requests-guard is a small library that allows you to impose size and time limits on your HTTP requests.
Python
4
star
57

ChatGPT-Bot

A small Python library that makes it easier to write a ChatGPT bot.
Python
4
star
58

rust-bakeit

A command-line client for pastery.net, the best pastebin in the world (official mirror of https://gitlab.com/stavros/rust-bakeit).
Rust
3
star
59

the-spam-chronicles

The Spam Chronicles, a static website where I post all the spam I got and SpamGPT auto-replied to.
Python
2
star
60

progress

A simple progress bar in Python
Python
2
star
61

blacklist-pre-commit-hook

A pre-commit hook for blacklisting certain functions
Python
2
star
62

back-scratcher

A back scratching robot!
Python
2
star
63

zulipbot

A ChatGPT Zulip bot
Python
1
star
64

iphoneconverter

A small script to convert a folder of videos into an iPhone format.
1
star
65

reddit-rage-faces

An Opera extension to put ragefaces in every subreddit.
JavaScript
1
star