Skip to content
Browse files

tags

  • Loading branch information...
1 parent 12cca5c commit 56daf9c5b7b99ec21fc584cc46bda9b58b36bbce @danieleguido committed Mar 22, 2013
Showing with 173 additions and 15 deletions.
  1. +4 −0 glue/__init__.py
  2. +62 −1 glue/api.py
  3. +2 −1 glue/forms.py
  4. +7 −0 glue/models.py
  5. +3 −0 glue/urls.py
  6. +27 −0 static/js/oo/glue.js
  7. +12 −1 static/less/style.less
  8. +11 −9 templates/walt/index.html
  9. +43 −2 templates/walt/middle.html
  10. +2 −1 walt/views.py
View
4 glue/__init__.py
@@ -202,6 +202,10 @@ def add( self, key, value, jsonify=False):
self.response[ key ] = value.json() if jsonify else value
return value
+ def meta( self, key, value ):
+ self.response['meta'][ key ] = value
+ return value
+
def throw_error( self, error="", code=API_EXCEPTION ):
self.response[ 'status' ] = 'error'
self.response[ 'error' ] = error
View
63 glue/api.py
@@ -11,7 +11,7 @@
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
+from glue.forms import AddPageForm, AddPinForm, EditPinForm, UploadPinForm, AddSerieForm, AddFrameForm, AddTagForm
logger = logging.getLogger(__name__)
@@ -178,6 +178,67 @@ def frames( request, serie_id ):
def frame( request, frame_id ):
return Epoxy( request ).single( Frame, {'id':frame_id,'serie__authors':request.user } ).json()
+#
+#
+# TAGs
+#
+#
+@login_required( login_url=settings.GLUE_ACCESS_DENIED_URL )
+def tags( request ):
+ response = Epoxy( request )
+
+ if response.method == 'POST':
+ response.meta('types', Tag.TYPE_CHOICES )
+ form = AddTagForm( request.REQUEST )
+ if not form.is_valid():
+ return response.throw_error(error=form.errors, code=API_EXCEPTION_FORMERRORS ).json()
+ try:
+ tag = Tag(
+ name = form.cleaned_data['name'],
+ slug = form.cleaned_data['slug'],
+ type = form.cleaned_data['type']
+ )
+ tag.save()
+ except IntegrityError, e:
+
+ tag = Tag.objects.get(
+ type = form.cleaned_data['type'],
+ slug = form.cleaned_data['slug']
+ )
+
+ response.add( 'object', tag, jsonify=True )
+
+ if len(form.cleaned_data['pin_slug']) > 0:
+ # attacch tag to a selected pin
+ for p in Pin.objects.filter( slug=form.cleaned_data['pin_slug'] ):
+ p.tags.add( tag )
+ p.save()
+
+ response.add('pin_slug',form.cleaned_data['pin_slug'])
+
+ return response.json()
+
+
+ return response.queryset( Tag.objects.filter() ).json()
+
+@login_required( login_url=settings.GLUE_ACCESS_DENIED_URL )
+def tag( request, tag_id ):
+ response = Epoxy( request )
+
+
+
+ return response.single( Frame, {'id':tag_id } ).json()
+
+
+
+
+
+#
+#
+# PINs
+#
+#
+
@login_required( login_url=settings.GLUE_ACCESS_DENIED_URL )
def pins( request ):
response = Epoxy( request )
View
3 glue/forms.py
@@ -70,4 +70,5 @@ class UploadPinForm(forms.Form): # an upload form without file :D (upload via aj
class AddTagForm(forms.Form):
name = forms.CharField( label=_("tag name"),required=True )
slug = forms.SlugField( required=True )
- type = forms.CharField( label=_("type"), required=True, widget = forms.ChoiceField( widget=forms.Select, choices=Tag.TYPE_CHOICES ) )
+ type = forms.ChoiceField( required=True, widget=forms.Select(attrs={'class':'span6'}), choices=Tag.TYPE_CHOICES )
+ pin_slug = forms.SlugField( required=False, widget=forms.HiddenInput )
View
7 glue/models.py
@@ -45,6 +45,13 @@ class Meta:
ordering = ["type", "slug" ]
unique_together = ("type", "slug")
+ def json( self ):
+ return{
+ 'id': self.id,
+ 'slug':self.slug,
+ 'name':self.name,
+ 'type':self.get_type_display()
+ }
class Pin( models.Model ):
PUBLISHED='P'
DRAFT = 'D'
View
3 glue/urls.py
@@ -28,6 +28,9 @@
url(r'^serie/(?P<serie_id>\d+)/$', 'glue.api.serie', name='glue_api_serie'), # get a signle serie WITHOUT its frame collection. POST to edit serie Data
url(r'^serie/(?P<serie_id>\d+)/frames/$', 'glue.api.serie_frames', name='glue_api_serie_frames'), # get a signle serie along wiht its frame collection. POST to add frame...
+ url(r'^tag/$', 'glue.api.tags', name='glue_api_tags'), # get list, post single page
+ url(r'^tag/(?P<tag_id>\d+)/$', 'glue.api.tag', name='glue_api_tag'),
+
url(r'^frame/$', 'glue.api.frames', name='glue_api_frames'), # get list of frames per author (useless)
url(r'^frame/(?P<frame_id>\d+)/$', 'glue.api.frame', name='glue_api_frame'), # GET: full information
View
27 static/js/oo/glue.js
@@ -37,6 +37,11 @@ oo.magic.pin.remove = function( result ){
}
+oo.magic.tag = oo.magic.tag || {};
+oo.magic.tag.add = function( result ){
+ oo.log("[oo.magic.pin.add]", result);
+ window.location.reload();
+}
/*
@@ -91,6 +96,22 @@ oo.glue.pin.listeners.edit = function( event ){
// load and callback to oo.glue.pin.edit
};
+oo.glue.pin.listeners.open_attach_tag = function( event ){
+ var el = $(this);
+ var pin_slug = el.attr( "data-pin-slug" );
+ var auto_id = el.attr( "data-auto-id" );
+ $("#id_attach_tag_pin_slug").val( pin_slug );
+ $( "#attach-tag-modal" ).modal({ show:true });
+}
+
+oo.glue.pin.listeners.attach_tag = function( event ){
+ oo.api.tag.add({
+ name:$("#id_attach_tag_name").val(),
+ type:$("#id_attach_tag_type").val(),
+ slug:$("#id_attach_tag_slug").val(),
+ pin_slug:$("#id_attach_tag_pin_slug").val()
+ });
+}
oo.glue.pin.listeners.update = function(event){ event.preventDefault();
var el = $(this);
@@ -187,6 +208,9 @@ oo.glue.init = function(){ oo.log("[oo.glue.init]");
// compile pin api
oo.api.compile( 'pin' );
+ // compile tag api
+ oo.api.compile( 'tag' );
+
// bib text parser init
oo.glue.bibtex.init();
@@ -215,6 +239,9 @@ oo.glue.init = function(){ oo.log("[oo.glue.init]");
// save edited pin
$(".update-pin").on("click", oo.glue.pin.listeners.update );
+ // attach tag to a pin
+ $(".open-attach-tag").on("click", oo.glue.pin.listeners.open_attach_tag );
+ $(".attach-tag").on("click", oo.glue.pin.listeners.attach_tag );
// remove pin with the same slug as pin given (remove from all languages)
// user should be the object author, an the object shound.nt be used into frames
$(".remove-pin").on("click", oo.glue.pin.listeners.remove );
View
13 static/less/style.less
@@ -105,11 +105,16 @@ a[role="button"]{
@footer-background-color: #eee;
footer{
background: @footer-background-color;
- border-top: 1px solid darken( @footer-background-color, 14%);
+ // border-top: 1px solid darken( @footer-background-color, 14%);
border-bottom: 1px solid darken( @footer-background-color, 19%);
+
+ #logos{
+ //color: white;
+ }
}
#footer-inner{
+display:none;
background-color: transparent;
margin-top: 3px;
@@ -188,6 +193,7 @@ h2{
.metadata{
margin-bottom: @grid-padding/2;
}
+
.actions{
border-top: 1px solid #e1e1e1;
margin: @grid-padding/2 0;
@@ -205,6 +211,11 @@ h2{
}
}
}
+ border: 1px solid white;
+ &:hover{
+ // .box-shadow( 0 0px 2px @blue );
+ border: 1px solid @blue;
+ }
}
#timeline-serie{
View
20 templates/walt/index.html
@@ -18,6 +18,8 @@
oo.urls.list_pin = "{% url glue_api_pins %}";
oo.urls.edit_pin = "{% url glue_api_pin 0 %}";
oo.urls.remove_pin = "{% url glue_api_pin 0 %}";
+
+ oo.urls.add_tag = "{% url glue_api_tags %}";
{% endif %}
{% endblock %}
@@ -29,7 +31,7 @@ <h2 class="grid_3 alpha">
( {{ walt.wander.pins.count }} )
</a>
{% if user.is_authenticated %}
- <a href="#add-walt-w-modal" role="button" data-toggle="modal" style="color: crimson">+ {% trans "add bookmark" %}</a>
+ | <a href="#add-walt-w-modal" role="button" data-toggle="modal">+ {% trans "add bookmark" %}</a>
{% endif %}
{% comment %}<div class="description">
@@ -43,7 +45,7 @@ <h2 class="grid_3">
( {{ walt.augment.pins.count }} )
</a>
{% if user.is_authenticated %}
- <a href="#add-walt-a-modal" role="button" data-toggle="modal" style="color: crimson">+ {% trans "add object" %}</a>
+ | <a href="#add-walt-a-modal" role="button" data-toggle="modal">+ {% trans "add object" %}</a>
{% endif %}
{% comment %}<div class="description">
{{ walt.augment.page.abstract }}
@@ -54,7 +56,7 @@ <h2 class="grid_3" >
( {{ walt.learn.pins.count }} )
</a>
{% if user.is_authenticated %}
- <a href="#add-walt-l-modal" role="button" data-toggle="modal" style="color: crimson">+ {% trans "add publication" %}</a>
+ | <a href="#add-walt-l-modal" role="button" data-toggle="modal">+ {% trans "add publication" %}</a>
{% endif %}
{% comment %}<div class="description">
{{ walt.learn.page.abstract }}
@@ -65,7 +67,7 @@ <h2 class="grid_3 omega">
( {{ walt.try.pins.count }} )
</a>
{% if user.is_authenticated %}
- <a href="#add-walt-t-modal" role="button" data-toggle="modal" style="color: crimson">+ {% trans "add tool" %}</a>
+ | <a href="#add-walt-t-modal" role="button" data-toggle="modal">+ {% trans "add tool" %}</a>
{% endif %}
{% comment %}<div class="description">
{{ walt.try.page.abstract }}
@@ -185,7 +187,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</span>
<div class="actions">
- <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "edit" %}</a>
{% if pin.permalink %}
<a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
@@ -235,7 +237,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
<a href="{% url walt_tag tag.type|lower tag.slug %}" class="tag" alt="{{ tag.name }} ( {{ tag.type }} )">{{ tag.name }}</a>
{% if not forloop.last %},{%endif %}
{% endfor %}
-
+ <a href="#" class="open-attach-tag" data-pin-slug="{{ pin.slug }}" alt="attach tag">+</a>
</div>
<div>
{{ pin.content|safe }}
@@ -254,7 +256,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</span>
<div class="actions">
- <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "edit" %}</a>
<a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
{% if user in authors %}
@@ -316,7 +318,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</span>
<div class="actions">
- <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "edit" %}</a>
{% if pin.permalink %}
<a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
@@ -374,7 +376,7 @@ <h2 style="text-align: center"><a href="{% url walt_login %}">&rarr; {% trans "p
</span>
<div class="actions">
- <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "modify" %}</a>
+ <a href="#{% url admin:glue_pin_change pin.id %}" class="edit-pin action" data-id="{{ pin.id }}" title="{% trans "edit" %}">{% trans "edit" %}</a>
{% if pin.permalink %}
<a class="external action" href="{{ pin.permalink}}">{% trans "link" %}</a>
View
45 templates/walt/middle.html
@@ -9,22 +9,29 @@
<div id="menu" class="grid_12">
<h1 style="float: left; margin:0; margin-right:24px"><a href="{% url walt_home %}">walt.</a></h1>
<div style="margin:12px; ">
- <a href="{% url walt_home %}" {% if 'home' in tags %}class="active"{% endif %}>{% trans "all walts" %}</a> |
+ <!-- a href="{% url walt_home %}" {% if 'home' in tags %}class="active"{% endif %}>{% trans "all walts" %}</a> |
{% if user.is_authenticated %}
<a href="{% url walt_spiff user.username %}" {% if 'my-walt' in tags %}class="active"{% endif %}>{% trans "my walt"%} ( {{ user.username }} )</a> ||
{% endif %}
- <a href="{% url walt_series %}">{% trans "all series" %} ({{ series.count }})</a> |
+ -->
+ <!-- a href="{% url walt_series %}">{% trans "all series" %} ({{ series.count }})</a> | -->
{% if user.is_authenticated %}
<a href="{% url walt_logout %}">{% trans "logout" %} </a>
{% else %}
<a href="{% url walt_login %}">{% trans "login" %}</a>
{% endif %}
<!-- {{ tags}} -->
</div>
+
+ {% if spiff %}
+ <h1>{{ spiff }}'s walt</h1>
+ {% endif %}
+
</div>
</div>
<div class="container_12" id="navbar">
+
{% block navbar %}
{% endblock %}
@@ -41,6 +48,8 @@ <h1 style="float: left; margin:0; margin-right:24px"><a href="{% url walt_home %
</div>
{% else %}
+
+
{% block page %}
{% endblock %}
@@ -310,5 +319,37 @@ <h1 style="float: left; margin:0; margin-right:24px"><a href="{% url walt_home %
</div>
</div>
{% endif %}
+
+ <!-- attach tag -->
+ <div id="attach-tag-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+ <h2>{% trans "attach a tagl" %}</h2>
+ </div>
+ <div class="modal-body">
+ <p>
+ <label for='id_attach_tag_name'>{% trans "tag it" %}</label>
+ <input type='text' class="span6 repeatable" data-target="id_attach_tag_slug" id="id_attach_tag_name" placeholder="tag"/>
+ <input type='hidden' id="id_attach_tag_pin_slug" value="0" />
+ </p>
+ <p>
+ <label for='id_attach_tag_slug'>{% trans "unique tag identifier" %}</label>
+ <input type='text' class="span6" id="id_attach_tag_slug" placeholder="tag"/>
+ </p>
+ <p>
+ <label for='id_attach_tag_type'>{% trans "tag type" %}</label>
+ {{ attach_tag_form.type }}
+ </p>
+
+ </div>
+ <div class="modal-footer">
+ <button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "close" %}</button>
+ <button class="btn btn-primary attach-tag" data-page-slug="" data-auto-id="id_attach_tag">{% trans "attach tag" %}</button>
+ </div>
+ </div>
+
+
+
+
{% endif %}
{% endblock %}
View
3 walt/views.py
@@ -13,7 +13,7 @@
from django.utils.translation import ugettext as _
from django.utils.translation import get_language
-from glue.forms import LoginForm, AddPinForm, EditPinForm, AddSerieForm
+from glue.forms import LoginForm, AddPinForm, EditPinForm, AddSerieForm, AddTagForm
from glue.models import Pin, Page, Serie
@@ -70,6 +70,7 @@ def sc( request, tags=[], d={}, load_walt=True, username=None ):
d['login_form'] = LoginForm( auto_id="id_login_%s")
d['add_pin_form'] = AddPinForm( auto_id="id_add_pin_%s")
d['add_serie_form'] = AddSerieForm( auto_id="id_add_serie_%s")
+ d['attach_tag_form'] = AddTagForm( auto_id="id_attach_tag_%s")
return d

0 comments on commit 56daf9c

Please sign in to comment.
Something went wrong with that request. Please try again.