Permalink
Browse files

push frames api ! done, with pin slug and ordering.

  • Loading branch information...
1 parent bc941df commit 74dc75aedc2a311af3a0de2a6472dc3e73cf28eb @danieleguido committed Mar 14, 2013
Showing with 335 additions and 193 deletions.
  1. +1 −0 glue/__init__.py
  2. +46 −19 glue/api.py
  3. +8 −1 static/js/oo.js
  4. +55 −5 static/js/oo/glue.js
  5. +1 −1 static/js/oo/rice.js
  6. +31 −6 static/less/style.less
  7. +36 −20 templates/walt/index.html
  8. +155 −139 templates/walt/middle.html
  9. +2 −2 walt/views.py
View
@@ -15,6 +15,7 @@
API_AVAILABLE_METHODS = [ 'DELETE', 'POST', 'GET' ]
API_EXCEPTION = 'GenericException'
API_EXCEPTION_INTEGRITY = 'IntegrityError'
+API_EXCEPTION_VALUE = 'ValueError'
API_EXCEPTION_DOESNOTEXIST = 'DoesNotExist'
API_EXCEPTION_DUPLICATED = 'Duplicated'
API_EXCEPTION_FORMERRORS = 'FormErrors'
View
@@ -1,4 +1,4 @@
-import logging, os, mimetypes
+import logging, os, mimetypes, json
import datetime as dt
from django.conf import settings
@@ -9,7 +9,7 @@
from django.utils.translation import get_language
from django.template.defaultfilters import slugify
-from glue import Epoxy, API_EXCEPTION_FORMERRORS, API_EXCEPTION_INTEGRITY, API_EXCEPTION_DOESNOTEXIST, API_EXCEPTION_OSERROR, API_EXCEPTION
+from glue import Epoxy, API_EXCEPTION_FORMERRORS, API_EXCEPTION_INTEGRITY, API_EXCEPTION_DOESNOTEXIST, API_EXCEPTION_OSERROR, API_EXCEPTION, API_EXCEPTION_VALUE
from glue.models import Page, Pin, Tag, Serie, Frame
from glue.forms import AddPageForm, AddPinForm, EditPinForm, UploadPinForm, AddSerieForm, AddFrameForm
@@ -98,50 +98,77 @@ def series( request ):
def serie( request, serie_id ):
return Epoxy( request ).single( Serie, {'id':serie_id} ).json()
+from django.db import transaction
@login_required( login_url=settings.GLUE_ACCESS_DENIED_URL )
+@transaction.commit_manually
def serie_frames( request, serie_id ):
response = Epoxy( request )
try:
serie = Serie.objects.get( id=serie_id )
- # gimme series !
+ # gimme every language series !
series = dict([(s.language,s) for s in Serie.objects.filter( slug=serie.slug ) ])
except Serie.DoesNotExist, e:
+ transaction.rollback()
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:
+ frames = request.REQUEST.get('frames','')
+ try:
+ frames = response.add( 'frames', json.loads(frames ) );
+ except ValueError, e:
+ transaction.rollback() # no json found!
+ return response.throw_error( error="%s" % e, code=API_EXCEPTION_VALUE).json()
+
+ # matching slug: no other control needed
+ matching_slugs = Pin.objects.filter( slug__in=[f['slug'] for f in frames ], language=settings.LANGUAGES[0][0] ).count()
+ response.add( 'matching slugs',matching_slugs )
+
+ if matching_slugs != len( frames ):
+ transaction.rollback()
+ return response.throw_error( error="some pin does not exist", code=API_EXCEPTION_DOESNOTEXIST ).json()
+
- 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 Pin.DoesNotExist, e:
- return response.throw_error( error="%s" % e, code=API_EXCEPTION_DOESNOTEXIST ).json()
- except IntegrityError,e:
- return response.throw_error( error="%s" % e, code=API_EXCEPTION_INTEGRITY).json()
+ for language in series:
+ l = language
+ for f in frames:
+ try:
+ frame = Frame.objects.get( serie=series[ language ], pin__slug=f['slug' ], pin__language=language )
+ except Frame.DoesNotExist, e:
+
+ frame = Frame( pin=Pin.objects.get( slug=f[ 'slug' ], language=language ) )
+ frame.save()
+ series[ language ].frames.add( frame )
+ else:
+ transaction.commit()
- series[s].frames.add( frame )
- series[s].save()
+ frame.sort = f['sort']
+ frame.save()
- response.add( 'object', frame.json() )
+ transaction.commit()
+
response.add( 'object', serie.json(load_frames=True) )
+ transaction.commit()
return response.json()
@login_required( login_url=settings.GLUE_ACCESS_DENIED_URL )
def frames( request, serie_id ):
response = Epoxy( request )
+
+ if response.method == 'POST':
+ # json with sorting mechanism {}
+
+ lista = json.load( request.REQUEST.get('frames') )
+
+ response.add( 'object', lista);
# add a dictonary of frame : sort
return response.queryset( Frame.objects.filter( serie__authors=request.user ) ).json()
View
@@ -234,6 +234,12 @@ oo.fn.get_cookie = function (e){
var t=null;if(document.cookie&&document.cookie!=""){var n=document.cookie.split(";");for(var r=0;r<n.length;r++){var i=jQuery.trim(n[r]);if(i.substring(0,e.length+1)==e+"="){t=decodeURIComponent(i.substring(e.length+1));break}}}return t
};
+oo.fn.wait = function( fn, delay ){
+ var timer = md5( fn.toString() + delay );
+ clearTimeout( oo.vars[ timer ] );
+ oo.vars[ timer ] = setTimeout( fn, delay );
+
+}
/*
@@ -295,7 +301,8 @@ oo.i18n.dict = {
*/
oo.fn.bibtex = function ( bibtex ){
- var bibjson = bibtex.replace(/(\w+)\s*=\s*\{+/g,"\"$1\": \"")
+ var bibjson = bibtex.replace(/^\s+|\s+$/g,'')
+ .replace(/(\w+)\s*=\s*\{+/g,"\"$1\": \"")
.replace(/\}+(?=\s*[,\}+])/g,"\"")
.replace(/@(\w+)\s*\{([^,]*)/,"{\"bibtext_key\":\"$1\",\"$1\": \"$2\"");
oo.log( bibjson )
View
@@ -45,7 +45,22 @@ oo.magic.pin.get = function( result ){
oo.glue = {};
oo.glue.resize = function(){
var h = $(window).height();
+
+ if ( h < 600){
+ $("#navbar .description").hide();
+ } else {
+ $("#navbar .description").show();
+ }
+
+ var hh = $("header").height();
+ var fh = $("footer").height();
+
+
$(".modal-body").height( h - 160 );
+
+ //$(".items").height(
+ // h - hh - fh
+ //);
}
oo.glue.init = function(){ oo.log("[oo.glue.init]");
@@ -58,11 +73,16 @@ oo.glue.init = function(){ oo.log("[oo.glue.init]");
// input.repeatable: copy $.val() to targeted data-target element
$(document).on('keyup', 'input.repeatable', function(event){ var $this = $(this); $( '#' + $this.attr('data-target') ).val( oo.fn.slug( $this.val() ) );});
+
+ $(document).on('keyup', 'textarea.embeddable', oo.glue.embed.keyup );
+
+
+
// remove invalid elements
$(document).click( function(event){ $(".invalid").removeClass('invalid');});
// modal max height
- oo.on('resize', oo.glue.resize );
+ oo.on('resize', function(){ oo.fn.wait( oo.glue.resize, 100 );});
oo.glue.resize()
// generic pin adder to walt page, with error control
@@ -125,6 +145,35 @@ oo.glue.init = function(){ oo.log("[oo.glue.init]");
};
+oo.glue.embed = {};
+// clean a textarea
+oo.glue.embed.keyup = function( event ){
+ var el = $(this);
+ var content = el.val().replace(/^\s+|\s+$/g,'');
+ var url = "";
+
+
+
+ try{
+ url = content.match(/src=(?!\s)['"]?(.+?)[\s"']/).pop()
+ } catch( e ){
+ el.val( content );
+ oo.toast()
+ return;
+ }
+
+
+ // replave numeric pixel width 100%
+ el.val( content.replace(/width=(?!\s)["']?([\dpx\%]+)[\s'"]/g,'width="100%"') );
+
+ //
+ $('#' + el.attr('data-target-permalink')).val( url );
+
+
+};
+
+
+
oo.glue.bibtex = { timer:0 }
oo.glue.bibtex.wait = function( event ){
clearTimeout( oo.glue.bibtex.timer );
@@ -133,17 +182,18 @@ oo.glue.bibtex.wait = function( event ){
oo.glue.bibtex.parse = function(){
try{
- var bib = oo.fn.bibtex( $("#id_add_pin_content").val() );
- $("#id_add_pin_title_en").val( bib.title );
- $("#id_add_pin_slug").val( oo.fn.slug( bib[ bib.bibtext_key ] ) );
+ var bib = oo.fn.bibtex( $("#id_add_walt_l_content").val() );
+ oo.log( bib );
+ $("#id_add_walt_l_title_en").val( bib.title );
+ $("#id_add_walt_l_slug").val( oo.fn.slug( bib[ bib.bibtext_key ] ) );
} catch( e ){
oo.log( e );
}
}
oo.glue.bibtex.init = function(){
// content as bibtext parser !@!
- $("#id_add_pin_content").on("keyup", oo.glue.bibtex.wait );
+ $("#id_add_walt_l_content").on("keyup", oo.glue.bibtex.wait );
}
View
@@ -178,7 +178,7 @@ oo.rice.Serie = function( options ){
}
this.add = function( event ){
- $('#add-serie-modal').reveal(); $("#id_add_serie_title_en").focus();
+ $("#id_add_serie_title_en").focus();
}
/*
View
@@ -43,13 +43,24 @@ header{
width: 100%;
background-color: white;
overflow: auto;
+ a{
+ line-height: 20px;
+ }
+ a.active{
+ border-top: 1px solid #08c;
+ }
}
#navbar{
background-color: white;
h2{
border-bottom: 0px solid transparent;
+
+
+ margin-top: 0;
+ padding-top: @grid-padding / 2;
+ margin-bottom: 0;
padding-bottom: @grid-padding / 2;
}
@@ -100,6 +111,12 @@ h2{
}
}
+.items{
+ // height: 200px;
+ // min-height: 200px;
+ // overflow-y:auto;
+}
+
.item{
margin-bottom: @grid-padding;
@@ -169,9 +186,18 @@ h2{
float:left;
.spring( 0, 0, 1, 2, url("../../img/frame_types.png") );
-
- &:hover{
- .spring-position(1, 0);
+
+ &.augment{
+ .spring-position(0, 2);
+ &:hover{
+ .spring-position(1, 2);
+ }
+ }
+
+ &.wander{
+ &:hover{
+ .spring-position(1, 0);
+ }
}
}
@@ -264,9 +290,8 @@ input[type="text"]{
-moz-border-radius: 0px;
border-radius: 0px
}
-
-input, button, select, textarea {
- .mono(16px)
+select, button, textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
+ .mono(13px)
}
Oops, something went wrong.

0 comments on commit 74dc75a

Please sign in to comment.