Skip to content

Instantly share code, notes, and snippets.

View eugena's full-sized avatar
💭
🤸🏽

Eugena Mikhaylikova eugena

💭
🤸🏽
View GitHub Profile
uwsgi --socket /var/run/uwsgi/application_name --env DJANGO_SETTINGS_MODULE=application_name.settings --module application_name.wsgi:application --chmod-socket=664
@eugena
eugena / django_form_mixins.py
Last active September 1, 2015 11:25
Form mixins for django
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
class LoginRequiredMixin(object):
"""
LoginRequired Mixin
"""
@classmethod
def as_view(cls, **initkwargs):
@eugena
eugena / django_tests_mixins.py
Last active September 11, 2015 13:13
Test mixins for django
class RedirectChainAnalysisMixin(object):
"""
A mixin to check if a redirect chain of response is correct
Must be used with Django TestCase object
"""
def chain_check(self, response, needed):
"""
Checks a chain
@eugena
eugena / django_jsonable_form_mixin.py
Last active September 11, 2015 13:38
Mixin to adding AJAX support to a form view.
from django.http import JsonResponse
from django.conf import settings
from django_remote_forms.forms import RemoteForm
class JsonableFormMixin(object):
"""
Mixin to adding AJAX support to a form view.
Must be used with django model editing views
@eugena
eugena / django_prototype_of_base_view.py
Last active September 16, 2015 13:40
The prototype of BaseFormView when form rendering executes in one layer, but validation and object saving in another
class PrototypeOfBaseView(FormView):
"""
The prototype of base view, which allows to render a form
by Django Form framework, but to validate and save data by API framework
"""
template_name = None
serializer_class = None
fields = None
import importlib
from django.conf import settings
from django.contrib.auth import SESSION_KEY
def get_id_by_session_key(session_key):
"""
Returns user identifier by session_key
"""
class PasswordSerializer(serializers.ModelSerializer):
"""
Changes user password
"""
old_password = serializers.CharField(required=True)
new_password = serializers.CharField(required=True)
_required_fields = ['old_password', 'new_password']
@eugena
eugena / gocardless.view.py
Created November 10, 2015 10:49
GoCardlessMixin
from django.conf import settings
import gocardless_pro
class GoCardless(object):
"""
GoCardless wrapper
"""
def __init__(self):
self.client = gocardless_pro.Client(
@eugena
eugena / hybrid_field.py
Created November 10, 2015 11:08
Writable hybrid of PrimaryKeyRelated and SerializerMethod Fields
from rest_framework import serializers
class HybridPrimaryKeyRelatedAndSerializerMethodField(serializers.PrimaryKeyRelatedField):
"""
PrimaryKeyRelatedField & SerializerMethodField
"""
def __init__(self, method_name=None, **kwargs):
self.method_name = method_name
super(HybridPrimaryKeyRelatedAndSerializerMethodField, self).__init__(**kwargs)
@eugena
eugena / csrf_exempt_authentication.py
Created November 12, 2015 10:46
SessionAuthentication without csrf token check
from rest_framework.authentication import SessionAuthentication
class CsrfExemptSessionAuthentication(SessionAuthentication):
"""
SessionAuthentication without csrf token check
"""
def enforce_csrf(self, request):
"""
Not performing csrf token check