Ejemplo n.º 1
0
def publish_venue(context, request=None, user=None):
    context.state = PersistentList(['published'])
    context.modified_at = datetime.datetime.now(tz=pytz.UTC)
    context.origin_oid = get_oid(context)
    original = context.original
    root = getattr(request, 'root', None) if request else getSite()
    site = get_site_folder(True, request)
    author = getattr(context, 'author', None)
    if author and user is not author:
        alert('internal', [site], [author], {
            'kind': InternalAlertKind.moderation_alert,
            'subjects': [context]
        })

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

            root.delfromproperty('venues', original)

    context.reindex()
Ejemplo n.º 2
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        user = get_current()
        venue = appstruct['_object_data']
        root.addtoproperty('venues', venue)
        venue.state = PersistentList(['editable'])
        grant_roles(user=user, roles=(('Owner', venue), ))
        venue.setproperty('author', user)
        venue.add_contributors(context.contributors)
        venue.add_contributors([user])
        venue.setproperty('original', context)
        venue.set_metadata(appstruct)
        venue.hash_venue_data()
        source = request.GET.get('source', '')
        if source:
            source_venue = get_obj(int(source))
            if source_venue:
                replaced = source_venue.replace_by(venue)
                if replaced:
                    request.registry.notify(
                        ObjectReplaced(old_object=source_venue,
                                       new_object=venue))
                    root.delfromproperty('venues', source_venue)

        venue.reindex()
        request.registry.notify(ActivityExecuted(self, [venue], user))
        return {'newcontext': venue}
Ejemplo n.º 3
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        user = get_current()
        artist = appstruct['_object_data']
        root.addtoproperty('artists', artist)
        artist.state = PersistentList(['editable'])
        grant_roles(user=user, roles=(('Owner', artist), ))
        artist.setproperty('author', user)
        artist.add_contributors(context.contributors)
        artist.add_contributors([user])
        artist.setproperty('original', context)
        artist.set_metadata(appstruct)
        artist.hash_picture_fp()
        artist.hash_artist_data()
        source = request.GET.get('source', '')
        if source:
            source_artist = get_obj(int(source))
            if source_artist:
                replaced = source_artist.replace_by(artist)
                if replaced:
                    request.registry.notify(
                        ObjectReplaced(old_object=source_artist,
                                       new_object=artist))
                    root.delfromproperty('artists', source_artist)

        artist.reindex()
        request.registry.notify(ActivityExecuted(self, [artist], user))
        return {'newcontext': artist}
Ejemplo n.º 4
0
 def start(self, context, request, appstruct, **kw):
     root = getSite()
     source = appstruct['source']
     targets = appstruct['targets']
     for artist in targets:
         replaced = artist.replace_by(source)
         if replaced:
             request.registry.notify(
                 ObjectReplaced(old_object=artist, new_object=source))
             root.delfromproperty('artists', artist)
     return {}
Ejemplo n.º 5
0
def extract_artists(artists_data, request, is_directors=False):
    root = request.root
    artists = []
    new_artists = []
    user = get_current()
    if artists_data:
        artists = [
            a.get(OBJECT_DATA) for a in artists_data if OBJECT_DATA in a
        ]
        new_artists = list(artists)

    for artist in list(artists):
        root.addtoproperty('artists', artist)
        artist.state = PersistentList(['editable'])
        grant_roles(roles=(('Owner', artist), ))
        artist.setproperty('author', user)
        artist.add_contributors([user])
        if is_directors:
            artist.is_director = is_directors

        artist.hash_picture_fp()
        artist.hash_artist_data()
        artist.reindex()
        if getattr(artist, 'origin_oid', None):
            origin = get_obj(artist.origin_oid, None)
            if origin and 'published' not in origin.state:
                replaced = origin.replace_by(artist)
                if replaced:
                    request.registry.notify(
                        ObjectReplaced(old_object=origin, new_object=artist))
                    root.delfromproperty('artists', origin)

            elif origin:
                if origin.eq(artist):
                    artists.remove(artist)
                    new_artists.remove(artist)
                    artists.append(origin)
                    root.delfromproperty('artists', artist)
                elif artist is not origin:
                    artist.setproperty('original', origin)
                    artist.add_contributors(origin.contributors)

        artist.origin_oid = get_oid(artist)

    return artists, new_artists
Ejemplo n.º 6
0
def group_venues(new_venues, request):
    root = request.root
    validate_venues = []
    for venue in new_venues:
        if venue not in validate_venues:
            venues = list(new_venues)
            venues.remove(venue)
            eq_venues = [v for v in venues if v.eq(venue)]
            if eq_venues:
                validate_venues.extend(eq_venues)
                validate_venues.append(venue)
                for eq_venue in venues:
                    replaced = eq_venue.replace_by(venue)
                    if replaced:
                        request.registry.notify(
                            ObjectReplaced(old_object=eq_venue,
                                           new_object=venue))
                        root.delfromproperty('venues', eq_venue)
Ejemplo n.º 7
0
    def start(self, context, request, appstruct, **kw):
        site = get_site_folder(True, request)
        user = get_current(request)
        is_manager = has_any_roles(
            user=user,
            roles=('Admin', ('SiteAdmin', site))) or\
            is_site_moderator(request)
        if is_manager or all(
                has_role(user=user, role=('Owner', v))
                for v in appstruct['targets'] if 'published' not in v.state):
            root = getSite()
            source = appstruct['source']
            targets = appstruct['targets']
            for venue in targets:
                replaced = venue.replace_by(source)
                if replaced:
                    request.registry.notify(
                        ObjectReplaced(old_object=venue, new_object=source))
                    root.delfromproperty('venues', venue)
        else:
            return {'error': True}

        return {}
Ejemplo n.º 8
0
def extract_venue(venue_data, request):
    root = request.root
    venue = venue_data.get(OBJECT_DATA, None)
    is_new = True
    result = None
    if venue:
        user = get_current()
        root.addtoproperty('venues', venue)
        venue.state = PersistentList(['editable'])
        grant_roles(roles=(('Owner', venue), ))
        venue.setproperty('author', user)
        venue.add_contributors([user])
        venue.hash_venue_data()
        venue.reindex()
        result = venue
        if getattr(venue, 'origin_oid', None):
            origin = get_obj(venue.origin_oid, None)
            if origin:
                if 'published' not in origin.state:
                    replaced = origin.replace_by(venue)
                    if replaced:
                        request.registry.notify(
                            ObjectReplaced(old_object=origin,
                                           new_object=venue))
                        root.delfromproperty('venues', origin)
                else:
                    if origin.eq(venue):
                        result = origin
                        is_new = False
                        root.delfromproperty('venues', venue)
                    elif venue is not origin:
                        venue.setproperty('original', origin)
                        venue.add_contributors(origin.contributors)

        venue.origin_oid = get_oid(venue)

    return result, is_new
Ejemplo n.º 9
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 {}