Exemplo n.º 1
0
def fixture_add_activity(obj,
                         verb="post",
                         target=None,
                         generator=None,
                         actor=None):
    if generator is None:
        generator = Generator(name="GNU MediaGoblin", object_type="service")
        generator.save()

    if actor is None:
        actor = fixture_add_user()

    activity = Activity(
        verb=verb,
        actor=actor.id,
        generator=generator.id,
    )

    activity.set_object(obj)

    if target is not None:
        activity.set_target(target)

    activity.save()
    return activity
Exemplo n.º 2
0
def create_activity(verb, obj, actor, target=None, generator=None):
    """
    This will create an Activity object which for the obj if possible
    and save it. The verb should be one of the following:
        add, author, create, delete, dislike, favorite, follow
        like, post, share, unfollow, unfavorite, unlike, unshare,
        update, tag.

    If none of those fit you might not want/need to create an activity for
    the object. The list is in mediagoblin.db.models.Activity.VALID_VERBS
    """
    # exception when we try and generate an activity with an unknow verb
    # could change later to allow arbitrary verbs but at the moment we'll play
    # it safe.

    if verb not in Activity.VALID_VERBS:
        raise ValueError("A invalid verb type has been supplied.")

    if generator is None:
        # This should exist as we're creating it by the migration for Generator
        generator = Generator.query.filter_by(name="GNU MediaGoblin").first()
        if generator is None:
            generator = Generator(
                name="GNU MediaGoblin",
                object_type="service"
            )
            generator.save()

    # Ensure the object has an ID which is needed by the activity.
    obj.save(commit=False)

    # Create the activity
    activity = Activity(verb=verb)
    activity.object = obj

    if target is not None:
        activity.target = target

   # If they've set it override the actor from the obj.
    activity.actor = actor.id if isinstance(actor, User) else actor
    activity.generator = generator.id
    activity.save()

    # Sigh want to do this prior to save but I can't figure a way to get
    # around relationship() not looking up object when model isn't saved.
    if activity.generate_content():
        activity.save()

    return activity
def fixture_add_activity(obj, verb="post", target=None, generator=None, actor=None):
    if generator is None:
        generator = Generator(
            name="GNU MediaGoblin",
            object_type="service"
        )
        generator.save()

    if actor is None:
        actor = fixture_add_user()

    activity = Activity(
        verb=verb,
        actor=actor.id,
        generator=generator.id,
    )

    activity.set_object(obj)

    if target is not None:
        activity.set_target(target)

    activity.save()
    return activity
Exemplo n.º 4
0
def create_activity(verb, obj, actor, target=None, generator=None):
    """
    This will create an Activity object which for the obj if possible
    and save it. The verb should be one of the following:
        add, author, create, delete, dislike, favorite, follow
        like, post, share, unfollow, unfavorite, unlike, unshare,
        update, tag.

    If none of those fit you might not want/need to create an activity for
    the object. The list is in mediagoblin.db.models.Activity.VALID_VERBS
    """
    # exception when we try and generate an activity with an unknow verb
    # could change later to allow arbitrary verbs but at the moment we'll play
    # it safe.

    if verb not in Activity.VALID_VERBS:
        raise ValueError("A invalid verb type has been supplied.")

    if generator is None:
        # This should exist as we're creating it by the migration for Generator
        generator = Generator.query.filter_by(name="GNU MediaGoblin").first()
        if generator is None:
            generator = Generator(name="GNU MediaGoblin",
                                  object_type="service")
            generator.save()

    # Ensure the object has an ID which is needed by the activity.
    obj.save(commit=False)

    # Create the activity
    activity = Activity(verb=verb)
    activity.object = obj

    if target is not None:
        activity.target = target

# If they've set it override the actor from the obj.
    activity.actor = actor.id if isinstance(actor, User) else actor
    activity.generator = generator.id
    activity.save()

    # Sigh want to do this prior to save but I can't figure a way to get
    # around relationship() not looking up object when model isn't saved.
    if activity.generate_content():
        activity.save()

    return activity