Beispiel #1
0
 def create(self, user, obj, **kwargs):
     """
     Create a new follow link between a user and an object
     of a registered model type.
     
     """
     follow = Follow(user=user)
     follow.target = obj
     follow.save()
     return follow
Beispiel #2
0
 def create(self, user, obj, **kwargs):
     """
     Create a new follow link between a user and an object
     of a registered model type.
     
     """
     follow = Follow(user=user)
     follow.target = obj
     follow.save()
     return follow
def follow_own_user_object(sender, instance, created, raw, **kwargs):
    if raw or instance.id == settings.ANONYMOUS_USER_ID:
        # Don't create when importing via loaddata - they're already
        # being imported.
        return
    if settings.IN_API_TEST:
        # XXX TODO Due to some horrible, difficult to figure out bug in
        # how force_authenticate() works in the API tests,
        # we have to skip signals here :/
        return
    if created:
        f = Follow(user=instance, target_user=instance)
        f.save()
def follow_own_user_object(sender, instance, created, raw, **kwargs):
    if raw or instance.id == settings.ANONYMOUS_USER_ID:
        # Don't create when importing via loaddata - they're already
        # being imported.
        return
    if settings.IN_API_TEST:
        # XXX TODO Due to some horrible, difficult to figure out bug in
        # how force_authenticate() works in the API tests,
        # we have to skip signals here :/
        return
    if created:
        f = Follow(user=instance, target_user=instance)
        f.save()
Beispiel #5
0
def get_follower_list(data, username, db_session):
    logger.info(LogMsg.START, username)

    result = []

    user = check_user(username, db_session)
    if user is None:
        raise Http_error(400, Message.INVALID_USER)

    if user.person_id is None:
        logger.error(LogMsg.USER_HAS_NO_PERSON, username)
        raise Http_error(400, Message.Invalid_persons)

    validate_person(user.person_id, db_session)
    logger.debug(LogMsg.PERSON_EXISTS)

    if data.get('sort') is None:
        data['sort'] = ['creation_date-']

    if data.get('filter') is None:
        data.update({'filter': {'following_id': user.person_id}})
    else:
        data['filter'].update({'following_id': user.person_id})

    res = Follow.mongoquery(db_session.query(Follow)).query(**data).end().all()
    for item in res:
        result.append(follow_to_dict(item))
    logger.debug(LogMsg.FOLLOWER_LIST, result)
    logger.info(LogMsg.END)

    return result
def re_add_users_following_before_delete(instance):
    # First, let's see if this page existed before.
    if instance.versions.all().count() > 2:
        # Now let's get the version before it was deleted
        before_delete = instance.versions.all()[2]

        past_follows = Follow.versions.filter(target_page__id=before_delete.id)

        # Now, re-follow.
        for follow in follows_before_cascade(past_follows):
            f = Follow(user=follow.user, target_page=instance)
            # For versioning purposes, let's keep the same pk
            # we had before delete.
            f.id = follow.id
            # We set TYPE_REVERTED here because it's slightly
            # more accurate than the (default) TYPE_ADDED.
            f._history_type = TYPE_REVERTED
            f.save()
def _maybe_follow_region(page):
    from follow.models import Follow

    user_edited = page.versions.most_recent().version_info.user
    if not user_edited:
        return

    # User doesn't follow any regions yet.
    if not Follow.objects.filter(user=user_edited).exclude(target_region=None).exists():
        # Auto-follow this region
        Follow(user=user_edited, target_region=page.region).save()
Beispiel #8
0
def add(db_session, data, username):
    logger.info(LogMsg.START, username)

    schema_validate(data, ADD_SCHEMA_PATH)
    logger.debug(LogMsg.SCHEMA_CHECKED)

    following_id = data.get('following_id')

    user = check_user(username, db_session)
    if user is None:
        raise Http_error(400, Message.INVALID_USER)

    if user.person_id is None:
        logger.error(LogMsg.USER_HAS_NO_PERSON, username)
        raise Http_error(400, Message.Invalid_persons)

    validate_person(user.person_id, db_session)
    validate_person(following_id, db_session)
    logger.debug(LogMsg.PERSON_EXISTS)

    if following_id == user.person_id:
        logger.error(LogMsg.FOLLOW_SELF_DENIED)
        raise Http_error(400, Message.FOLLOW_DENIED)

    logger.debug(LogMsg.FOLLOW_CHECK, data)
    follow = get(user.person_id, following_id, db_session)
    if follow is not None:
        logger.error(LogMsg.FOLLOW_EXISTS, data)
        raise Http_error(409, Message.ALREADY_FOLLOWS)

    model_instance = Follow()
    model_instance.id = str(uuid4())
    model_instance.creation_date = Now()
    model_instance.creator = username
    model_instance.version = 1
    model_instance.tags = data.get('tags')

    model_instance.following_id = following_id
    model_instance.follower_id = user.person_id

    db_session.add(model_instance)
    logger.debug(LogMsg.FOLLOW_ADD, follow_to_dict(model_instance))
    logger.info(LogMsg.END)

    return model_instance
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Don't use "from appname.models import ModelName".
        # Use orm.ModelName to refer to models in this application,
        # and orm['appname.ModelName'] for models in other applications.
        for u in User.objects.all():
            # If hasn't edited, skip.
            if not Page.versions.filter(history_user=u).exists():
                continue

            page_edits = Page.versions.filter(history_user=u)
            most_recent_region = page_edits[0].region

            if not Follow.objects.filter(user=u,
                                         target_region=most_recent_region):
                # Follow the most recently edited region
                print 'Following', most_recent_region, 'on user', u
                Follow(user=u, target_region=most_recent_region).save()
def re_add_users_following_before_delete(instance):
    # First, let's see if this page existed before.
    if instance.versions.all().count() > 2:
        # Now let's get the version before it was deleted
        before_delete = instance.versions.all()[2]

        past_follows = Follow.versions.filter(target_page__id=before_delete.id)

        # Now, re-follow.
        for follow in follows_before_cascade(past_follows):
            f = Follow(user=follow.user, target_page=instance)
            # For versioning purposes, let's keep the same pk
            # we had before delete.
            f.id = follow.id
            # We set TYPE_REVERTED here because it's slightly
            # more accurate than the (default) TYPE_ADDED.
            f._history_type = TYPE_REVERTED
            f.save()
 def forwards(self, orm):
     for u in User.objects.all():
         if not Follow.objects.filter(user=u, target_user=u):
             Follow(user=u, target_user=u).save()
def create_follows():

	Follow.objects.all().delete()

	for pk, fields in follows.iteritems():

		try:
			f = Follow(pk=pk)
			f.user_id = get_user(fields['user'])
			if fields['object_type'] == 'dateaaction':
				campaign = Campaign.objects.get(pk=fields['object_id'])
				f.content_object = campaign.main_tag
				f.follow_key = 'tag.'+str(campaign.main_tag.pk)
				f.object_id = campaign.main_tag.pk
				f.client_domain = datea
				f.save()
			elif fields['object_type'] == 'dateamapitem':
				dateo = Dateo.object.get(pk=fields['object_id'])
				f.content_object = dateo
				f.object_id = dateo.pk
				f.follow_key = 'dateo.'+str(dateo.pk)
				f.client_domain = datea
				f.save()
		except:
			pass
 def forwards(self, orm):
     for rs in RegionSettings.objects.all():
         for u in rs.admins.all():
             if not Follow.objects.filter(user=u, target_region=rs.region):
                 Follow(user=u, target_region=rs.region).save()