Permalink
Browse files

view serie and api to add frame

  • Loading branch information...
1 parent 5f3a382 commit e8fc3d92028ab0f96a7529f6ade26df874118c68 @danieleguido committed Mar 8, 2013
Showing with 46 additions and 15 deletions.
  1. +28 −2 glue/api.py
  2. +5 −1 glue/forms.py
  3. +0 −1 glue/models.py
  4. +2 −2 templates/walt/boilerplate.html
  5. +7 −5 templates/walt/index.html
  6. +1 −1 walt/urls.py
  7. +3 −3 walt/views.py
View
@@ -10,7 +10,7 @@
from glue import Epoxy, API_EXCEPTION_FORMERRORS, API_EXCEPTION_INTEGRITY, API_EXCEPTION_DOESNOTEXIST, API_EXCEPTION_OSERROR
from glue.models import Page, Pin, Tag, Serie, Frame
-from glue.forms import AddPageForm, AddPinForm, EditPinForm, UploadPinForm, AddSerieForm
+from glue.forms import AddPageForm, AddPinForm, EditPinForm, UploadPinForm, AddSerieForm, AddFrameForm
logger = logging.getLogger(__name__)
@@ -89,17 +89,43 @@ def series( request ):
def serie( request, serie_id ):
return Epoxy( request ).single( Serie, {'id':serie_id} ).json()
+
+
@login_required
def serie_frames( request, serie_id ):
response = Epoxy( request )
try:
serie = Serie.objects.get( id=serie_id )
+
+ # gimme series !
+ series = dict([(s.language,s) for s in Serie.objects.filter( slug=serie.slug ) ])
+
except Serie.DoesNotExist, e:
return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST ).json()
+ if response.method == 'POST':
+ form = AddFrameForm( request.REQUEST )
+ if not form.is_valid():
+ return response.throw_error( error=form.errors, code=API_EXCEPTION_FORMERRORS).json()
+
+ # check exhistence
+ for s in series:
+
+ try:
+ # ( serie.slug )
+ frame = Frame( pin=Pin.objects.get( language=series[s].language, slug=form.cleaned_data['slug'] ), sort=form.cleaned_data['sort'] )
+ frame.save()
+ except IntegrityError,e:
+ return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
+
+
+ series[s].frames.add( frame )
+ series[s].save()
+
+ response.add( 'object', frame.json() )
- response.add( 'object', serie.json(load_frames=True))
+ response.add( 'object', serie.json(load_frames=True) )
return response.json()
@login_required
View
@@ -2,7 +2,7 @@
from django.forms import ModelForm
from django.utils.translation import ugettext as _
from django.conf import settings
-from glue.models import Tag, Serie
+from glue.models import Tag, Serie, Frame
class LoginForm(forms.Form):
username = forms.CharField( label=_('login'), max_length=64 )
@@ -32,6 +32,10 @@ def __init__(self, *args, **kwargs):
type = forms.ChoiceField( label=_("type"), required=True, choices=Serie.TYPE_CHOICES )
+class AddFrameForm(forms.Form):
+ slug = forms.SlugField( required=True )
+ type = forms.ChoiceField( label=_("type"), required=True, choices=Frame.TYPE_CHOICES )
+ sort = forms.IntegerField( min_value=1 )
class AddPinForm(forms.Form):
View
@@ -175,7 +175,6 @@ class Frame( models.Model ):
def json( self ):
return{
'id': self.id,
- 'serie':self.serie.id,
'duration': self.duration,
'sort': self.sort,
'abstract': self.abstract,
@@ -79,8 +79,8 @@
add_pin : "{% url glue_api_pins %}"
}
- oo.urls.add_serie = "{% url glue_api_serie %}";
- oo.urls.edit_serie = "{% url glue_api_serie %}";
+ oo.urls.add_serie = "{% url glue_api_serie 0 %}";
+ oo.urls.edit_serie = "{% url glue_api_serie 0 %}";
$(document).ready( function(){
oo.api.init();
View
@@ -5,18 +5,20 @@
{% block page %}
<div class="grid_12">
- <h2 style="border-width:0px">{% trans "series" %} ( {{ series.count }} )</h2>
+ <h2>{% trans "series" %} ( {{ series.count }} )<div class="description"><a href="#">{% trans "add serie" %}</a></div></h2>
- <div class="series">
- <a href="{% url admin:glue_serie_add %}">{% trans "add serie" %}</a>
+ <div class="series" style="border-bottom: 1px solid #ccc">
+
{% for serie in series %}
<div class="serie">
<div class="title">{{ serie.title }}. <span><a href="{% url walt_serie serie.slug %}">play #{{ serie.id }}</a></span></div>
- <div class="frames">
+ <div class="frames" style="border-bottom: 1px solid #ccc; padding-bottom: 10px; margin-bottom: 10px">
+ start &rarr;
{% for frame in serie.frames.all %}
- <span><a href="{% url admin:glue_frame_change frame.id %}"> {{ frame.title }}</a></span>
+ <span><a href="{% url admin:glue_frame_change frame.id %}" title="{{ frame.pin.title }}"> {{ frame.role }} {{ frame.type }}</a></span> &rarr;
{% endfor %}
+ end.
</div>
<div class="timeline">
View
@@ -35,7 +35,7 @@
url(r'^u/(?P<username>[a-z\.]+)/$', 'walt.views.spiff', name='walt_spiff'),
url(r'^tag/(?P<tag_type>[a-z\-]+)/(?P<tag_slug>[a-zA-Z\d\-]+)/', 'walt.views.tag', name='walt_tag'),
- url(r'^serie/(?P<serie_slug>[a-zA-Z\d\-]+)/', 'walt.views.serie', name='walt_serie'),
+ url(r'^serie/(?P<serie_slug>[a-zA-Z\_\d\-]+)/', 'walt.views.serie', name='walt_serie'),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
View
@@ -116,7 +116,7 @@ def logout_view( request ):
def home( request ):
data = sc( request, tags=[ "home" ] )
- data['series'] = Serie.objects.all()
+ data['series'] = Serie.objects.filter( language=data['language'] ).order_by( '-date_last_modified' )[:3]
return render_to_response( "walt/index.html", RequestContext(request, data ) )
@@ -140,14 +140,14 @@ def tag( request, tag_type, tag_slug ):
def pin( request, pin_slug ):
data = sc( request, tags=[ "pin" ] )
data['pin'] = get_object_or_404( Pin, language=data['language'], slug=pin_slug )
- data['series'] = Serie.objects.filter( frame__pin__slug=pin_slug ).distinct()
+ data['series'] = Serie.objects.filter( frames__pin__slug=pin_slug ).distinct()
return render_to_response( "walt/pin.html", RequestContext(request, data ) )
@login_required
def serie( request, serie_slug ):
data = sc( request, tags=[ "serie" ] )
- data['serie'] = get_object_or_404( Serie, slug=serie_slug )
+ data['serie'] = get_object_or_404( Serie, slug=serie_slug, language=data['language'] )
return render_to_response( "walt/serie.html", RequestContext(request, data ) )

0 comments on commit e8fc3d9

Please sign in to comment.