Thread subscribers working.

TODO: Implement thread read status per user.
TODO: Implemented edit post functionality for privileged user.
This commit is contained in:
Tanshu 2013-06-07 15:55:12 +05:30
parent 6bf884da66
commit 970eea2979
1 changed files with 11 additions and 7 deletions

View File

@ -5,6 +5,7 @@ from pyramid.security import authenticated_userid
from pyramid.view import view_config
from sqlalchemy.orm import joinedload_all
import transaction
from brewman import groupfinder
from brewman.models import DBSession
from brewman.models.auth import User
@ -23,6 +24,7 @@ def html(request):
@TryCatchFunction
def save(request):
user_id = uuid.UUID(authenticated_userid(request))
user_name = User.by_id(user_id).name
thread = Thread(title=request.json_body['Title'], priority=request.json_body['Priority'], user_id=user_id)
DBSession.add(thread)
for item in request.json_body['Posts']:
@ -38,6 +40,8 @@ def save(request):
tag = Tag(name=name)
DBSession.add(tag)
thread.tags.append(tag)
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)
thread.subscribers.append(subscriber)
@ -101,12 +105,12 @@ def show_id(request):
@view_config(request_method='GET', route_name='api_message', renderer='json', request_param='list')
def show_list(request):
user_id = None if authenticated_userid(request) is None else uuid.UUID(authenticated_userid(request))
list = Thread.query().filter(Thread.closed == False)
# Thread.subscribers, Thread.posts,
if authenticated_userid(request) is None:
if user_id is None:
list = list.filter(Thread.public == True)
# else:
# list.filter(Thread.subscribers.any(Subscriber.user_id == uuid.UUID(authenticated_userid(request))))
elif 'Messages' not in groupfinder(user_id, request):
list = list.filter(Thread.subscribers.any(Subscriber.user_id == user_id))
list = list.order_by(Thread.priority).all()
tags = {}
threads = []