Skip to content

Instantly share code, notes, and snippets.

View rafen's full-sized avatar

Rafael Capdevielle rafen

View GitHub Profile
@rafen
rafen / register_app_test.py
Last active August 29, 2015 13:58
MMDBClient error debug for register_app
# Settings for local.py
#
# MMDB_API_HOST = 'http://mc.dev.nationalgeographic.com:8000'
#
# Load test database in your db. Use production db for this test if possible
# $ python manage.py loaddata mmdb/apps/users/fixtures/test_user.json
from mmdbcommons.client import MMDBClient, mmdb_client
from mmdbcommons.exceptions import AppAlreadyRegisteredError
import json
import requests
user_id = 9617855
host = 'http://mc.dev.nationalgeographic.com:8000'
url = host + '/user/%s/app_registration/' % user_id
data = {'name': 'YourShot'}
headers = {
@rafen
rafen / README.md
Created January 19, 2017 19:13
django-full-email

Full e-mail address Field for Django

Out of the box, Django e-mail fields for both database models and forms only accept plain e-mail addresses. For example, [email protected] is accepted.

On the other hand, full e-mail addresses which include a human-readable name, for example the following address fails validation in Django::

Joe Hacker

@rafen
rafen / warequest.py
Created March 25, 2017 21:24
Fix for yowsup-cli for registration
import urllib, sys, os, logging
import ssl, socket
import hashlib
from .waresponseparser import ResponseParser
from yowsup.env import S40YowsupEnv
CURRENT_ENV = S40YowsupEnv()
if sys.version_info < (3, 0):
import httplib
from urllib import urlencode
@rafen
rafen / README.md
Last active January 28, 2024 10:32
Django ExtendedActionsMixin allows ModelAdmin classes to execute actions with empty queryset and filtered queryset

ExtendedActionsMixin

This is a Django mixin that allows ModelAdmin classes to execute actions without selecting any objects on the change list of the Django Admin.

To implement it you need to include the Mixin as usual (see https://docs.djangoproject.com/en/1.10/topics/class-based-views/mixins/) and define a class attribute called extended_actions containing a list of string with the name of the actions that you want to be exectued with empty queryset.

If in the action you want to use the same queryset that the user is seeing, you can use the get_filtered_queryset method also provided by the mixin

@rafen
rafen / test_views.py
Last active April 11, 2022 18:59
GitHub webhook django view + tests
from unittest.mock import patch
from django.urls import reverse
from django.tests import TestCase
class TestGitHubWebhookView(TestCase):
@patch('my_app.views.GitHubWebhookView.ping')
def test_view_ping_event(self, mock_ping):