Skip to main content
django-mashup
=============

django-mashup is a view masher for the Django Framework. Combine multiple views, templates, and/or Ajax loaded urls into a single class-based view.

Wrap those views in template-based containers.

Define different combinations of views and/or containers for different request types.

Installation
===============

Install the module in your Python distribution or virtualenv::

$ pip install git+https://github.com/SigmaEducation/django-mashup.git

Add the application to your `INSTALLED_APPS`::

```
INSTALLED_APPS = (...
"mashup",
...
)
```

Use
===

django-mashup provides one view class:

from mashup.views import MashUp

and three component classes:

from mashup.views import URLMash, TemplateMash, ViewMash

Example:

```
from django.core.urlresolvers import reverse
from mashup.views import MashUp, URLMash, TemplateMash

class MyMashup(MashUp):
views = [TemplateMash("my_app/my_login_instructions.html"),
URLMash(reverse('account:login')),
]

# my_app/my_login_instructions.html

<p>Use the following form to log in.</p>
```

Here's an example that mashes a view with HTML:

```
from django.views.generic.edit import FormView
from mashup.views import MashUp, TemplateMash, ViewMash

class MyFormView(FormView):
...

class MyMashup(MashUp):
views = [TemplateMash("my_app/my_login_instructions.html"),
ViewMash(MyFormView),
]
```

Each component class takes an optional container keyword argument. This should be a template name. Use '{{ mashup|safe }}' to specify where the content should be placed:

```
from django.core.urlresolvers import reverse
from mashup.views import MashUp, URLMash, TemplateMash

class MyMashup(MashUp):
views = [TemplateMash("my_app/my_login_instructions.html",
container="my_app/my_template.html"),
URLMash(reverse('account:login')),

...

# my_app/my_template.html

<div class=explanation>{{ mashup|safe }}</div>
```

The three component classes may be subclassed with default containers. The following MyMashup class will produce the same response as the one above:

```
from django.core.urlresolvers import reverse
from mashup.views import MashUp, URLMash, TemplateMash

class MyTemplateMash(TemplateMash):
container = "my_app/my_template.html"

class MyMashup(MashUp):
views = [MyTemplateMash("my_app/my_login_instructions.html"),
URLMash(reverse('account:login')),
]
```

The Mashup class may also be given default containers. Here's an abstract subclass of Mashup which takes two views and wraps them in the the divs #left-pane and #right-pane. Any Mashups which inherit from this Mashup will have their views contained in those divs:

```
from mashup.views import MashUp

class MyPaneMashup(Mashup):
containers = ('my_app/my_right_pane.html',
'my_app/my_left_pane.html',
)

...

# my_app/my_right_pane.html

<div id=right-pane>{{ mashup|safe }}</div>

...

# my_app/my_left_pane.html

<div id=right-pane>{{ mashup|safe }}</div>

```

Finally, you may define Mashup views and containers by request method: prefix 'views' or 'containers' with the lowercase name of the request method.

For example, your form views might respond with HTML to GET requests and JSON to POST requests; in this case you do not want your Mashup to attach HTML containers and content to POST response:

```
from mashup.views import Mashup, TemplateMash

from myapp.views import MyAjaxFormView


class MyFormMashup(Mashup):
get_views = (MyAjaxFormView,
TemplateMash("my_app/my_login_instructions.html", container="my_app/my_template.html"),
)
get_containers = ('my_app/my_right_pane.html',
'my_app/my_right_pane.html',)

post_views = (MyAjaxFormView,)
post_containers = ()
```
You may similarly define unique DELETE, PUT, TRACE, etc., views/containers.

Compatibility
=============

* Django Rest Framework 3.0.1
* Django 1.7
* Python 2.7, 3.4

Notes
=====
If you use a custom jquery or javascript function for loading page content via Ajax, you can specify that function by providing your own /templates/mashup/js_jquery_ajax_loader.html.


Getting Involved
================

Feel free to open pull requests or issues. GitHub is the canonical location of this project.

Metadata

Release files for django-mashup 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-mashup 0.7.1
File Size Uploaded
django-mashup-0.7.1.tar.gz 18.2 kB Details

Release files / django-mashup-0.7.1.tar.gz

Download URL django-mashup-0.7.1.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bed75176b54a4bda9f8023805fa01a76064c8684a79413ceeac35be524525027
BLAKE2b-256 checksum
How to use checksums
06a534a2109ca754d6130f48a0a74ca9e9703468194ba7ca2d7be4894d3f94d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.7.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page