~doctormo/erato/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Copyright 2010, Martin Owens.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from art_website.settings import MEMORY_CACHE
from django import template
from django.template import Context, loader, RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response

from art_website.assets.models import *
from forms import CreationForm
import sys
import json

def new(request):
    """Create a new Creation with uploads and everything"""
    rc = RequestContext(request)
    if request.method == 'POST':
        form = CreationForm(request.POST)
        if form.is_valid():
            # [[ Process the data in form.cleaned_data ]]
            # Once we have made the creation object we can assign
            # All the asset objects to this creation object.
            return HttpResponseRedirect('art/item/%d/' )#% obj.oid)
    else:
        form = CreationForm()
    dc = {
         'uuid' : 1,
         'form' : form,
    }
    return render_to_response('creations/new.html', dc, context_instance=rc)


def index(request):
    """Return an index of all types"""
    rc = template.RequestContext(request)
    return render_to_response('creations/browse.html', {}, context_instance=rc)


def item(request, asset_id):
    """Return a single creation page"""
    type_obj = get_object_or_404(Asset, id=asset_id)
    uploads = ContentUpload._default_manager.all().order_by('published')
    c = {
        'type' : type_obj,
        'recent_uploads' : uploads.filter(contentype=type_id)[15:]
    }
    rc = template.RequestContext(request)
    return render_to_response('creations/item.html', c, context_instance=rc)