Package: django-mfw
django-mfwis a framework for developping mobile site with Django. The
following feature is availableDetect accessing device via HTTP_USER_AGENT and determine the device can
handle cookie or not.Non cookie based Session and Csrf protection for the devices which cannot
handle cookies.Dynamically change loading template via the device information. That’s
mean you can prepare the HTML template for each device (flavour template
system)Encode request and response via detected device encoding. It is required
because some Japanese mobile phone cannot handle UTF-8Translate Japanese Emoji in request and response to proper character code
or image for PC.NoteThis is under development. The codes below may not work.Installsudo pip install django-mfwor:sudo pip install git+git://github.com/lambdalisue/django-mfw.git#egg=django-mfwRequired (Automatically installed)e4u(emoji4unicode bundle framework)Quick tutorialAddmfwandmfw.contrib.emojito yourINSTALL_APPSsettings insettings.pyAddmfw.middleware.device.RequestDeviceDetectionMiddlewaretothe first
itemofMIDDLEWARE_CLASSESinsettings.pyandmfw.middleware.device.ResponseDeviceDetectionMiddlewaretothe last
itemofNoteThe following django-mfw middlewares are assumed that this middleware
has called before they are called.Addmfw.middleware.session.SessionMiddlewareandmfw.middleware.csrf.CsrfViewMiddlewareto yourMIDDLEWARE_CLASSESsetting andcomment outexisting middlewares.Addmfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddlewareandmfw.middleware.flavour.DeviceFlavourDetectionMiddlewareto yourMIDDLEWARE_CLASSESsetting.Addmfw.template.loaders.flavour.Loadertothe first itemofTEMPLATE_LOADERSsetting.Addmfw.context_processors.deviceandmfw.context_processors.flavourto yourTEMPLATE_CONTEXT_PROCESSORSsetting.The code below describe sample settings. Seesettings.pyfor more detail.:# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'mfw.template.loaders.flavour.Loader',
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'mfw.middleware.device.RequestDeviceDetectionMiddleware',

    'django.middleware.common.CommonMiddleware',
    #'django.contrib.sessions.middleware.SessionMiddleware',
    'mfw.middleware.session.SessionMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'mfw.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'mfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddleware',
    'mfw.middleware.flavour.DeviceFlavourDetectionMiddleware',

    'mfw.middleware.device.ResponseDeviceDetectionMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
    "mfw.context_processors.device",
    "mfw.context_processors.flavour",
)UsageDevice detectionrequest device is detected withmfw.middleware.device.DeviceDetectionMiddlewareand stored inrequest.devicethedeviceinstance has following attributesdevice.support_cookieis the device support cookie or not.device.kindA kind of this device. It is used for flavour template system.device.nameA name of this device. It is used for flavour template system.device.modelA model name of this device. It is used for flavour template system.device.versionA version name of this device. It is used for flavour template system.device.encodingA recommended encoding for the device. It is used to encode the request/responsedevice.carrier (additional)An attribute which Mobilephone device has. the carrier name of the device.device.uid (additional)An attribute which Mobilephone device has. User id which is passed from
carrier server.device.reliable (additional)An attribute which Mobilephone device has. IfFalsethen the
HTTP_USER_AGENT might be modified thus passed user id is not reliable
enough.Non cookie based Session and CSRF protectionDjango default session is saved on cookie because of security reason. However some device doesn’t support cookie
somfw.middleware.session.SessionMiddlewareuse carrier’s UID and django cache system for saving session.the middleware never try to use carrier’s UID for device which support cookie. it is only for the device which doesn’t support cookie
and commonly such device has carrier’s UID. Because of security, device accessed from out of carrier’s CIDR
is not trusted so it cannot save session if cookie is not supported.NoteTo accept non cookie based session for the device accessed from out of carrier’s CIDR, setMFW_IGNORE_NON_RELIABLE_MOBILEtoFalsebutIT IS STRONGLY NOT RECOMMENDEDUnicode emoji and Japanese carrier emoji conversionmfw.contrib.emoji.middleware.DeviceEmojiTranslationMiddlewarecare it. it detect device and automatically translate unicode emoji to
carrier’s encoded emoji in response. That’s why you do not need to care the code of emoji. Just write emoji as unicode emoji then
middleware translate everything correctly and encode response to carrier’s encodingIncoming translation is also handled the middleware. ifrequest.GETorrequest.POSThas carrier emoji, the middleware automatically
translate the carrier emojis to unicode emojis and decode value to unicode.Unicode emoji is found onhttp://www.unicode.org/~scherer/emoji4unicode/snapshot/full.html. this is a part ofemoji4unicodeproject
and translation method is using conversion table of it. seee4ufor more detail.Flavour template systemmfw.middleware.flavour.DeviceFlavourDetectionMiddlewaredetect device and automatically createflavourfor device.
the flavour is used for prefix of template_name. so if the flavour issmartphone/iphone/1.3and called template name isblogs/post_detail.htmlthenmfw.template.loaders.flavour.Loaderwill try to load the file listed below with template loaders listed inTEMPLATE_LOADERSexcept oneself.TEMPLATE_DIRECTORY/smartphone/iphone/1.3/blogs/post_detail.htmlTEMPLATE_DIRECTORY/smartphone/iphone/blogs/post_detail.htmlTEMPLATE_DIRECTORY/smartphone/blogs/post_detail.htmlTEMPLATE_DIRECTORY/blogs/post_detail.htmlmfw.template.loaders.flavour.Loaderis bundle loader and loading method is depended with template loaders listed inTEMPLATE_LOADERSso make sure you listed correct template loader inTEMPLATE_LOADERSSpecial thanksdjango-mfw’s concept is inspired bydjango-bpmobiledjango-mobileandemoji4unicode