diff --git a/brewman/brewman/models/messaging.py b/brewman/brewman/models/messaging.py
index 27c64cab..7313be45 100644
--- a/brewman/brewman/models/messaging.py
+++ b/brewman/brewman/models/messaging.py
@@ -71,6 +71,8 @@ class Thread(Base):
@classmethod
def by_id(cls, id):
+ if not isinstance(id, uuid.UUID):
+ id = uuid.UUID(id)
return DBSession.query(cls).filter(cls.id == id).first()
@classmethod
diff --git a/brewman/brewman/static/offline.appcache b/brewman/brewman/static/offline.appcache
index 1cd19418..76df45e3 100644
--- a/brewman/brewman/static/offline.appcache
+++ b/brewman/brewman/static/offline.appcache
@@ -1,6 +1,6 @@
CACHE MANIFEST
-# version 2013-06-19.1
+# version 2013-06-24.1
CACHE:
/partial/404.html
diff --git a/brewman/brewman/static/partial/home.html b/brewman/brewman/static/partial/home.html
index 87077e81..40fb99e2 100644
--- a/brewman/brewman/static/partial/home.html
+++ b/brewman/brewman/static/partial/home.html
@@ -6,7 +6,7 @@
Open
Closed
All
-
+
Tags
@@ -18,24 +18,14 @@
-
-
-
-
- |
-
- Details
- |
-
-
-
- |
+
User: {{item.User}} {{item.Age}} ago. Updated {{item.LastUpdated}} ago.
{{item.Title}}
{{tag}}
+ {{subscriber}}
|
diff --git a/brewman/brewman/static/scripts/angular_directive.js b/brewman/brewman/static/scripts/angular_directive.js
index ddf8d69a..5530840d 100644
--- a/brewman/brewman/static/scripts/angular_directive.js
+++ b/brewman/brewman/static/scripts/angular_directive.js
@@ -8,11 +8,13 @@ overlord_directive.directive('ngAutocomplete', ['$q', '$parse', 'DeepLabel', fun
var mappedCache = {},
labels = [],
mapped = {},
- deepLabel = DeepLabel;
+ deepLabel = DeepLabel,
+ count = 20;
element.typeahead({
source: function (query, process) {
- var Entity = angular.injector(['overlord.service']).get(attrs.resource);
- Entity.autocomplete({term: query, count: 20}, function (result) {
+ var Entity = angular.injector(['overlord.service']).get(attrs.resource),
+ options = {term: query, count: count};
+ Entity.autocomplete(options, function (result) {
labels = [];
mapped = {};
$.each(result, function (i, item) {
@@ -25,7 +27,7 @@ overlord_directive.directive('ngAutocomplete', ['$q', '$parse', 'DeepLabel', fun
});
},
minLength: 1,
- items: 20,
+ items: count,
matcher: function (item) {
return true;
},
diff --git a/brewman/brewman/views/messaging.py b/brewman/brewman/views/messaging.py
index a8f68926..5019b398 100644
--- a/brewman/brewman/views/messaging.py
+++ b/brewman/brewman/views/messaging.py
@@ -46,7 +46,7 @@ def save(request):
if user_name not in request.json_body['Subscribers']:
request.json_body['Subscribers'].append(user_name)
for item in request.json_body['Subscribers']:
- subscriber = Subscriber(user_id=User.by_name(item).id, read=False)
+ subscriber = Subscriber(user_id=User.by_name(item).id, read=item == user_name)
thread.subscribers.append(subscriber)
DBSession.add(subscriber)
transaction.commit()
@@ -57,6 +57,7 @@ def save(request):
@TryCatchFunction
def update(request):
user_id = uuid.UUID(authenticated_userid(request))
+ user_name = User.by_id(user_id).name
super_user = 'Messages' in groupfinder(user_id, request)
thread = Thread.by_id(uuid.UUID(request.matchdict['id']))
public = request.json_body['Public']
@@ -101,6 +102,8 @@ def update(request):
thread.posts.append(post)
DBSession.add(post)
+ if user_name not in request.json_body['Subscribers']:
+ request.json_body['Subscribers'].append(user_name)
newSubscribers = request.json_body['Subscribers']
for i in range(len(thread.subscribers), 0, -1):
subscriber = thread.subscribers[i - 1]
@@ -108,9 +111,9 @@ def update(request):
thread.subscribers.remove(subscriber)
else:
newSubscribers.remove(subscriber.user.name)
- subscriber.read = False
+ subscriber.read = subscriber.user.name == user_name
for j in newSubscribers:
- subscriber = Subscriber(user_id=User.by_name(j).id, read=False)
+ subscriber = Subscriber(user_id=User.by_name(j).id, read=j == user_name)
thread.subscribers.append(subscriber)
DBSession.add(subscriber)
@@ -127,7 +130,14 @@ def show_blank(request):
@view_config(request_method='GET', route_name='api_message_id', renderer='json', permission='Authenticated')
def show_id(request):
- return thread_info(uuid.UUID(request.matchdict.get('id', None)))
+ user_id = authenticated_userid(request) and uuid.UUID(authenticated_userid(request))
+ thread = Thread.by_id(request.matchdict['id'])
+ subscriber = [s for s in thread.subscribers if s.user_id == user_id]
+ if len(subscriber) > 0:
+ subscriber[0].read = True
+ info = thread_info(thread)
+ transaction.commit()
+ return info
@view_config(request_method='GET', route_name='api_message', renderer='json', request_param='list')
@@ -153,7 +163,7 @@ def show_list(request):
tags = {}
threads = []
for item in list:
- thread = {'ThreadID': item.id, 'Title': item.title, 'Age': get_age(item.creation_date),
+ thread = {'ThreadID': item.id, 'Title': item.title, 'Age': get_age(item.creation_date), 'Read': False,
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
last_updated = item.creation_date
@@ -168,12 +178,16 @@ def show_list(request):
else:
tags[tag.name] += 1
+ for subscriber in item.subscribers:
+ thread['Subscribers'].append(subscriber.user.name)
+ if subscriber.user_id == user_id:
+ thread['Read'] = subscriber.read
threads.append(thread)
return {'Tags': tags, 'Threads': threads, 'Type': type}
def thread_info(id):
- item = Thread.by_id(id)
+ item = id if isinstance(id, Thread) else Thread.by_id(id)
thread = {'ThreadID': item.id, 'Title': item.title, 'Closed': item.closed,
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
diff --git a/brewman/brewman/views/services/voucher/purchase.py b/brewman/brewman/views/services/voucher/purchase.py
index b7f130eb..7c4f0ed9 100644
--- a/brewman/brewman/views/services/voucher/purchase.py
+++ b/brewman/brewman/views/services/voucher/purchase.py
@@ -103,6 +103,7 @@ def purchase_update_inventory(voucher, newInventories):
rate = round(Decimal(i['Rate']), 2)
discount = round(Decimal(i['Discount']), 5)
tax = round(Decimal(i['Tax']), 5)
+ item.batch.name = voucher.date
item.rate = rate
item.batch.rate = rate
item.discount = discount