Skip to content

Instantly share code, notes, and snippets.

View eugena's full-sized avatar
💭
🤸🏽

Eugena Mikhaylikova eugena

💭
🤸🏽
View GitHub Profile
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']
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
"""
@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
@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_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_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):
uwsgi --socket /var/run/uwsgi/application_name --env DJANGO_SETTINGS_MODULE=application_name.settings --module application_name.wsgi:application --chmod-socket=664