Example #1
0
def cinema_reviews_factory(entity, state, root,
                           sites=None, access_control=None):
    """The cinema review factory. Add a cinema review to the 'root'.
       'entity' is a dict contains data,
       'state' the state of the added cinema review,
       'sites' site ids by service,
       'access_control' site ids if not sites"""

    access_control = get_access_control(entity, sites, access_control)
    if access_control:
        if 'tree' in entity and ROOT_TREE not in entity['tree']:
            entity['tree'] = {ROOT_TREE: entity['tree']}

        obj = create_object('cinema_review', entity)
        obj.state.append(state)
        obj.access_control = PersistentList(access_control)
        root.addtoproperty('reviews', obj)
        if state == 'published':
            tree = getattr(obj, '_tree', None)
            if tree:
                sites = [_get_obj(s) for s in access_control]
                root.merge_tree(tree)
                for site in [s for s in sites if s]:
                    site.merge_tree(tree)

            for artist in obj.artists:
                publish_artist(artist)

            for director in obj.directors:
                publish_artist(director)

        obj.reindex()
Example #2
0
def cinema_reviews_factory(entity,
                           state,
                           root,
                           sites=None,
                           access_control=None):
    """The cinema review factory. Add a cinema review to the 'root'.
       'entity' is a dict contains data,
       'state' the state of the added cinema review,
       'sites' site ids by service,
       'access_control' site ids if not sites"""

    access_control = get_access_control(entity, sites, access_control)
    if access_control:
        if 'tree' in entity and ROOT_TREE not in entity['tree']:
            entity['tree'] = {ROOT_TREE: entity['tree']}

        obj = create_object('cinema_review', entity)
        obj.state.append(state)
        obj.access_control = PersistentList(access_control)
        root.addtoproperty('reviews', obj)
        if state == 'published':
            tree = getattr(obj, '_tree', None)
            if tree:
                sites = [_get_obj(s) for s in access_control]
                root.merge_tree(tree)
                for site in [s for s in sites if s]:
                    site.merge_tree(tree)

            for artist in obj.artists:
                publish_artist(artist)

            for director in obj.directors:
                publish_artist(director)

        obj.reindex()
Example #3
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        context.state = PersistentList(['published'])
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        published = [context]
        root = getSite()
        if getattr(context, '_tree', None):
            tree = getattr(context, '_tree')
            request.get_site_folder.merge_tree(tree)
            root.merge_tree(tree)

        not_published_artists = [a for a in context.artists
                                 if 'published' not in a.state]
        published.extend(not_published_artists)
        for artist in not_published_artists:
            publish_artist(artist, request, user)

        not_published_directors = [a for a in getattr(context, 'directors', [])
                                   if 'published' not in a.state]
        published.extend(not_published_directors)
        for director in not_published_directors:
            publish_artist(director, request, user)

        context.release_date = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        author = getattr(context, 'author', None)
        if author and user is not author:
            site = get_site_folder(True, request)
            alert('internal', [site], [author],
                  {'kind': InternalAlertKind.moderation_alert,
                   'subjects': [context]})

        request.registry.notify(ActivityExecuted(
            self, published, user))
        return {}
Example #4
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        artists, new_artists = extract_artists(
            appstruct.pop('artists', []), request)
        directors, new_directors = extract_artists(
            appstruct.pop('directors', []),
            request, is_directors=True)
        appstruct.pop('artists_ids')
        appstruct.pop('directors_ids')
        if appstruct.get('picture', None) is not None and \
            OBJECT_DATA in appstruct['picture']:
            appstruct['picture'] = appstruct['picture'][OBJECT_DATA]
            if not getattr(appstruct['picture'], '__name__', None):
                appstruct['picture'].__name__ = 'picture'

        context.set_metadata(appstruct)
        context.set_data(appstruct)
        context.setproperty('artists', artists)
        context.setproperty('directors', directors)
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        if 'published' in context.state:
            not_published_artists = [a for a in context.artists
                                     if 'published' not in a.state]
            not_published_artists.extend(
                [a for a in context.directors
                 if 'published' not in a.state])
            for artist in not_published_artists:
                publish_artist(artist, request, user)

        context.reindex()
        new_objects = new_artists
        new_objects.extend(new_directors)
        new_objects.append(context)
        request.registry.notify(ActivityExecuted(self, new_objects, user))
        return {}
Example #5
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        context.state = PersistentList(['published'])
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        published = [context]
        if getattr(context, '_tree', None):
            tree = getattr(context, '_tree')
            request.get_site_folder.merge_tree(tree)
            getSite().merge_tree(tree)

        not_published_artists = [a for a in context.artists
                                 if 'published' not in a.state]
        published.extend(not_published_artists)
        for artist in not_published_artists:
            publish_artist(artist, request, user)

        not_published_directors = [a for a in context.directors
                                   if 'published' not in a.state]
        published.extend(not_published_directors)
        for director in not_published_directors:
            publish_artist(director, request, user)

        request.registry.notify(ActivityExecuted(self, published, user))
        return {}
Example #6
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        artists, new_artists = extract_artists(
            appstruct.get('artists', []), request)
        context.setproperty('artists', artists)
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.set_metadata(appstruct)
        if 'published' in context.state:
            not_published_artists = [a for a in context.artists
                                     if 'published' not in a.state]
            for artist in not_published_artists:
                publish_artist(artist, request, user)

        context.reindex()
        new_objects = new_artists
        new_objects.append(context)
        request.registry.notify(ActivityExecuted(self, new_objects, user))
        return {}
Example #7
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        artists, new_artists = extract_artists(appstruct.get('artists', []),
                                               request)
        context.setproperty('artists', artists)
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.set_metadata(appstruct)
        if 'published' in context.state:
            not_published_artists = [
                a for a in context.artists if 'published' not in a.state
            ]
            for artist in not_published_artists:
                publish_artist(artist, request, user)

        context.reindex()
        new_objects = new_artists
        new_objects.append(context)
        request.registry.notify(ActivityExecuted(self, new_objects, user))
        return {}
Example #8
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        context.state = PersistentList(['published'])
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        published = [context]
        root = getSite()
        if getattr(context, '_tree', None):
            tree = getattr(context, '_tree')
            request.get_site_folder.merge_tree(tree)
            root.merge_tree(tree)

        not_published_artists = [
            a for a in context.artists if 'published' not in a.state
        ]
        published.extend(not_published_artists)
        for artist in not_published_artists:
            publish_artist(artist, request, user)

        not_published_directors = [
            a for a in getattr(context, 'directors', [])
            if 'published' not in a.state
        ]
        published.extend(not_published_directors)
        for director in not_published_directors:
            publish_artist(director, request, user)

        context.release_date = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        author = getattr(context, 'author', None)
        if author and user is not author:
            site = get_site_folder(True, request)
            alert('internal', [site], [author], {
                'kind': InternalAlertKind.moderation_alert,
                'subjects': [context]
            })

        request.registry.notify(ActivityExecuted(self, published, user))
        return {}
Example #9
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        artists, new_artists = extract_artists(appstruct.pop('artists', []),
                                               request)
        directors, new_directors = extract_artists(appstruct.pop(
            'directors', []),
                                                   request,
                                                   is_directors=True)
        appstruct.pop('artists_ids')
        appstruct.pop('directors_ids')
        if appstruct.get('picture', None) is not None and \
            OBJECT_DATA in appstruct['picture']:
            appstruct['picture'] = appstruct['picture'][OBJECT_DATA]
            if not getattr(appstruct['picture'], '__name__', None):
                appstruct['picture'].__name__ = 'picture'

        context.set_metadata(appstruct)
        context.set_data(appstruct)
        context.setproperty('artists', artists)
        context.setproperty('directors', directors)
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        if 'published' in context.state:
            not_published_artists = [
                a for a in context.artists if 'published' not in a.state
            ]
            not_published_artists.extend(
                [a for a in context.directors if 'published' not in a.state])
            for artist in not_published_artists:
                publish_artist(artist, request, user)

        context.reindex()
        new_objects = new_artists
        new_objects.extend(new_directors)
        new_objects.append(context)
        request.registry.notify(ActivityExecuted(self, new_objects, user))
        return {}
Example #10
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        user = get_current()
        appstruct.pop('_csrf_token_')
        artists, new_artists = extract_artists(appstruct.pop('artists', []),
                                               request)
        appstruct.pop('artists_ids')
        schedules = []
        new_venues = []
        for schedule_data in appstruct['schedules']:
            schedule = schedule_data[OBJECT_DATA]
            venue_data = schedule_data.get('venue', None)
            if venue_data:
                venue, is_new = extract_venue(venue_data, request)
                if is_new:
                    new_venues.append(venue)

                schedule.setproperty('venue', venue)

            schedules.append(schedule)

        appstruct['schedules'] = schedules
        schedules_to_remove = [
            s for s in context.schedules if s not in appstruct['schedules']
        ]
        for schedule in appstruct['schedules']:
            schedule.state = PersistentList(['created'])
            if not getattr(schedule, '__parent__', None):
                root.addtoproperty('schedules', schedule)

            schedule.reindex_dates()
            if schedule_expired(schedule):
                schedule.state.append('archived')
                schedule.reindex()

        group_venues(new_venues, request)
        if 'picture' in appstruct and appstruct['picture'] and \
            OBJECT_DATA in appstruct['picture']:
            appstruct['picture'] = appstruct['picture'][OBJECT_DATA]
            if not getattr(appstruct['picture'], '__name__', None):
                appstruct['picture'].__name__ = 'picture'

        context.set_metadata(appstruct)
        context.set_data(appstruct)
        for schedule in schedules_to_remove:
            root.delfromproperty('schedules', schedule)

        context.setproperty('artists', artists)
        #context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        remove_addresses_coordinates(new_venues)
        if 'published' in context.state:
            not_published_venues = [
                s.venue for s in context.schedules
                if s.venue and 'published' not in s.venue.state
            ]
            for venue in not_published_venues:
                publish_venue(venue, request, user)

            not_published_artists = [
                a for a in context.artists if 'published' not in a.state
            ]
            for artist in not_published_artists:
                publish_artist(artist, request, user)

        context.reindex()
        new_objects = new_venues
        new_objects.extend(new_artists)
        new_objects.append(context)
        request.registry.notify(ActivityExecuted(self, new_objects, user))
        return {}
Example #11
0
    def start(self, context, request, appstruct, **kw):
        #TODO published
        user = get_current()
        root = request.root
        site = get_site_folder(True, request)
        published = [context]
        author = context.author
        if author:
            if user is not author:
                alert('internal', [site], [author],
                      {'kind': InternalAlertKind.moderation_alert,
                       'subjects': [context]})

            site = request.get_site_folder
            mail_template = site.get_mail_template('acceptance_statement_event')
            subject = mail_template['subject'].format()
            mail = mail_template['template'].format(
                member=getattr(author, 'name', ''),
                url=request.resource_url(context, '@@index'))
            alert('email', [site.get_site_sender()], [author.email],
                  {'subject': subject, 'body': mail})

        context.state = PersistentList(['published'])
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        if getattr(context, '_tree', None):
            tree = getattr(context, '_tree')
            request.get_site_folder.merge_tree(tree)
            root.merge_tree(tree)

        not_published_artists = [a for a in context.artists
                                 if 'published' not in a.state]
        published.extend(not_published_artists)
        for artist in not_published_artists:
            publish_artist(artist, request, user)

        not_published_venues = [s.venue for s in context.schedules if s.venue
                                and 'published' not in s.venue.state]
        published.extend(not_published_venues)
        for venue in not_published_venues:
            publish_venue(venue, request, user)

        original = context.original
        if original and 'published' in original.state:
            original.state = PersistentList(['archived'])
            original.reindex()
            published.append(original)
            author = getattr(original, 'author', None)
            request.registry.notify(ObjectReplaced(
                old_object=original,
                new_object=context
            ))
            if author and user is not author:
                alert('internal', [site], [author],
                      {'kind': InternalAlertKind.content_alert,
                       'subjects': [context],
                       'alert_kind': 'replaced',
                       'replaced_title': original.title})

        request.registry.notify(ActivityExecuted(
            self, published, user))
        return {}