Beispiel #1
0
    def submit_success(self, appstruct):
        """
        Create a new workshop
        """
        come_from = appstruct.pop('come_from')

        timeslots_datas = appstruct.pop('timeslots')
        for i in timeslots_datas:
            i.pop('id', None)

        timeslots_datas.sort(key=lambda val: val['start_time'])

        appstruct['datetime'] = timeslots_datas[0]['start_time']
        appstruct['timeslots'] = [
            models.Timeslot(**data) for data in timeslots_datas
        ]

        participants_ids = set(appstruct.pop('participants', []))
        appstruct['participants'] = [
            user.User.get(id_) for id_ in participants_ids
        ]

        for timeslot in appstruct['timeslots']:
            timeslot.participants = appstruct['participants']

        trainers_ids = set(appstruct.pop('trainers', []))
        appstruct['trainers'] = [user.User.get(id_) for id_ in trainers_ids]

        # Current user by default
        if (self.request.has_permission('edit_owner.event')
                and appstruct.get('owner')):
            appstruct['owner'] = user.User.get(appstruct['owner'])
        else:
            appstruct['owner'] = user.User.get(self.request.user.id)

        workshop_obj = models.Workshop(**appstruct)

        workshop_obj = merge_session_with_post(
            workshop_obj,
            appstruct,
            remove_empty_values=False,
        )
        self.dbsession.add(workshop_obj)
        self.dbsession.flush()

        workshop_url = self.request.route_path("workshop",
                                               id=workshop_obj.id,
                                               _query=dict(action="edit"))

        if not come_from:
            redirect = workshop_url
        else:
            msg = WORKSHOP_SUCCESS_MSG.format(workshop_url)
            self.session.flash(msg)
            redirect = come_from
        return HTTPFound(redirect)
Beispiel #2
0
def workshop_model(dbsession):
    appstruct = {
        'name': 'Workshop',
        'leaders': ['user1', 'user2'],
        'datetime': date.today(),
        'info1': 'Header1',
    }
    w = workshop.Workshop(**appstruct)

    start = datetime(2014, 06, 12, 8)
    stop = datetime(2014, 06, 12, 12)
    timeslot = workshop.Timeslot(
        name=u'matinée',
        start_time=start,
        end_time=stop,
    )
    w.timeslots.append(timeslot)
    dbsession.add(w)
    dbsession.flush()
    return w
Beispiel #3
0
def workshop_model(dbsession, workshop_action, user):
    appstruct = {
        'name': 'Workshop',
        'description': 'test desc',
        'owner': user,
        'datetime': date.today(),
        'info1_id': workshop_action.id,
    }
    w = workshop.Workshop(**appstruct)

    start = datetime(2014, 06, 12, 8)
    stop = datetime(2014, 06, 12, 12)
    timeslot = workshop.Timeslot(
        name=u'matinée',
        start_time=start,
        end_time=stop,
    )
    w.timeslots.append(timeslot)
    dbsession.add(w)
    dbsession.flush()
    return w
Beispiel #4
0
    def submit_success(self, appstruct):
        """
        Create a new workshop
        """
        come_from = appstruct.pop('come_from')

        timeslots_datas = appstruct.pop('timeslots')
        for i in timeslots_datas:
            i.pop('id', None)

        timeslots_datas.sort(key=lambda val: val['start_time'])

        appstruct['datetime'] = timeslots_datas[0]['start_time']
        appstruct['timeslots'] = [
            models.Timeslot(**data) for data in timeslots_datas
        ]

        participants_ids = set(appstruct.pop('participants', []))
        appstruct['participants'] = [
            user.User.get(id_) for id_ in participants_ids
        ]

        for timeslot in appstruct['timeslots']:
            timeslot.participants = appstruct['participants']

        workshop_obj = models.Workshop(**appstruct)
        self.dbsession.add(workshop_obj)
        self.dbsession.flush()

        workshop_url = self.request.route_path("workshop",
                                               id=workshop_obj.id,
                                               _query=dict(action="edit"))

        if not come_from:
            redirect = workshop_url
        else:
            msg = WORKSHOP_SUCCESS_MSG.format(workshop_url)
            self.session.flash(msg)
            redirect = come_from
        return HTTPFound(redirect)