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

View File

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