示例#1
0
def buildURL(request, data, location, location_type, user_name=None, start_time=0, renderJSON=False, partial='spraycan.html', thetemplate=None, payload={}, to_time=INFINITE_TIME):
    loggedin = False if data == None or 'loggedin' not in data else data['loggedin']
    from webapp.views.user import INFINITE_TIME
    if user_name == None :
        user_name = data['user_name']
    urlform = SpraycanSearchURL({'search':location})
    if urlform.is_valid() or location_type == 'HUB' :
        if location_type == 'URL' :
            location_type = 'URL' if 'http' in str(location) else 'geo'
        if location_type != 'HUB' :
            ttags = ttagPost("/ttag/get",{'access_token': request.COOKIES.get('access_token',''), 'user_id': data['_id'],'location': str(location), 'location_type': location_type, 'start_time': start_time, 'end_time': to_time, 'search_on': 'time','page_number':0,'items_per_page':ITEMS_PER_PAGE})
        else :
            hub_id = location.split('#')[0]
            ttagdata = {'hub_id':hub_id,"from_time":start_time,"to_time":to_time,'page_number':0,'items_per_page':ITEMS_PER_PAGE}
            if request.COOKIES.get('access_token',None) != None :
                ttagdata['access_token'] = request.COOKIES['access_token']
                ttagdata['user_id'] = data['_id']
            ttags = ttagPost("/find/hub-ttags",ttagdata)
        if ttags['result'] == 'OK' :
            import datetime
            if not renderJSON or 'spraycanAuto' not in request.session or request.session['spraycanAuto'] :
                request.session['start_time'] = ttags['time']
            else :
                request.session['start_time'] = start_time
            from webapp.views.user import getUserFollowers
            loggedin_user = data['_id']
            if 'total_count' in ttags['data'] and ttags['data']['total_count'] > ITEMS_PER_PAGE and 'ttags' in ttags['data'] :
                NEW_TIME = int(ttags['data']['ttags'][len(ttags['data']['ttags'])-1]['created_timestamp'])-1
            response = {'time': request.session['start_time'], 'data':{
                                'founder': [] if 'finder' not in ttags['data'] or ttags['data']['finder'] == None else ttags['data']['finder'],
                                'favorite': False if 'favorite' not in ttags['data'] else ttags['data']['favorite'],
                                'ttags':[] if ttags['data']['ttags'] == None else ttags['data']['ttags'],
                                'spams':[] if 'spams' not in ttags['data'] or ttags['data']['spams'] == None or 'ttag_list' not in ttags['data']['spams'] or ttags['data']['spams']['ttag_list'] == None else ttags['data']['spams']['ttag_list'],
                                'thumbups':[] if 'thumbups' not in ttags['data'] or ttags['data']['thumbups'] == None or 'ttag_list' not in ttags['data']['thumbups'] or ttags['data']['thumbups']['ttag_list'] == None else ttags['data']['thumbups']['ttag_list'],
                                'followers': getUserFollowers(loggedin_user)}}
            servertime = datetime.datetime.fromtimestamp(int(ttags['time'])/1000)
            if renderJSON :
                objReturn = {}
                ttags = render_to_response('partial_spraycan_ttags.html',locals(),context_instance=RequestContext(request))
                objReturn['manual_ttags'] = mark_safe(ttags.content)
                if 'spraycanAuto' in request.session and request.session['spraycanAuto'] :
                    objReturn['ttags'] = mark_safe(ttags.content)
                feed = render_to_response('partial_spraycan_feed.html',locals(),context_instance=RequestContext(request))
                objReturn['feed'] = mark_safe(feed.content)
                jsonReturn = simplejson.dumps(objReturn)
            thereturn = render_to_response(partial, locals(), context_instance=RequestContext(request))
        else :
            thereturn = render_to_response('ajax_ttag_create.html',{'jsonReturn':simplejson.dumps(ttags)})
    else :
        thereturn = hash(request)
    return thereturn
示例#2
0
def buildURL(request,
             data,
             location,
             location_type,
             user_name=None,
             start_time=0,
             renderJSON=False,
             partial='spraycan.html',
             thetemplate=None,
             payload={},
             to_time=INFINITE_TIME):
    loggedin = False if data == None or 'loggedin' not in data else data[
        'loggedin']
    from webapp.views.user import INFINITE_TIME
    if user_name == None:
        user_name = data['user_name']
    urlform = SpraycanSearchURL({'search': location})
    if urlform.is_valid() or location_type == 'HUB':
        if location_type == 'URL':
            location_type = 'URL' if 'http' in str(location) else 'geo'
        if location_type != 'HUB':
            ttags = ttagPost(
                "/ttag/get", {
                    'access_token': request.COOKIES.get('access_token', ''),
                    'user_id': data['_id'],
                    'location': str(location),
                    'location_type': location_type,
                    'start_time': start_time,
                    'end_time': to_time,
                    'search_on': 'time',
                    'page_number': 0,
                    'items_per_page': ITEMS_PER_PAGE
                })
        else:
            hub_id = location.split('#')[0]
            ttagdata = {
                'hub_id': hub_id,
                "from_time": start_time,
                "to_time": to_time,
                'page_number': 0,
                'items_per_page': ITEMS_PER_PAGE
            }
            if request.COOKIES.get('access_token', None) != None:
                ttagdata['access_token'] = request.COOKIES['access_token']
                ttagdata['user_id'] = data['_id']
            ttags = ttagPost("/find/hub-ttags", ttagdata)
        if ttags['result'] == 'OK':
            import datetime
            if not renderJSON or 'spraycanAuto' not in request.session or request.session[
                    'spraycanAuto']:
                request.session['start_time'] = ttags['time']
            else:
                request.session['start_time'] = start_time
            from webapp.views.user import getUserFollowers
            loggedin_user = data['_id']
            if 'total_count' in ttags['data'] and ttags['data'][
                    'total_count'] > ITEMS_PER_PAGE and 'ttags' in ttags[
                        'data']:
                NEW_TIME = int(
                    ttags['data']['ttags'][len(ttags['data']['ttags']) -
                                           1]['created_timestamp']) - 1
            response = {
                'time': request.session['start_time'],
                'data': {
                    'founder': [] if 'finder' not in ttags['data']
                    or ttags['data']['finder'] == None else
                    ttags['data']['finder'],
                    'favorite':
                    False if 'favorite' not in ttags['data'] else
                    ttags['data']['favorite'],
                    'ttags': [] if ttags['data']['ttags'] == None else
                    ttags['data']['ttags'],
                    'spams': [] if 'spams' not in ttags['data']
                    or ttags['data']['spams'] == None
                    or 'ttag_list' not in ttags['data']['spams']
                    or ttags['data']['spams']['ttag_list'] == None else
                    ttags['data']['spams']['ttag_list'],
                    'thumbups': [] if 'thumbups' not in ttags['data']
                    or ttags['data']['thumbups'] == None
                    or 'ttag_list' not in ttags['data']['thumbups']
                    or ttags['data']['thumbups']['ttag_list'] == None else
                    ttags['data']['thumbups']['ttag_list'],
                    'followers':
                    getUserFollowers(loggedin_user)
                }
            }
            servertime = datetime.datetime.fromtimestamp(
                int(ttags['time']) / 1000)
            if renderJSON:
                objReturn = {}
                ttags = render_to_response(
                    'partial_spraycan_ttags.html',
                    locals(),
                    context_instance=RequestContext(request))
                objReturn['manual_ttags'] = mark_safe(ttags.content)
                if 'spraycanAuto' in request.session and request.session[
                        'spraycanAuto']:
                    objReturn['ttags'] = mark_safe(ttags.content)
                feed = render_to_response(
                    'partial_spraycan_feed.html',
                    locals(),
                    context_instance=RequestContext(request))
                objReturn['feed'] = mark_safe(feed.content)
                jsonReturn = simplejson.dumps(objReturn)
            thereturn = render_to_response(
                partial, locals(), context_instance=RequestContext(request))
        else:
            thereturn = render_to_response(
                'ajax_ttag_create.html',
                {'jsonReturn': simplejson.dumps(ttags)})
    else:
        thereturn = hash(request)
    return thereturn
示例#3
0
def search(request):
    try:
        thereturn = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin:
            if 'search' in request.POST:
                atusername = ''
                emailform = SpraycanSearchEmail(request.POST)
                usernameform = SpraycanSearchUsername(request.POST)
                if emailform.is_valid():
                    resp = ttagPost('/validate/request-username-by-email',
                                    {'email': emailform.getSpraycan_Search()})
                    if resp['result'] == 'OK' and resp['find_by_email']:
                        atusername = resp['user_name']
                elif usernameform.is_valid():
                    resp = ttagRequestUserProfile(
                        usernameform.getSpraycan_Search()[1:])
                    if resp['result'] == 'OK':
                        atusername = resp['data']['user_name']
                if atusername != '':
                    #                from django.core.urlresolvers import reverse
                    #                return render_to_response("javascript_redirect.html", {"redirect_url" : reverse('user-profile', kwargs={'user_name':atusername,'view_type':'','page':'','time':''}),'hidespraycan':'true'})
                    from webapp.views.user import userWallView
                    return userWallView(request, atusername)
                form = SpraycanSearch(request.POST)
                if form.is_valid():
                    urlform = SpraycanSearchURL(request.POST)
                    if urlform.is_valid():
                        #show spraycan for URL
                        thereturn = url(request, urlform.getSpraycan_Search())
                    else:
                        #show search results
                        import datetime
                        from webapp.views.user import getUserFollowers
                        location_type = 'search'
                        loggedin_user = data['_id']
                        filter = request.POST.get('filter', "All")
                        ttags = ttagPost(
                            '/find/url-keyword-hashtag', {
                                'query': form.getSpraycan_Search(),
                                'items_per_page': '100',
                                'page_number': '0'
                            })
                        response = {
                            'time': ttags['time'],
                            'data': {
                                'founder': {},
                                'favorite':
                                False,
                                'ttags': [] if filter not in ['All', 'Tags']
                                or ttags['data'] == None
                                or 'ttags' not in ttags['data']
                                or ttags['data']['ttags'] == None else
                                ttags['data']['ttags'],
                                'users': [] if filter not in ['All', 'Users']
                                or ttags['data'] == None
                                or 'users' not in ttags['data']
                                or ttags['data']['users'] == None else
                                ttags['data']['users'],
                                'hashtags':
                                [] if filter not in ['All', 'HashTags']
                                or ttags['data'] == None
                                or 'hashtags' not in ttags['data']
                                or ttags['data']['hashtags'] == None else
                                ttags['data']['hashtags'],
                                'location':
                                [] if filter not in ['All', 'Locations']
                                or ttags['data'] == None
                                or 'location' not in ttags['data']
                                or ttags['data']['location'] == None else
                                ttags['data']['location'],
                                'hubs': [] if filter not in ['All', 'Hubs']
                                or ttags['data'] == None
                                or 'hubs' not in ttags['data']
                                or ttags['data']['hubs'] == None else
                                ttags['data']['hubs'],
                                'spams': [],
                                'thumbups': []
                            }
                        }
                        from webapp.models.hub import processRawHubs
                        response['data']['hubs'] = processRawHubs(
                            response['data']['hubs'], request)
                        response['data']['followers'] = getUserFollowers(
                            loggedin_user)
                        from webapp.views.user import getUserHubs
                        response['data']['joinedhubs'] = getUserHubs(
                            data['user_name'])
                        response['data']['searchcounts'] = {
                            'ttags':
                            0 if ttags['data'] == None
                            or 'ttags' not in ttags['data']
                            or ttags['data']['ttags'] == None else len(
                                ttags['data']['ttags']),
                            'users':
                            0 if ttags['data'] == None
                            or 'users' not in ttags['data']
                            or ttags['data']['users'] == None else len(
                                ttags['data']['users']),
                            'hashtags':
                            0 if ttags['data'] == None
                            or 'hashtags' not in ttags['data']
                            or ttags['data']['hashtags'] == None else len(
                                ttags['data']['hashtags']),
                            'location':
                            0 if ttags['data'] == None
                            or 'location' not in ttags['data']
                            or ttags['data']['location'] == None else len(
                                ttags['data']['location']),
                            'hubs':
                            0 if ttags['data'] == None
                            or 'hubs' not in ttags['data']
                            or ttags['data']['hubs'] == None else len(
                                ttags['data']['hubs'])
                        }
                        servertime = datetime.datetime.fromtimestamp(
                            int(ttags['time']) / 1000)
                        if request.is_ajax():
                            thetemplate = 'base_ajax.html'
                        thereturn = render_to_response(
                            "spraycan.html",
                            locals(),
                            context_instance=RequestContext(request))
                    if request.is_ajax():
                        usercontext = mark_safe(
                            render_to_response('partial_user_details.html',
                                               locals(),
                                               context_instance=RequestContext(
                                                   request)).content)
                        import simplejson
                        jsonReturn = simplejson.dumps({
                            'context':
                            usercontext,
                            'results':
                            mark_safe(thereturn.content)
                        })
                        thereturn = HttpResponse(mark_safe(jsonReturn))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
示例#4
0
def search(request):
    try :
        thereturn = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin :
            if 'search' in request.POST :
                atusername = ''
                emailform = SpraycanSearchEmail(request.POST)
                usernameform = SpraycanSearchUsername(request.POST)
                if emailform.is_valid() :
                    resp = ttagPost('/validate/request-username-by-email',{'email':emailform.getSpraycan_Search()})
                    if resp['result'] == 'OK' and resp['find_by_email'] :
                        atusername = resp['user_name']
                elif usernameform.is_valid() :
                    resp = ttagRequestUserProfile(usernameform.getSpraycan_Search()[1:])
                    if resp['result'] == 'OK' :
                        atusername = resp['data']['user_name']
                if atusername != '' :
    #                from django.core.urlresolvers import reverse
    #                return render_to_response("javascript_redirect.html", {"redirect_url" : reverse('user-profile', kwargs={'user_name':atusername,'view_type':'','page':'','time':''}),'hidespraycan':'true'})
                    from webapp.views.user import userWallView
                    return userWallView(request, atusername)
                form = SpraycanSearch(request.POST)
                if form.is_valid() :
                    urlform = SpraycanSearchURL(request.POST)
                    if urlform.is_valid() :
                        #show spraycan for URL
                        thereturn = url(request, urlform.getSpraycan_Search())
                    else :
                        #show search results
                        import datetime
                        from webapp.views.user import getUserFollowers
                        location_type = 'search'
                        loggedin_user = data['_id']
                        filter = request.POST.get('filter', "All")
                        ttags = ttagPost('/find/url-keyword-hashtag',{'query':form.getSpraycan_Search(),'items_per_page':'100','page_number':'0'})
                        response = {'time': ttags['time'], 'data':{
                                            'founder': {},
                                            'favorite': False,
                                            'ttags':[] if filter not in ['All','Tags'] or ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else ttags['data']['ttags'],
                                            'users': [] if filter not in ['All','Users'] or ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else ttags['data']['users'],
                                            'hashtags': [] if filter not in ['All','HashTags'] or ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else ttags['data']['hashtags'],
                                            'location': [] if filter not in ['All','Locations'] or ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else ttags['data']['location'],
                                            'hubs': [] if filter not in ['All','Hubs'] or ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else ttags['data']['hubs'],
                                            'spams':[],
                                            'thumbups':[]}}
                        from webapp.models.hub import processRawHubs
                        response['data']['hubs'] = processRawHubs(response['data']['hubs'], request)
                        response['data']['followers'] = getUserFollowers(loggedin_user)
                        from webapp.views.user import getUserHubs
                        response['data']['joinedhubs'] = getUserHubs(data['user_name'])
                        response['data']['searchcounts'] = {
                                                            'ttags': 0 if ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else len(ttags['data']['ttags']),
                                                            'users': 0 if ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else len(ttags['data']['users']),
                                                            'hashtags': 0 if ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else len(ttags['data']['hashtags']),
                                                            'location': 0 if ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else len(ttags['data']['location']),
                                                            'hubs': 0 if ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else len(ttags['data']['hubs'])
                                                            }
                        servertime = datetime.datetime.fromtimestamp(int(ttags['time'])/1000)
                        if request.is_ajax() :
                            thetemplate = 'base_ajax.html'
                        thereturn = render_to_response("spraycan.html", locals(), context_instance=RequestContext(request))
                    if request.is_ajax() :
                        usercontext = mark_safe(render_to_response('partial_user_details.html',locals(),context_instance=RequestContext(request)).content)
                        import simplejson
                        jsonReturn = simplejson.dumps({'context':usercontext,'results':mark_safe(thereturn.content)})
                        thereturn = HttpResponse(mark_safe(jsonReturn));
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)