Permalink
Browse files

timeline preparation

  • Loading branch information...
1 parent 81dff99 commit f18b360787b381ff4f4889d26081a68b18c174e5 @danieleguido committed Mar 6, 2013
Showing with 163 additions and 33 deletions.
  1. +27 −19 glue/api.py
  2. +14 −0 static/js/oo.js
  3. +84 −0 static/js/oo/rice.js
  4. +2 −0 templates/walt/boilerplate.html
  5. +5 −1 templates/walt/index.html
  6. +19 −5 templates/walt/middle.html
  7. +12 −8 walt/views.py
View
@@ -106,25 +106,33 @@ def pins( request ):
#already linked permalink?
permalink_hash = ''
+ is_a_clone = False
# handle aliases
if len( form.cleaned_data['permalink'] ) > 0:
import hashlib
permalink_hash = hashlib.md5( form.cleaned_data['permalink'] ).hexdigest()
+ is_a_clone = Pin.objects.filter( permalink_hash=permalink_hash ).count() > 0
- aliases = Pin.objects.filter( permalink_hash=permalink_hash )
- if aliases.count() > 0:
- for a in aliases:
- a.authors.add( request.user )
-
- if len(pins) > 0:
- a.parent = pins[ a.language ]
-
- a.save()
+
+ for language,l in settings.LANGUAGES:
+ ipin = None
+ if is_a_clone:
+ # content exists in some language
+ try:
+ ipin = Pin.objects.get( permalink_hash=permalink_hash, language=language )
+ ipin.authors.add( request.user )
+ ipin.save()
+
+
+ except Pin.DoesNotExist, e:
+ # pin has not been created for a certain language...
+ pass
+
- else:
- for language,l in settings.LANGUAGES:
+ if ipin is None:
+ # it is an original import.
try:
ipin = Pin( title=form.cleaned_data[ 'title_%s' % language ], language=language, slug=form.cleaned_data[ 'slug' ], permalink=form.cleaned_data['permalink'], permalink_hash = permalink_hash,content=form.cleaned_data['content'], mimetype=form.cleaned_data['mimetype'] )
@@ -135,16 +143,16 @@ def pins( request ):
except IntegrityError, e:
return response.throw_error( error={'slug':"Exception %s" % e}, code=API_EXCEPTION_INTEGRITY).json()
- if len(pages) > 0:
- pages[ language ].pins.add( ipin )
- pages[ language ].save()
+ if len(pages) > 0:
+ pages[ language ].pins.add( ipin )
+ pages[ language ].save()
- if len(pins) > 0:
- ipin.parent = pins[ language ]
- ipin.save()
+ if len(pins) > 0:
+ ipin.parent = pins[ language ]
+ ipin.save()
- return response.json()
- # response.add('object',[ p.json() for p in ipins ])
+ #return response.json()
+ #response.add('object',[ p.json() for p in ipins ])
return response.queryset( Pin.objects.filter() ).json()
View
@@ -19,6 +19,20 @@ oo.log = function(){
}
}
+/*
+
+
+ WINDOW On / Trigger helpers
+ ===========================
+*/
+oo.on = function( eventType, callback ){
+ $(window).on( eventType, callback );
+};
+
+oo.trigger = function ( eventType, data ){
+ $(window).trigger( eventType, data );
+};
+
/*
View
@@ -0,0 +1,84 @@
+var oo = oo || {}; oo.rice = {};
+
+/*
+
+
+ Magic
+ =====
+
+*/
+oo.magic = oo.magic || {};
+
+
+
+/*
+
+
+ Rice UI
+ =======
+
+*/
+oo.rice = oo.rice || {};
+
+oo.rice.dragstart = function( event ){
+ $("#actual-serie").height( 40 );
+}
+
+oo.rice.append = function( event ){
+ if (typeof oo.rice.serie == "undefined" ){
+ // default serie
+ oo.rice.serie = new oo.rice.Serie();
+ }
+ oo.trigger( oo.rice.events.append, {what:'me'});
+}
+
+oo.rice.init = function(){oo.log("[oo.rice.init]");
+
+ // load last serie from cookie
+ oo.rice.serie = new oo.rice.Serie({ autoload:true });
+
+ $(document).on('click','.drag-to-serie',oo.rice.append );
+
+
+}
+
+oo.rice.events = {
+ 'append':'oo.rice.events.add',
+ 'change':'oo.rice.events.change',
+ 'clean':'oo.rice.events.clean',
+ 'init':'oo.rice.events.init',
+ 'replace':'oo.rice.events.replace',
+ 'remove':'oo.rice.events.remove',
+ 'reset':'oo.rice.events.reset'
+};
+
+/*
+
+
+ Serie Class
+ ===========
+
+*/
+oo.rice.Serie = function( options ){
+
+
+ this.settings = $.extend({
+ autoload: false
+ }, options );
+
+ this.append = function( event, data ){
+ oo.log( event, data );
+ };
+
+ this.init = function(){
+ // if options.autoload:
+
+ oo.log( "[oo.rice.Serie] Serie object created", this.settings );
+
+ // enable listeners
+
+ oo.on( oo.rice.events.append, this.append );
+ }
+
+ this.init();
+}
@@ -69,6 +69,7 @@
<script src="{{ STATIC_URL }}/js/oo.js"></script>
<script src="{{ STATIC_URL }}/js/oo/glue.js"></script>
+ <script src="{{ STATIC_URL }}/js/oo/rice.js"></script>
<script src="{{ STATIC_URL }}/js/walt.js"></script>
<script>
@@ -78,6 +79,7 @@
$(document).ready( function(){
oo.api.init();
oo.glue.init();
+ oo.rice.init();
});
</script>
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
@@ -68,7 +68,11 @@ <h2 style="border-width:0px">{% trans "series" %} ( {{ series.count }} )</h2>
{% if not forloop.last %}, {% endif %}
{% endfor %}
</p>
- <p><a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a></p>
+ <p>
+ <a href="{% url admin:glue_pin_change pin.id %}">&rarr; {% trans "edit" %}</a>
+ <div style="float:left" draggable="true" class="drag-to-serie" >&curren; {% trans "drag" %}</div>
+
+ </p>
</div>
<blockquote>
{{ pin.abstract }}
View
@@ -1,8 +1,10 @@
{% extends "walt/boilerplate.html" %}
{% load i18n %}
+
{% block body %}
- <div class="container_12">
+
+ <div class="container_12" style="margin-bottom:201px">
<div class="grid_12">
<h1><a href="{% url walt_home %}">{% block spiffing %}{% endblock %} walt.</a></h1>
@@ -14,22 +16,34 @@
{% endif %}
</div>
-
- {% block page %}
+ {% if exception %}
+ <div class="grid_12">
+ <h2>maybe you want to <a href="{% url walt_setup %}">SETUP</a> first ?</h2>
- {% endblock %}
+ </div>
+ {% else %}
+ {% block page %}
+ {% endblock %}
+ {% endif %}
{% block footer %}
<div class="grid_12">
language:{{ language }} {% for language in languages %} {{ language }}{%if not forloop.last %}, {%endif%}{% endfor %}
{{ warnings }}
</div>
+
+
{% endblock %}
</div>
+ <!-- ACTLUA SERIE DROP -->
+ <div id="actual-serie" style="position:fixed; bottom: 0px; height:30px; width: 100%; background: #2bbfbd; color: white; line-height:30px; padding: 0 20px">
+ drag an element to start a new serie
+ </div>
+
{% ifequal page.slug 'learn' %}
<div id="add-pin-modal" class="reveal-modal">
<h1>{% trans "bibtext" %}</h1>
@@ -137,5 +151,5 @@
<a class="close-reveal-modal">&#215;</a>
</div>
{% endifequal %}
-
+
{% endblock %}
View
@@ -43,6 +43,7 @@ def sc( request, tags=[], d={}, load_walt=True, username=None ):
d['language'] = get_language()
d['languages'] = dict( settings.LANGUAGES )
d['warnings'] = {}
+ d['exception'] = False
d['walt'] = {}
d['spiff'] = ""
@@ -51,14 +52,17 @@ def sc( request, tags=[], d={}, load_walt=True, username=None ):
d['spiff'] = username
d['filters']['authors__username'] = username
- if load_walt:
- for page_slug in WALT_PAGES:
-
- d['walt'][ page_slug ] = {
- 'page': Page.objects.get( language=d['language'], slug=page_slug ),
- 'pins': Pin.objects.filter( language=d['language'], page__slug=page_slug ).filter( **d['filters'] )
- }
-
+ try:
+ if load_walt:
+ for page_slug in WALT_PAGES:
+
+ d['walt'][ page_slug ] = {
+ 'page': Page.objects.get( language=d['language'], slug=page_slug ),
+ 'pins': Pin.objects.filter( language=d['language'], page__slug=page_slug ).filter( **d['filters'] )
+ }
+ except Page.DoesNotExist,e:
+ d['exception'] = e
+
# d['walt'] = dict([(p.slug,p) for p in Page.objects.filter( language=d['language'], slug__in=WALT_PAGES ) ] ) if load_walt else {}

0 comments on commit f18b360

Please sign in to comment.