Exemple #1
0
 def _process(self):
     form = AddChatroomForm(obj=FormDefaults(name=self.event.title),
                            date=self.event.start_dt_local)
     if form.validate_on_submit():
         chatroom = Chatroom(created_by_user=session.user)
         event_chatroom = ChatroomEventAssociation(event=self.event,
                                                   chatroom=chatroom)
         form.populate_obj(event_chatroom,
                           fields=form.event_specific_fields)
         form.populate_obj(chatroom, skip=form.event_specific_fields)
         chatroom.jid_node = form.jid_node.data
         db.session.add_all((chatroom, event_chatroom))
         db.session.flush()
         create_room(chatroom)
         notify_created(chatroom, self.event, session.user)
         self.event.log(EventLogRealm.management, EventLogKind.positive,
                        'Chat',
                        'Chatroom created: {}'.format(chatroom.name),
                        session.user)
         flash(_('Chatroom created'), 'success')
         return jsonify_data(flash=False)
     return jsonify_template('manage_event_edit.html',
                             render_plugin_template,
                             form=form,
                             event=self.event)
Exemple #2
0
 def validate_name(self, field):
     jid = generate_jid(field.data, self._date)
     if not jid:
         # This error is not very helpful to a user, but it is extremely unlikely - only if he uses a name
         # which does not contain a single char usable in a JID
         raise ValidationError(_('Could not convert name to a jabber ID'))
     if Chatroom.find_first(jid_node=jid, custom_server=self.custom_server.data):
         raise ValidationError(_('A room with this name already exists'))
     if not self.custom_server.data:
         tmp_room = Chatroom(jid_node=jid)
         if room_exists(tmp_room.jid):
             raise ValidationError(_('A room with this name/JID already exists on the Jabber server ({0})').format(
                 tmp_room.jid
             ))
Exemple #3
0
 def _process(self):
     form = AddChatroomForm(obj=FormDefaults(name=self.event.title),
                            date=self.event.start_dt_local)
     if form.validate_on_submit():
         chatroom = Chatroom(created_by_user=session.user)
         event_chatroom = ChatroomEventAssociation(event=self.event, chatroom=chatroom)
         form.populate_obj(event_chatroom, fields=form.event_specific_fields)
         form.populate_obj(chatroom, skip=form.event_specific_fields)
         chatroom.jid_node = form.jid_node.data
         db.session.add_all((chatroom, event_chatroom))
         db.session.flush()
         create_room(chatroom)
         notify_created(chatroom, self.event, session.user)
         self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat',
                        'Chatroom created: {}'.format(chatroom.name), session.user)
         flash(_('Chatroom created'), 'success')
         return jsonify_data(flash=False)
     return jsonify_template('manage_event_edit.html', render_plugin_template, form=form, event=self.event)
 def _process(self):
     form = AddChatroomForm(obj=FormDefaults(name=to_unicode(self.event.title)),
                            date=self.event.getAdjustedStartDate())
     if form.validate_on_submit():
         chatroom = Chatroom(created_by_user=session.user)
         event_chatroom = ChatroomEventAssociation(event_id=self.event_id, chatroom=chatroom)
         form.populate_obj(event_chatroom, fields=form.event_specific_fields)
         form.populate_obj(chatroom, skip=form.event_specific_fields)
         chatroom.jid_node = form.jid_node.data
         db.session.add_all((chatroom, event_chatroom))
         db.session.flush()
         create_room(chatroom)
         notify_created(chatroom, self.event, session.user)
         self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat',
                        'Chatroom created: {}'.format(chatroom.name), session.user)
         flash(_('Chatroom created'), 'success')
         return redirect(url_for_plugin('.manage_rooms', self.event))
     return WPChatEventMgmt.render_template('manage_event_edit.html', self._conf, form=form, event=self.event)
    def migrate_chatrooms(self):
        print cformat('%{white!}migrating chatrooms')
        default_server = ChatPlugin.settings.get('muc_server')
        chatrooms = {}
        for old_room in committing_iterator(
                self.chat_root['indexByID']._data.itervalues()):
            has_custom_server = not old_room._createdInLocalServer and old_room._host != default_server
            custom_server = convert_to_unicode(
                old_room._host) if has_custom_server else ''
            identifier = (custom_server, old_room._name.lower())
            room = chatrooms.get(identifier)
            if room:
                print cformat(
                    '- %{cyan}{}   %{yellow!}DUPLICATE%{reset}').format(
                        room.name)
            else:
                user = User.get(int(old_room._owner.id)) or User.get(
                    Config.getInstance().getJanitorUserId())
                room = Chatroom(
                    jid_node=convert_to_unicode(old_room._name.lower()),
                    name=convert_to_unicode(old_room._name),
                    description=convert_to_unicode(old_room._description),
                    password=convert_to_unicode(old_room._password),
                    custom_server=custom_server,
                    created_by_user=user,
                    created_dt=old_room._creationDate,
                    modified_dt=old_room._modificationDate)
                chatrooms[identifier] = room
                db.session.add(room)
                print cformat('- %{cyan}{}').format(room.name)
                if room.custom_server:
                    print cformat(
                        '  %{blue!}Custom server:%{reset} {}').format(
                            room.custom_server)

            events = set()
            for event in old_room._conferences:
                assoc = ChatroomEventAssociation(
                    event_id=int(event),
                    chatroom=room,
                    hidden=not old_room._showRoom,
                    show_password=old_room._showPass)
                db.session.add(assoc)
                events.add(assoc.event_id)
            if events:
                print cformat('  %{blue!}Events:%{reset} {}').format(', '.join(
                    map(unicode, events)))
            else:
                print cformat('  %{yellow!}no events%{reset}')
 def has_data(self):
     return Chatroom.find().count()
 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
Exemple #8
0
 def has_data(self):
     return Chatroom.find().count()