Compatible Django Middleware

kichik's blog

Django 1.10 added a new style of middleware with a different interface and a new setting called MIDDLWARE instead of MIDDLEWARE_CLASSES. Creating a class that supports both is easy enough with MiddlewareMixin, but that only works with Django 1.10 and above. What if you want to create middleware that can work with all versions of Django so it can be easily shared?

Writing a compatible middleware is not too hard. The trick is having a fallback for when the import fails on any earlier versions of Django. I couldn’t find a full example anywhere and it took me a few attempts to get it just right, so I thought I’d share my results to save you some time.

CompatibleMiddleware can now be used in both MIDDLWARE and MIDDLEWARE_CLASSES. It should also work with any version of Django so it’s easier to share.

View original post

Advertisements

How to Install & Set Up FreeBSD with A Desktop Environment

AntumDeluge

*!!!* This tutorial is a work in progress *!!!*

This tutorial is written for FreeBSD 10.0.

Don’t know what BSD is? Check out this page.

Contents

Installing Base System

— The FreeBSD Boot Loader —

First boot into the FreeBSD installation media (cd/dvd/usb). The boot loader will display:

FreeBSD Boot Loader

When the boot loader is displayed press “1” or “Enter” to boot into multi-user mode (Note: You can pause the boot loader timer by press the space bar). If booting fails restart & try changing some boot settings from the boot loader or try single-user mode. Once the machine has booted…

View original post 1,618 more words

Zend Framework 2 : Create Simple Upload Form with File Validation

Welcome to Abdul Malik Ikhsan's Blog

Zend Framework 2 has ZendFileTransfer component that can provide file transfer need for our application. We can add Files validator and pass error message to ZendForm component object, that can be retrieve by view if process was failed. We can add another validator instead of Upload validator that registered by default in Http Adapter.


For example, i have upload form like this :


The code form will be like the following :

By that code above, we can call ProfileForm from action Controller :

For view, we can write the following :

Just that, and form will be created. How we filter the input ? we can create input filter by following :

Now, we can set inputFilter to form from action controller, pass data post and file to form object, and check the validation :

If form is valid, we can save file to directory we desired by ZendFileTransferAdapterHttp…

View original post 57 more words