from django.conf import settings
from django.core.cache import cache, get_cache
from django.utils.importlib import import_module
class UserRestrictMiddleware(object):
def process_request(self, request):
"""
Checks if different session exists for user and deletes it.
"""
if request.user.is_authenticated():
cache = get_cache('default')
cache_timeout = 86400
cache_key = "user_pk_%s_restrict" % request.user.pk
cache_value = cache.get(cache_key)
if cache_value is not None:
if request.session.session_key != cache_value:
engine = import_module(settings.SESSION_ENGINE)
session = engine.SessionStore(session_key=cache_value)
session.delete()
cache.set(cache_key, request.session.session_key,
cache_timeout)
else:
cache.set(cache_key, request.session.session_key, cache_timeout)
System.loadLibrary()
ищет библиотеку в java.library.path. В разных системах это свойство содержит разное значение по умолчанию:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews">
<com.example.customviews.MyEditText
android:id="@+id/my_input"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="My text"
/>
</LinearLayout>
MyEditText text = (MyEditText) findViewById(R.id.my_input)
from django.apps import apps
from django.core import serializers
# Получаем список всех моделей всех приложений из INSTALLED_APPS
# и фильтруем django'вские
models = [model for model in apps.get_models() if not model.__module__.startswith('django')]
# Сериалзиуем в json полный QuerySet каждой модели
dump = ''
for m in models:
dump += serializers.serialize('json', m._default_manager.all())
class NewsAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "category":
kwargs["queryset"] = Category.objects.filter(some_parameter=some_value)
return super(NewsAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
(defproject spa-tutorial "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.521"]
[org.clojure/core.async "0.3.442"]
[org.omcljs/om "0.9.0"]
[prismatic/om-tools "0.4.0"]
[http-kit "2.3.0-alpha2"]
[secretary "1.2.3"]]
:plugins [[lein-cljsbuild "1.1.6"]]
:source-paths ["src" "target/classes"]
:clean-targets ["out/spa_tutorial" "out/spa_tutorial.js"]
:cljsbuild {
:builds [{:id "spa-tutorial"
:source-paths ["src"]
:compiler {
:main spa-tutorial.core
:output-to "out/spa_tutorial.js"
:output-dir "out"
:optimizations :none
:verbose true}}]})