src/iconolab/views.py
author Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
Thu, 16 Jun 2016 12:26:13 +0200
changeset 20 91e7f0429e4f
parent 8 7e49ce535296
child 22 2c58c2c0d7f6
permissions -rw-r--r--
editing urls.py to add new annotations views
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
     1
from django.shortcuts import HttpResponse, get_object_or_404, render, redirect
6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     2
from iconolab.models import Annotation
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     3
from django.http import Http404
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     4
from django.contrib.auth.decorators import login_required
20
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
     5
from .forms import AnnotationForm
6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     7
@login_required
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     8
def index(request):
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
     9
	print(request.user)
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    10
	return HttpResponse("<p>Home</p>");
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    11
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    12
8
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    13
def draw_fragment(request, pk):
6
37baf9d13f32 first commit
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff changeset
    14
	annotation = get_object_or_404(Annotation, pk=pk)
8
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    15
	return render(request, 'iconolab/fragment_draw.html', {'annotation': annotation})
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    16
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    17
def create_annotation(request):
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    18
	return render(request, 'iconolab/create_annotation.html')
20
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    19
	pass
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    20
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    21
def show_annotation(request, pk):
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    22
	annotation = get_object_or_404(Annotation, pk=pk)
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    23
	return render(request, 'iconolab/show_annotation.html', {'annotation': annotation}) 
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    24
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    25
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    26
# save annotation
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    27
# handle revision
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    28
def save_annotation(request):
8
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    29
	pass
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    30
7e49ce535296 fragment editor
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 6
diff changeset
    31
def edit_annotation(request, pk):
20
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    32
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    33
	#enregistrer title, description, fragment:nmz
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    34
	annotation = get_object_or_404(Annotation, pk=pk)
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    35
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    36
	if request.method == 'POST':
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    37
		Annotation_form = AnnotationForm(request.POST, instance=annotation)
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    38
		Annotation_form = AnnotationForm()
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    39
		if Annotation_form.is_valid():
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    40
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    41
			#redirect to view
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    42
			pass
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    43
	else:
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    44
		Annotation_form = AnnotationForm(instance = annotation)
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    45
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    46
	return render(request, 'iconolab/edit_annotation.html', {'annotation': annotation, 'form': Annotation_form }) 
91e7f0429e4f editing urls.py to add new annotations views
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents: 8
diff changeset
    47