summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2011-05-10 15:53:46 +0200
committerLeif Johansson <leifj@sunet.se>2011-05-10 15:53:46 +0200
commite357598b8f62524c3c9c2f4008c4c0fba035c2db (patch)
tree2ef297d669a434c874ab8e070319082aa93c4642
parent7025f3791d379f5bdf10c479ec54ae7f010e6d29 (diff)
tagging
-rw-r--r--src/meetingtools/apps/auth/views.py3
-rw-r--r--src/meetingtools/apps/room/forms.py7
-rw-r--r--src/meetingtools/apps/room/models.py6
-rw-r--r--src/meetingtools/apps/room/views.py46
-rw-r--r--src/meetingtools/settings.py1
-rw-r--r--src/meetingtools/urls.py7
-rw-r--r--src/templates/apps/room/list.html1
-rw-r--r--src/templates/apps/room/tag.html21
-rw-r--r--src/templates/edit.html45
9 files changed, 101 insertions, 36 deletions
diff --git a/src/meetingtools/apps/auth/views.py b/src/meetingtools/apps/auth/views.py
index 0c46338..8b0a8fd 100644
--- a/src/meetingtools/apps/auth/views.py
+++ b/src/meetingtools/apps/auth/views.py
@@ -141,10 +141,11 @@ def accounts_login_federated(request):
'last-name':ln,
'email':mail,
'send-email': 0,
- 'password': key,
'login':request.user.username,
'ext-login':request.user.username})
+ connect_api.request("user-update-pwd",{"user-id": principal.get('principal-id'),'password': key,'password-verify': key},True)
+
co_import_from_request(request)
member_or_employee = _is_member_or_employee(request.user)
diff --git a/src/meetingtools/apps/room/forms.py b/src/meetingtools/apps/room/forms.py
index 143551a..ed4287f 100644
--- a/src/meetingtools/apps/room/forms.py
+++ b/src/meetingtools/apps/room/forms.py
@@ -6,7 +6,7 @@ Created on Feb 1, 2011
from meetingtools.apps.room.models import Room
from django.forms.widgets import Select, TextInput, RadioSelect
-from django.forms.fields import BooleanField, ChoiceField
+from django.forms.fields import BooleanField, ChoiceField, CharField
from django.forms.forms import Form
from form_utils.forms import BetterModelForm
from django.utils.safestring import mark_safe
@@ -81,4 +81,7 @@ class CreateRoomForm(BetterModelForm):
'name': TextInput(attrs={'size': '40'})}
class DeleteRoomForm(Form):
- confirm = BooleanField(label="Confirm remove room") \ No newline at end of file
+ confirm = BooleanField(label="Confirm remove room")
+
+class TagRoomForm(Form):
+ tag = CharField(max_length=256) \ No newline at end of file
diff --git a/src/meetingtools/apps/room/models.py b/src/meetingtools/apps/room/models.py
index 736c63f..a71e608 100644
--- a/src/meetingtools/apps/room/models.py
+++ b/src/meetingtools/apps/room/models.py
@@ -11,7 +11,7 @@ from django.db.models.fields.related import ForeignKey
from django.contrib.auth.models import User
from meetingtools.apps.cluster.models import ACCluster
import time
-from django_co_acls.models import AccessControlEntry
+import tagging
class Room(models.Model):
creator = ForeignKey(User,editable=False)
@@ -38,4 +38,6 @@ class Room(models.Model):
if not self.lastvisited:
return 0
else:
- return int(time.mktime(self.lastvisited.timetuple())*1000) \ No newline at end of file
+ return int(time.mktime(self.lastvisited.timetuple())*1000)
+
+tagging.register(Room) \ No newline at end of file
diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py
index 81ce1dc..201509e 100644
--- a/src/meetingtools/apps/room/views.py
+++ b/src/meetingtools/apps/room/views.py
@@ -6,7 +6,7 @@ Created on Jan 31, 2011
from meetingtools.apps.room.models import Room, ACCluster
from meetingtools.multiresponse import respond_to, redirect_to
from meetingtools.apps.room.forms import DeleteRoomForm,\
- CreateRoomForm, ModifyRoomForm
+ CreateRoomForm, ModifyRoomForm, TagRoomForm
from django.shortcuts import get_object_or_404
from meetingtools.ac import ac_api_client, api
import re
@@ -22,6 +22,7 @@ from django.http import HttpResponseRedirect
from django.core.exceptions import ObjectDoesNotExist
from django_co_acls.models import allow, deny, acl, clear_acl
from meetingtools.ac.api import ACPClient
+from tagging.models import Tag, TaggedItem
def _acc_for_user(user):
(local,domain) = user.username.split('@')
@@ -348,4 +349,45 @@ def goto(request,room):
return user_client.redirect_to(room.acc.url+urlpath)
else:
return HttpResponseRedirect(room.acc.url+urlpath)
- \ No newline at end of file
+
+## Tagging
+
+@login_required
+def list_by_tag(request,tn):
+ tags = tn.split('+')
+ rooms = TaggedItem.objects.get_by_model(Room, tags)
+
+
+def _can_tag(request,tag):
+ if tag in ('selfcleaning','public','private'):
+ return False,"'%s' is reserved" % tag
+ # XXX implement access model for tags here soon
+ return True,""
+
+@login_required
+def untag(request,rid,tag):
+ room = get_object_or_404(Room,pk=rid)
+ new_tags = []
+ for t in Tag.objects.get_for_object(room):
+ if t.name != tag:
+ new_tags.append(t.name)
+
+ Tag.objects.update_tags(room, ' '.join(new_tags))
+ return redirect_to("/room/%d/tag" % room.id)
+
+@login_required
+def tag(request,rid):
+ room = get_object_or_404(Room,pk=rid)
+ if request.method == 'POST':
+ form = TagRoomForm(request.POST)
+ if form.is_valid():
+ tag = form.cleaned_data['tag']
+ ok,reason = _can_tag(request,tag)
+ if ok:
+ Tag.objects.add_tag(room, tag)
+ else:
+ form._errors['tag'] = form.error_class([u'%s ... please choose another tag!' % reason])
+ else:
+ form = TagRoomForm()
+
+ return respond_to(request, {'text/html': "apps/room/tag.html"}, {'form': form,'formtitle': 'Add Tag','submitname': 'Add Tag','room': room, 'tags': Tag.objects.get_for_object(room)}) \ No newline at end of file
diff --git a/src/meetingtools/settings.py b/src/meetingtools/settings.py
index 34a4c06..a09da72 100644
--- a/src/meetingtools/settings.py
+++ b/src/meetingtools/settings.py
@@ -106,6 +106,7 @@ INSTALLED_APPS = (
'django_extensions',
'django_co_connector',
'django_co_acls',
+ 'tagging',
'meetingtools.extensions',
'meetingtools.apps.auth',
'meetingtools.apps.room',
diff --git a/src/meetingtools/urls.py b/src/meetingtools/urls.py
index 568ac83..27980f2 100644
--- a/src/meetingtools/urls.py
+++ b/src/meetingtools/urls.py
@@ -1,9 +1,7 @@
-from django.conf.urls.defaults import *
+from django.conf.urls.defaults import patterns,include
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
-from django.http import HttpResponseRedirect
-from django.contrib.auth.views import login, logout
from meetingtools.settings import ADMIN_MEDIA_ROOT, MEDIA_ROOT
from meetingtools.multiresponse import redirect_to
admin.autodiscover()
@@ -27,6 +25,9 @@ urlpatterns = patterns('',
(r'^room/(\d+)$','meetingtools.apps.room.views.view'),
(r'^room/(\d+)/modify$','meetingtools.apps.room.views.update'),
(r'^room/(\d+)/delete$','meetingtools.apps.room.views.delete'),
+ (r'^room/(\d+)/tag$','meetingtools.apps.room.views.tag'),
+ (r'^room/(\d+)/untag/(.+)$','meetingtools.apps.room.views.untag'),
+ (r'^\+(.+)','meetingtools.apps.room.views.list_by_tag'),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
diff --git a/src/templates/apps/room/list.html b/src/templates/apps/room/list.html
index 6c39e12..fb47ca1 100644
--- a/src/templates/apps/room/list.html
+++ b/src/templates/apps/room/list.html
@@ -34,6 +34,7 @@
<ul class="ilist">
<!-- li><div class="button"><a href="{% prefix %}/room/{{r.id}}/modify">Modify Room</a></li -->
<li><div class="button"><a href="{% prefix %}/room/{{r.id}}/delete">Delete Room</a></li>
+ <li><div class="button"><a href="{% prefix %}/room/{{r.id}}/tag">Room Tags</a></li>
</ul>
</div>
</div>
diff --git a/src/templates/apps/room/tag.html b/src/templates/apps/room/tag.html
new file mode 100644
index 0000000..d8c666e
--- /dev/null
+++ b/src/templates/apps/room/tag.html
@@ -0,0 +1,21 @@
+{% extends "edit.html" %}
+{% load prefix %}
+{% load datehumanize %}
+{% load roomurl %}
+{% load prefix %}
+{% block widgets %}
+
+{% endblock %}
+{% block beforeform %}
+ <h1>Tags for {{room.name}}</h1>
+ {% if tags %}
+ <ul class="ilist">
+ {% for tag in tags %}
+ <li class="ui-widget ui-state-highlight ui-corner-all" style="padding: 6px 10px;"><a href="{%prefix%}/+{{tag}}">{{tag}}</a>&nbsp;<a href="{% prefix %}/room/{{room.id}}/untag/{{tag}}"><span style="vertical-align: middle;" class="ui-icon ui-icon-closethick"></span></a></li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <em>There are no tags yet...</em>
+ {% endif %}
+ <br/>
+{% endblock %} \ No newline at end of file
diff --git a/src/templates/edit.html b/src/templates/edit.html
index 961fe66..400a087 100644
--- a/src/templates/edit.html
+++ b/src/templates/edit.html
@@ -2,31 +2,24 @@
{% load prefix %}
{% block content %}
{% block beforeform %}{% endblock %}
-<form method="POST">
- <div class="ui-widget-content ui-corner-all infopanel">
- <h1>{{formtitle}}</h1>
- <table class="formtable">
- {% for field in form %}
- <tr style="padding-top: 10px;">
- <td>
- {% if not field.is_hidden %}
- <div class="ui-widget fieldlabel">{{ field.label_tag }}</div>
- {% endif %}
- {% if field.errors %}
- <div class="ui-widget ui-state-error">{{ field.errors }}</div>
- {% endif %}
- </td>
- <td>
- <div class="ui-widget">{{ field }}</div>
- </td>
- </tr>
- {% endfor %}
- </table>
- </div>
- <br/>
- <div class="button">
- <input type="submit" value="{{submitname}}" />
- <input type="button" onClick="document.location='{% prefix %}/rooms'" value="Cancel"/>
- </div>
+<h1>{{formtitle}}</h1>
+<form method="POST" class="ui-widget ui-corner-all ui-state-highlight bbq infopanel" style="width: 50%">
+<ul class="links">
+ {% for field in form %}
+ {% if field.is_hidden %}
+ {{ field }}
+ {% else %}
+ <li class="links {% if field.field.required %}required{% endif %}" {{ field.row_attrs }} style="margin-bottom: 10px;">
+ {{ field.errors }}
+ <label for="id_{{ field.html_name }}" class="fieldlabel" style="border-bottom: 1px solid #CECECE;"><em>{{ field.label }}{% if field.field.required %}<b>*</b>{% endif %}</em></label>
+ <div class="fieldinput">{{ field }}</div>
+ </li>
+ {% endif %}
+ {% endfor %}
+</ul>
+<ul class="ilist" style="padding-top: 10px; padding-bottom: 5px;">
+ <li class="button"><input type="submit" value="{{submitname}}" /></li>
+ <li class="button right"><input type="button" onClick="document.location='{% prefix %}/rooms'" value="Cancel"/></li>
+</ul>
</form>
{% endblock %} \ No newline at end of file