Esempio n. 1
0
def detail_view(request, celebrityid, userid):
    result = ''

    stalker_key = db.Key(userid)
    celebrity_key = db.Key(celebrityid)
    
    subscribed_string = 'false'
    subscribed = Subscription.all().filter('stalker', stalker_key).filter('celebrity', celebrity_key).fetch(1)
    if len(subscribed) > 0:
        subscribed_string = 'true'
    
    spottings_list = []
    last_spottings = Spotting.all().filter('celebrity',celebrity_key).order('-date').fetch(5)
    for spotting in last_spottings:
        date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
        location_name = spotting.location_name
        if location_name is None:
            try:
                location_name = _resolve_location(spotting.location)
            except:
                location_name = 'Cocoon'
        spottings_list.append({'spotting_id':str(spotting.key()), 'celebrity_id': str(spotting.celebrity.key()), 'celebrity_name': spotting.celebrity.name, 'location':location_name, 'comment':spotting.comment, 'date':date_string})
    
    spottings_json = simplejson.dumps(spottings_list)
    
    result = {'celebrity_id':str(spotting.celebrity.key()), 'celebrity_name':spotting.celebrity.name, 'following': subscribed_string, 'spottings':spottings_json}

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 2
0
def profile_view(request, userid):
    result = ''
    
    # See also http://stackoverflow.com/questions/5824801/serialize-an-entity-key-to-a-string-in-python-for-gae
    # stalker_key = db.Key.from_path('Stalker', '2')
    # stalker = db.get(stalker_key)

    stalker_key = db.Key(userid)
    # stalker = db.get(stalker_key)
    
    subscriptions_list = []
    subscriptions = Subscription.all().filter('stalker', stalker_key).fetch(FETCH_LIMIT)
    for subscription in subscriptions:
        subscriptions_list.append({'celebrity_id':str(subscription.celebrity.key()), 'name':subscription.celebrity.name})
    
    spottings_list = []
    spottings = Spotting.all().filter('stalker', stalker_key).fetch(FETCH_LIMIT)
    for spotting in spottings:
        date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
        spottings_list.append({'spotting_id':str(spotting.key()), 'celebrity_id': str(spotting.celebrity.key()), 'celebrity_name': spotting.celebrity.name, 'location':spotting.location, 'comment':spotting.comment, 'date':date_string})
    
    subscriptions_json = simplejson.dumps(subscriptions_list)
    spottings_json = simplejson.dumps(spottings_list)
    
    result = {'spottings_count': len(subscriptions), 'following_count': len(spottings), 'celebrities': subscriptions_json, 'spottings': spottings_json}

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 3
0
def personal_list_view(request, userid):
    result = [] #Ask
    
    stalker_key = db.Key(userid)
    subscriptions = Subscription.all().filter('stalker', stalker_key).fetch(FETCH_LIMIT)
    for subscription in subscriptions:
        spottings = Spotting.all().filter('celebrity',subscription.celebrity.key()).order('-date').fetch(25)
        for spotting in spottings:
            date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
            location_name = spotting.location_name
            if location_name is None:
                location_name = _resolve_location(spotting.location)
            result.append({'spotting_id':str(spotting.key()), 'celebrity_id': str(spotting.celebrity.key()), 'celebrity_name': spotting.celebrity.name, 'location':location_name, 'comment':spotting.comment, 'date':date_string})    

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 4
0
def profile_view(request, userid):
    result = ''

    # See also http://stackoverflow.com/questions/5824801/serialize-an-entity-key-to-a-string-in-python-for-gae
    # stalker_key = db.Key.from_path('Stalker', '2')
    # stalker = db.get(stalker_key)

    stalker_key = db.Key(userid)
    # stalker = db.get(stalker_key)

    subscriptions_list = []
    subscriptions = Subscription.all().filter('stalker',
                                              stalker_key).fetch(FETCH_LIMIT)
    for subscription in subscriptions:
        subscriptions_list.append({
            'celebrity_id':
            str(subscription.celebrity.key()),
            'name':
            subscription.celebrity.name
        })

    spottings_list = []
    spottings = Spotting.all().filter('stalker',
                                      stalker_key).fetch(FETCH_LIMIT)
    for spotting in spottings:
        date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
        spottings_list.append({
            'spotting_id': str(spotting.key()),
            'celebrity_id': str(spotting.celebrity.key()),
            'celebrity_name': spotting.celebrity.name,
            'location': spotting.location,
            'comment': spotting.comment,
            'date': date_string
        })

    subscriptions_json = simplejson.dumps(subscriptions_list)
    spottings_json = simplejson.dumps(spottings_list)

    result = {
        'spottings_count': len(subscriptions),
        'following_count': len(spottings),
        'celebrities': subscriptions_json,
        'spottings': spottings_json
    }

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 5
0
def unfollow_view(request):
    result = ''
    
    if request.method == 'POST':
        json_data = simplejson.loads(request.raw_post_data)
        stalker_id = json_data['user_id']
        celebrity_id = json_data['celebrity_id']
    
        celebrity_key = db.Key(celebrity_id)
        stalker_key = db.Key(stalker_id)
        subscription = Subscription.all().filter('celebrity', celebrity_key).filter('stalker', stalker_key).fetch(1)
        if len(subscription) == 1:
            subscription[0].delete()
            result = {'status':'success'}
        else:
            result = {'status':'failure'}

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 6
0
def unfollow_view(request):
    result = ''

    if request.method == 'POST':
        json_data = simplejson.loads(request.raw_post_data)
        stalker_id = json_data['user_id']
        celebrity_id = json_data['celebrity_id']

        celebrity_key = db.Key(celebrity_id)
        stalker_key = db.Key(stalker_id)
        subscription = Subscription.all().filter(
            'celebrity', celebrity_key).filter('stalker', stalker_key).fetch(1)
        if len(subscription) == 1:
            subscription[0].delete()
            result = {'status': 'success'}
        else:
            result = {'status': 'failure'}

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 7
0
def detail_view(request, celebrityid, userid):
    result = ''

    stalker_key = db.Key(userid)
    celebrity_key = db.Key(celebrityid)

    subscribed_string = 'false'
    subscribed = Subscription.all().filter('stalker', stalker_key).filter(
        'celebrity', celebrity_key).fetch(1)
    if len(subscribed) > 0:
        subscribed_string = 'true'

    spottings_list = []
    last_spottings = Spotting.all().filter(
        'celebrity', celebrity_key).order('-date').fetch(5)
    for spotting in last_spottings:
        date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
        location_name = spotting.location_name
        if location_name is None:
            try:
                location_name = _resolve_location(spotting.location)
            except:
                location_name = 'Cocoon'
        spottings_list.append({
            'spotting_id': str(spotting.key()),
            'celebrity_id': str(spotting.celebrity.key()),
            'celebrity_name': spotting.celebrity.name,
            'location': location_name,
            'comment': spotting.comment,
            'date': date_string
        })

    spottings_json = simplejson.dumps(spottings_list)

    result = {
        'celebrity_id': str(spotting.celebrity.key()),
        'celebrity_name': spotting.celebrity.name,
        'following': subscribed_string,
        'spottings': spottings_json
    }

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")
Esempio n. 8
0
def personal_list_view(request, userid):
    result = []  #Ask

    stalker_key = db.Key(userid)
    subscriptions = Subscription.all().filter('stalker',
                                              stalker_key).fetch(FETCH_LIMIT)
    for subscription in subscriptions:
        spottings = Spotting.all().filter(
            'celebrity', subscription.celebrity.key()).order('-date').fetch(25)
        for spotting in spottings:
            date_string = spotting.date.strftime("%Y-%m-%dT%H-%M-%S")
            location_name = spotting.location_name
            if location_name is None:
                location_name = _resolve_location(spotting.location)
            result.append({
                'spotting_id': str(spotting.key()),
                'celebrity_id': str(spotting.celebrity.key()),
                'celebrity_name': spotting.celebrity.name,
                'location': location_name,
                'comment': spotting.comment,
                'date': date_string
            })

    return HttpResponse(simplejson.dumps(result), mimetype="text/json")