-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend/room wsc #7
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
# COPYRIGHT (c) 2016 Cristóbal Ganter | ||
# | ||
# GNU AFFERO GENERAL PUBLIC LICENSE | ||
# Version 3, 19 November 2007 | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from .wsclass import RoomsWSC # noqa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import is not used here |
||
from . import patches # noqa | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no reason to use noqa here. |
||
|
||
class RoomIsNotDefined(AttributeError): | ||
"""Raise when ``room`` is not defined. | ||
|
||
``course`` should be defined in the current instance of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. room should be defined ... |
||
:class:`~controller.MSGHandler`. | ||
|
||
.. automethod:: __init__ | ||
""" | ||
|
||
def __init__(self, *args): | ||
"""Initialize a new CourseIsNotDefined exception.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, bad copy paste |
||
super().__init__( | ||
'Attempted to use the `course` attribute, but ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad copy paste |
||
'the attribute is not assigned.', | ||
*args | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
# COPYRIGHT (c) 2016 Cristóbal Ganter | ||
# | ||
# GNU AFFERO GENERAL PUBLIC LICENSE | ||
# Version 3, 19 November 2007 | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from controller import MSGHandler | ||
from src.db import Room | ||
from .. import router | ||
from .wsclass import RoomsWSC | ||
|
||
MSGHandler._room = None | ||
|
||
@property | ||
def room(self): | ||
"""Current room asociated with this MSGHandler.""" | ||
return self._room | ||
|
||
@room.setter | ||
def room(self, new_room): | ||
self._room = new_room | ||
self.room_msg_type = \ | ||
'message.filter.room({})'.format(new_room.id) | ||
router_object = self.ws_objects[ | ||
router.RouterWSC] | ||
rooms_object = self.ws_objects[RoomsWSC] | ||
|
||
rooms_object.register_action_in( | ||
self.room_msg_type, | ||
action=router_object.to_local, | ||
channels={'d'} | ||
) | ||
MSGHandler.room = room |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
# COPYRIGHT (c) 2016 Cristóbal Ganter | ||
# | ||
# GNU AFFERO GENERAL PUBLIC LICENSE | ||
# Version 3, 19 November 2007 | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from tornado.gen import coroutine | ||
|
||
import src | ||
from src.wsclass import subscribe | ||
from src.db import Course, User | ||
|
||
|
||
class RoomsWSC(src.wsclass.WSClass): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why is this necessary. |
||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,52 @@ def load_user(self, token): | |
) | ||
raise ite from norfdb | ||
|
||
@subscribe('message.filter.student', 'l') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be part of this branch. |
||
@coroutine | ||
def redirect_message_if_user_is_student( | ||
self, message, content=True): | ||
"""Redirects a message if the user is a student. | ||
|
||
This coroutine redirects a message to the local | ||
channel only if the current user is a student. | ||
|
||
:param dict message: | ||
The message that should be redirected if the | ||
user is a student. | ||
|
||
:param bool content: | ||
If ``True``, just the object corresponding to | ||
the ``'content'`` key of ``message`` will be | ||
sent. | ||
If ``False``, the whole message will be sent. | ||
|
||
:raises MalformedMessageError: | ||
If ``content`` is ``True``, but ``message`` | ||
doesn't have the ``'content'`` key. | ||
|
||
:raises NotDictError: | ||
If ``message`` is not a dictionary. | ||
|
||
:raises NoMessageTypeError: | ||
If the message or it's content doesn't have the | ||
``'type'`` key. | ||
|
||
:raises NoActionForMsgTypeError: | ||
If ``send_function`` of the ``PubSub`` object | ||
wasn't specified during object creation and | ||
there's no registered action for this message | ||
type. | ||
|
||
:raises AttributeError: | ||
If the user is not yet loaded or if the user is | ||
``None``. | ||
""" | ||
try: | ||
if self.handler.user.status == 'seat': | ||
self.redirect_to('l', message, content) | ||
except: | ||
raise | ||
|
||
@subscribe('teacherMessage', 'l') | ||
@coroutine | ||
def redirect_message_if_user_is_teacher( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should license this module as your own.