mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-12 23:27:22 +00:00
Chat: Adapt to form_header/form_footer changes
Also use a proper WTForm to attach chatrooms to events
This commit is contained in:
parent
7608990e4e
commit
fd349ba590
@ -16,7 +16,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from flask import session, request, flash, redirect, jsonify
|
||||
from flask import session, flash, redirect, jsonify
|
||||
from flask_pluginengine import current_plugin
|
||||
|
||||
from indico.core.db import db
|
||||
@ -29,25 +29,34 @@ from indico.web.forms.base import FormDefaults
|
||||
|
||||
from indico_chat import _
|
||||
from indico_chat.controllers.base import RHChatManageEventBase, RHEventChatroomMixin
|
||||
from indico_chat.forms import AddChatroomForm, EditChatroomForm
|
||||
from indico_chat.forms import AddChatroomForm, EditChatroomForm, AttachChatroomForm
|
||||
from indico_chat.models.chatrooms import ChatroomEventAssociation, Chatroom
|
||||
from indico_chat.notifications import notify_created, notify_attached, notify_modified, notify_deleted
|
||||
from indico_chat.views import WPChatEventMgmt
|
||||
from indico_chat.xmpp import create_room, update_room, get_room_config, room_exists
|
||||
|
||||
|
||||
class RHChatManageEvent(RHChatManageEventBase):
|
||||
class AttachChatroomMixin:
|
||||
def _get_attach_form(self):
|
||||
form = AttachChatroomForm()
|
||||
form.chatroom.query = Chatroom.find(Chatroom.created_by_user == session.user,
|
||||
~Chatroom.events.any(ChatroomEventAssociation.event_id == self.event_id))
|
||||
return form
|
||||
|
||||
|
||||
class RHChatManageEvent(AttachChatroomMixin, RHChatManageEventBase):
|
||||
"""Lists the chatrooms of an event"""
|
||||
|
||||
def _process(self):
|
||||
chatrooms = ChatroomEventAssociation.find_for_event(self.event, include_hidden=True,
|
||||
_eager='chatroom.events').all()
|
||||
chatroom_filter = (~Chatroom.id.in_(x.chatroom_id for x in chatrooms)) if chatrooms else True
|
||||
available_chatrooms = Chatroom.find_all(Chatroom.created_by_user == session.user, chatroom_filter)
|
||||
logs_enabled = current_plugin.settings.get('log_url')
|
||||
attach_form = self._get_attach_form()
|
||||
if not attach_form.chatroom._get_object_list():
|
||||
attach_form = None
|
||||
return WPChatEventMgmt.render_template('manage_event.html', self._conf, event_chatrooms=chatrooms,
|
||||
event=self.event, chat_links=current_plugin.settings.get('chat_links'),
|
||||
available_chatrooms=available_chatrooms, logs_enabled=logs_enabled)
|
||||
logs_enabled=logs_enabled, attach_form=attach_form)
|
||||
|
||||
|
||||
class RHChatManageEventModify(RHEventChatroomMixin, RHChatManageEventBase):
|
||||
@ -122,18 +131,19 @@ class RHChatManageEventCreate(RHChatManageEventBase):
|
||||
return WPChatEventMgmt.render_template('manage_event_edit.html', self._conf, form=form, event=self.event)
|
||||
|
||||
|
||||
class RHChatManageEventAttach(RHChatManageEventBase):
|
||||
class RHChatManageEventAttach(AttachChatroomMixin, RHChatManageEventBase):
|
||||
"""Attaches an existing chatroom to an event"""
|
||||
|
||||
def _checkParams(self, params):
|
||||
RHChatManageEventBase._checkParams(self, params)
|
||||
self.chatroom = Chatroom.find_one(id=request.form['chatroom_id'])
|
||||
|
||||
def _process(self):
|
||||
event_chatroom = ChatroomEventAssociation(event_id=self.event_id, chatroom=self.chatroom)
|
||||
db.session.add(event_chatroom)
|
||||
notify_attached(self.chatroom, self.event, session.user)
|
||||
flash(_('Chatroom added'), 'success')
|
||||
form = self._get_attach_form()
|
||||
if form.validate_on_submit():
|
||||
event_chatroom = ChatroomEventAssociation(event_id=self.event_id, chatroom=form.chatroom.data)
|
||||
db.session.add(event_chatroom)
|
||||
notify_attached(form.chatroom.data, self.event, session.user)
|
||||
flash(_('Chatroom added'), 'success')
|
||||
return redirect(url_for_plugin('.manage_rooms', self.event))
|
||||
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from flask_pluginengine import current_plugin
|
||||
from wtforms.ext.sqlalchemy.fields import QuerySelectField
|
||||
from wtforms.fields.core import BooleanField
|
||||
from wtforms.fields.simple import StringField, TextAreaField
|
||||
from wtforms.validators import DataRequired, ValidationError
|
||||
@ -29,6 +30,10 @@ from indico_chat.models.chatrooms import Chatroom
|
||||
from indico_chat.xmpp import generate_jid, room_exists
|
||||
|
||||
|
||||
class AttachChatroomForm(IndicoForm):
|
||||
chatroom = QuerySelectField(_('Available chatrooms'), [DataRequired()], get_label='name')
|
||||
|
||||
|
||||
class EditChatroomForm(IndicoForm):
|
||||
event_specific_fields = {'hidden', 'show_password'}
|
||||
|
||||
|
||||
@ -91,22 +91,13 @@
|
||||
<a class="i-button bottom i-form-button icon-plus" href="{{ url_for_plugin('.manage_rooms_create', event) }}">{% trans %}Create new room{% endtrans %}</a>
|
||||
</div>
|
||||
|
||||
{% if available_chatrooms %}
|
||||
{% if attach_form %}
|
||||
<div>
|
||||
<h2>{% trans %}Add existing chat room{% endtrans %}</h2>
|
||||
<div>
|
||||
{{ form_header(action=url_for_plugin('.manage_rooms_attach', event), method='post') }}
|
||||
<div class="form-group">
|
||||
<div class="form-label form-block form-label-middle">{% trans %}Available chatrooms{% endtrans %}</div>
|
||||
<div class="form-field form-block">
|
||||
<select name="chatroom_id">
|
||||
{% for chatroom in available_chatrooms -%}
|
||||
<option value="{{ chatroom.id }}">{{ chatroom.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{% call form_footer() %}
|
||||
{{ form_header(attach_form, action=url_for_plugin('.manage_rooms_attach', event)) }}
|
||||
{{ form_row(attach_form.chatroom) }}
|
||||
{% call form_footer(attach_form) %}
|
||||
<input class="i-button big highlight" type="submit" value="{% trans %}Attach existing room{% endtrans %}">
|
||||
{% endcall %}
|
||||
</div>
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ form_header(id='chatroom-form') }}
|
||||
{{ form_header(form, id='chatroom-form') }}
|
||||
|
||||
{% call form_fieldset(legend='Chatroom settings') %}
|
||||
{{ form_rows(form, skip=form.event_specific_fields) }}
|
||||
@ -23,8 +23,8 @@
|
||||
{{ form_rows(form, fields=form.event_specific_fields) }}
|
||||
{% endcall %}
|
||||
|
||||
{% call form_footer() %}
|
||||
<input class="i-button big highlight" type="submit" value="{% trans %}Save{% endtrans %}">
|
||||
{% call form_footer(form) %}
|
||||
<input class="i-button big highlight" type="submit" value="{% trans %}Save{% endtrans %}" data-disabled-until-change>
|
||||
<a href="{{ url_for_plugin('.manage_rooms', event) }}" class="i-button big">{% trans %}Cancel{% endtrans %}</a>
|
||||
{% endcall %}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user