Ejemplo n.º 1
0
def userWallView(request, user_name, to_time=INFINITE_TIME):
    try :
        from webapp.views.spraycan import url
        hideMiniSpraycan = True
        loggedin, user, loggedin_user, follow, data = getUserVariables(request, user_name)
        if '_id' in data :
            partial = 'partial_spraycan_ttags.html' if request.is_ajax() and to_time != INFINITE_TIME else 'partial_user_profile_wall.html'
            spraycanURL = '/'.join(['','user',data['_id'],'wall'])
            request.wall_owner_id = data['_id']
            request.is_wallowner = ( loggedin_user == data['_id'] )
            userdetails = mark_safe(url(request=request, location=spraycanURL, location_type='wall', partial=partial, thetemplate='base_ajax.html', user_name=user_name, to_time=to_time).content)
        else :
            userdetails = mark_safe(render_to_response('partial_user_notfound.html',locals(),context_instance=RequestContext(request)).content)
        if request.is_ajax() :
            if userdetails[0:1] == '{' or to_time != INFINITE_TIME :
                thereturn = HttpResponse(userdetails)
            else :
                usercontext = mark_safe(render_to_response('partial_user_details.html',locals(),context_instance=RequestContext(request)).content)
                trueJsonReturn = simplejson.dumps({'context':usercontext,'results':userdetails})
                thereturn = render_to_response('ajax_ttag_create.html',{'jsonReturn':trueJsonReturn})
        else :
            thereturn = userProfileView(request=request, view_type='tags', user_name=user_name, userdetails=userdetails, hideMiniSpraycan=True)
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Ejemplo n.º 2
0
def userWallView(request, user_name, to_time=INFINITE_TIME):
    try:
        from webapp.views.spraycan import url
        hideMiniSpraycan = True
        loggedin, user, loggedin_user, follow, data = getUserVariables(
            request, user_name)
        if '_id' in data:
            partial = 'partial_spraycan_ttags.html' if request.is_ajax(
            ) and to_time != INFINITE_TIME else 'partial_user_profile_wall.html'
            spraycanURL = '/'.join(['', 'user', data['_id'], 'wall'])
            request.wall_owner_id = data['_id']
            request.is_wallowner = (loggedin_user == data['_id'])
            userdetails = mark_safe(
                url(request=request,
                    location=spraycanURL,
                    location_type='wall',
                    partial=partial,
                    thetemplate='base_ajax.html',
                    user_name=user_name,
                    to_time=to_time).content)
        else:
            userdetails = mark_safe(
                render_to_response(
                    'partial_user_notfound.html',
                    locals(),
                    context_instance=RequestContext(request)).content)
        if request.is_ajax():
            if userdetails[0:1] == '{' or to_time != INFINITE_TIME:
                thereturn = HttpResponse(userdetails)
            else:
                usercontext = mark_safe(
                    render_to_response(
                        'partial_user_details.html',
                        locals(),
                        context_instance=RequestContext(request)).content)
                trueJsonReturn = simplejson.dumps({
                    'context': usercontext,
                    'results': userdetails
                })
                thereturn = render_to_response('ajax_ttag_create.html',
                                               {'jsonReturn': trueJsonReturn})
        else:
            thereturn = userProfileView(request=request,
                                        view_type='tags',
                                        user_name=user_name,
                                        userdetails=userdetails,
                                        hideMiniSpraycan=True)
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Ejemplo n.º 3
0
def handle(request, notification_id):
    try :
        thereturn = loginscreen(request)
        authed, user = ttagServiceAuth(request)
        if authed :
            thereturn = custompopup(request, '<p>It looks like you\'ve already clicked on this notice, try <a href="'+reverse('notification-page',args=('1',))+'">reloading the notifications?</a></p>')
            notifications = ttagPost("/notification/get",{'access_token': request.COOKIES['access_token'], '_id': notification_id})
            if notifications['result'] == 'OK' and 'data' in notifications :
                notice = notifications['data']
                if notice['notification_type'] == 'FOLLOW_ME' :
                    thereturn = redirect('user-profile',notice['notification_data']['value']['followee_name'],'','','')
                elif notice['notification_type'] == 'POST_ON_HUB_WALL' :
                    thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+reverse('hub-wall',args=('id/',notice['notification_data']['value']['hub_id'])))
                elif notice['notification_type'] == 'POST_ON_USER_WALL' :
                    thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+reverse('user-wall', args=(user['user_name'],)))
                elif notice['notification_type'] == 'REPLY_TTAG' or notice['notification_type'] == 'TTAG_FOLLOW' :
                    if 'ttag_location' not in notice['notification_data']['value'] :
                        ttag = ttagPost('/ttag/get',{'access_token': request.COOKIES['access_token'], 'user_id': user['_id'], 'ttag_id': notice['notification_data']['value']['ttag_id'], 'search_on': 'ttag'})
                        notice['notification_data']['value']['ttag_location'] = ttag['data']['ttag']['location']
                    if 'ttag_location_type' in notice['notification_data']['value'] :
                        if notice['notification_data']['value']['ttag_location_type'] == 'wall' :
                            thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+notice['notification_data']['value']['ttag_location'].replace(hosts.ROOT_HOST,""))
                        elif notice['notification_data']['value']['ttag_location_type'] == 'HUB' :
                            thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+reverse('hub-wall', args=('id/',notice['notification_data']['value']['ttag_location'].split('#')[0])))
                        return thereturn
                    elif not request.is_ajax() :
                        import urllib
                        thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+'/spraycan/url/?location='+urllib.quote_plus(notice['notification_data']['value']['ttag_location']))
                    else :
                        from webapp.views import spraycan
                        request.GET = request.GET.copy()
                        request.GET.update({'location':notice['notification_data']['value']['ttag_location']})
                        thereturn = spraycan.url(request)
                elif notice['notification_type'] in ['JOIN_HUB','QUIT_HUB'] :
                    thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+reverse('hub-members',args=('id/',notice['notification_data']['value']['hub_id'])))
                else :
                    thereturn = HttpResponseRedirect(paths.HTTPS+request.get_host()+reverse('notification-page',args=('1',)))
                delete = ttagPost("/notification/delete",{'access_token':request.COOKIES['access_token'],'notifications':[notification_id]})
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Ejemplo n.º 4
0
def handle(request, notification_id):
    try:
        thereturn = loginscreen(request)
        authed, user = ttagServiceAuth(request)
        if authed:
            thereturn = custompopup(
                request,
                '<p>It looks like you\'ve already clicked on this notice, try <a href="'
                + reverse('notification-page', args=('1', )) +
                '">reloading the notifications?</a></p>')
            notifications = ttagPost(
                "/notification/get", {
                    'access_token': request.COOKIES['access_token'],
                    '_id': notification_id
                })
            if notifications['result'] == 'OK' and 'data' in notifications:
                notice = notifications['data']
                if notice['notification_type'] == 'FOLLOW_ME':
                    thereturn = redirect(
                        'user-profile',
                        notice['notification_data']['value']['followee_name'],
                        '', '', '')
                elif notice['notification_type'] == 'POST_ON_HUB_WALL':
                    thereturn = HttpResponseRedirect(
                        paths.HTTPS + request.get_host() +
                        reverse('hub-wall',
                                args=('id/', notice['notification_data']
                                      ['value']['hub_id'])))
                elif notice['notification_type'] == 'POST_ON_USER_WALL':
                    thereturn = HttpResponseRedirect(
                        paths.HTTPS + request.get_host() +
                        reverse('user-wall', args=(user['user_name'], )))
                elif notice['notification_type'] == 'REPLY_TTAG' or notice[
                        'notification_type'] == 'TTAG_FOLLOW':
                    if 'ttag_location' not in notice['notification_data'][
                            'value']:
                        ttag = ttagPost(
                            '/ttag/get', {
                                'access_token':
                                request.COOKIES['access_token'],
                                'user_id':
                                user['_id'],
                                'ttag_id':
                                notice['notification_data']['value']
                                ['ttag_id'],
                                'search_on':
                                'ttag'
                            })
                        notice['notification_data']['value'][
                            'ttag_location'] = ttag['data']['ttag']['location']
                    if 'ttag_location_type' in notice['notification_data'][
                            'value']:
                        if notice['notification_data']['value'][
                                'ttag_location_type'] == 'wall':
                            thereturn = HttpResponseRedirect(
                                paths.HTTPS + request.get_host() +
                                notice['notification_data']['value']
                                ['ttag_location'].replace(hosts.ROOT_HOST, ""))
                        elif notice['notification_data']['value'][
                                'ttag_location_type'] == 'HUB':
                            thereturn = HttpResponseRedirect(
                                paths.HTTPS + request.get_host() + reverse(
                                    'hub-wall',
                                    args=('id/',
                                          notice['notification_data']['value']
                                          ['ttag_location'].split('#')[0])))
                        return thereturn
                    elif not request.is_ajax():
                        import urllib
                        thereturn = HttpResponseRedirect(
                            paths.HTTPS + request.get_host() +
                            '/spraycan/url/?location=' +
                            urllib.quote_plus(notice['notification_data']
                                              ['value']['ttag_location']))
                    else:
                        from webapp.views import spraycan
                        request.GET = request.GET.copy()
                        request.GET.update({
                            'location':
                            notice['notification_data']['value']
                            ['ttag_location']
                        })
                        thereturn = spraycan.url(request)
                elif notice['notification_type'] in ['JOIN_HUB', 'QUIT_HUB']:
                    thereturn = HttpResponseRedirect(
                        paths.HTTPS + request.get_host() +
                        reverse('hub-members',
                                args=('id/', notice['notification_data']
                                      ['value']['hub_id'])))
                else:
                    thereturn = HttpResponseRedirect(
                        paths.HTTPS + request.get_host() +
                        reverse('notification-page', args=('1', )))
                delete = ttagPost(
                    "/notification/delete", {
                        'access_token': request.COOKIES['access_token'],
                        'notifications': [notification_id]
                    })
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Ejemplo n.º 5
0
def ttagCreate(request):
    try:
        thereturn = loginscreen(request)
        authed, user = ttagServiceAuth(request)
        if authed:

            if 'Comment' in request.POST:
                form = TtagPost(request.POST)
                print[
                    form.is_valid(),
                    len(str(request.POST['Comment'])),
                    len(request.POST.get('meta_thumbnail', ""))
                ]
                print form.errors
                if form.is_valid() and (
                        len(str(request.POST['Comment']))
                        or len(request.POST.get('meta_thumbnail', ""))):
                    import re, urllib
                    location_type = 'URL' if (
                        'location_type' not in request.POST or
                        request.POST['location_type'] not in ['wall', 'HUB']
                    ) else request.POST['location_type']
                    remotetitle = ""
                    if location_type == 'URL':
                        getTitle = ttagPost(
                            '/find/get-title', {
                                'location': form.getTtag_Location(),
                                'location_type': 'URL'
                            })
                        try:
                            remotetitle = getTitle['data']['location_data'][
                                'title']
                        except:
                            import urllib2
                            import socket
                            timeout = 3
                            socket.setdefaulttimeout(timeout)
                            try:
                                req = urllib2.Request(form.getTtag_Location())
                                remotecontent = urllib2.urlopen(req).read()
                            except:
                                remotecontent = mark_safe('<title></title>')
                            #remotetitle = re.search(r"<title>(.*?)</title>", remotecontent).group(1)
                            title_dict = get_title(remotecontent, request)
                            if title_dict['status'] == 'OK':
                                remotetitle = title_dict['msg']
                            elif title_dict['status'] == 'ERROR':
                                remotetitle = ""
                    elif location_type == 'wall':
                        if 'wall_owner_id' in request.POST:
                            wallOwner = ttagServiceByUserID(
                                form.clean_Ttag_WallOwnerID())
                            if wallOwner['result'] == "OK":
                                remotetitle = wallOwner['data']['user'][
                                    'full_name'] + "'s Wall"
                    hashtags = ''.join(
                        re.findall(r"\#\w+", request.POST['Comment']))
                    root_id = '0'
                    ttag_id = '0'
                    ttagdata = {
                        'access_token':
                        request.COOKIES['access_token'],
                        'user_id':
                        user['_id'],
                        'location':
                        form.getTtag_Location(),
                        'location_type':
                        location_type,
                        'ttag_content':
                        form.getTtag_Comment(),
                        'root_id':
                        root_id,
                        'parent_id':
                        ttag_id,
                        'title':
                        remotetitle.strip(),
                        'hashtags':
                        hashtags,
                        'meta_url':
                        urlquote_plus(form.getTtag_metaurl()),
                        'meta_thumbnail':
                        urlquote_plus(form.getTtag_metathumbnail()),
                        'meta_title':
                        urlquote_plus(form.getTtag_metatitle()),
                        'meta_desc':
                        urlquote_plus(form.getTtag_metadesc())
                    }
                    if 'wall_owner_id' in request.POST:
                        ttagdata[
                            'wall_owner_id'] = form.clean_Ttag_WallOwnerID()
                        request.is_wallowner = (
                            form.clean_Ttag_WallOwnerID() == user['_id'])
                    create = ttagPost("/ttag/create", ttagdata)
                    if create['result'] == 'OK':
                        if not request.is_ajax():
                            import urllib
                            thereturn = HttpResponseRedirect(
                                paths.HTTPS + request.get_host() +
                                '/spraycan/url/?location=' +
                                urlquote_plus(request.POST['location']))
                        elif 'position' in request.POST and request.POST[
                                'position'] == 'minispraycan':
                            thereturn = render_to_response(
                                'partial_user_minispraycansuccess.html',
                                locals())
                        else:
                            location = form.getTtag_Location()
                            from webapp.views import spraycan
                            ttags = spraycan.url(
                                request, location, request.POST['start_time'],
                                'partial_spraycan_ttags.html', False, None,
                                None, location_type)
                            response = {'time': request.session['start_time']}
                            feed = render_to_response(
                                'partial_spraycan_feed.html',
                                locals(),
                                context_instance=RequestContext(request))
                            objReturn = {
                                'feed': mark_safe(feed.content),
                                'ttags': mark_safe(ttags.content)
                            }
                            jsonReturn = simplejson.dumps(objReturn)
                            thereturn = render_to_response(
                                'ajax_ttag_create.html',
                                locals(),
                                context_instance=RequestContext(request))
                        if "wall_owner_id" in ttagdata and ttagdata[
                                "wall_owner_id"] != ttagdata["user_id"]:
                            # send notification email to the wall owner
                            from webapp.views.email import notifyOfWallPost
                            notifyOfWallPost(request,
                                             ttagdata["wall_owner_id"],
                                             ttagdata["user_id"])
                else:
                    if len(request.POST['Comment']):
                        thereturn = HttpResponse(str(form.errors))
                    else:
                        import urllib
                        thereturn = HttpResponseRedirect(
                            paths.HTTPS + request.get_host() +
                            '/spraycan/url/?location=' +
                            urlquote_plus(request.POST['location']))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Ejemplo n.º 6
0
def ttagCreate(request):
    try:
        thereturn = loginscreen(request)
        authed, user = ttagServiceAuth(request)
        if authed:

            if "Comment" in request.POST:
                form = TtagPost(request.POST)
                print [form.is_valid(), len(str(request.POST["Comment"])), len(request.POST.get("meta_thumbnail", ""))]
                print form.errors
                if form.is_valid() and (
                    len(str(request.POST["Comment"])) or len(request.POST.get("meta_thumbnail", ""))
                ):
                    import re, urllib

                    location_type = (
                        "URL"
                        if ("location_type" not in request.POST or request.POST["location_type"] not in ["wall", "HUB"])
                        else request.POST["location_type"]
                    )
                    remotetitle = ""
                    if location_type == "URL":
                        getTitle = ttagPost(
                            "/find/get-title", {"location": form.getTtag_Location(), "location_type": "URL"}
                        )
                        try:
                            remotetitle = getTitle["data"]["location_data"]["title"]
                        except:
                            import urllib2
                            import socket

                            timeout = 3
                            socket.setdefaulttimeout(timeout)
                            try:
                                req = urllib2.Request(form.getTtag_Location())
                                remotecontent = urllib2.urlopen(req).read()
                            except:
                                remotecontent = mark_safe("<title></title>")
                            # remotetitle = re.search(r"<title>(.*?)</title>", remotecontent).group(1)
                            title_dict = get_title(remotecontent, request)
                            if title_dict["status"] == "OK":
                                remotetitle = title_dict["msg"]
                            elif title_dict["status"] == "ERROR":
                                remotetitle = ""
                    elif location_type == "wall":
                        if "wall_owner_id" in request.POST:
                            wallOwner = ttagServiceByUserID(form.clean_Ttag_WallOwnerID())
                            if wallOwner["result"] == "OK":
                                remotetitle = wallOwner["data"]["user"]["full_name"] + "'s Wall"
                    hashtags = "".join(re.findall(r"\#\w+", request.POST["Comment"]))
                    root_id = "0"
                    ttag_id = "0"
                    ttagdata = {
                        "access_token": request.COOKIES["access_token"],
                        "user_id": user["_id"],
                        "location": form.getTtag_Location(),
                        "location_type": location_type,
                        "ttag_content": form.getTtag_Comment(),
                        "root_id": root_id,
                        "parent_id": ttag_id,
                        "title": remotetitle.strip(),
                        "hashtags": hashtags,
                        "meta_url": urlquote_plus(form.getTtag_metaurl()),
                        "meta_thumbnail": urlquote_plus(form.getTtag_metathumbnail()),
                        "meta_title": urlquote_plus(form.getTtag_metatitle()),
                        "meta_desc": urlquote_plus(form.getTtag_metadesc()),
                    }
                    if "wall_owner_id" in request.POST:
                        ttagdata["wall_owner_id"] = form.clean_Ttag_WallOwnerID()
                        request.is_wallowner = form.clean_Ttag_WallOwnerID() == user["_id"]
                    create = ttagPost("/ttag/create", ttagdata)
                    if create["result"] == "OK":
                        if not request.is_ajax():
                            import urllib

                            thereturn = HttpResponseRedirect(
                                paths.HTTPS
                                + request.get_host()
                                + "/spraycan/url/?location="
                                + urlquote_plus(request.POST["location"])
                            )
                        elif "position" in request.POST and request.POST["position"] == "minispraycan":
                            thereturn = render_to_response("partial_user_minispraycansuccess.html", locals())
                        else:
                            location = form.getTtag_Location()
                            from webapp.views import spraycan

                            ttags = spraycan.url(
                                request,
                                location,
                                request.POST["start_time"],
                                "partial_spraycan_ttags.html",
                                False,
                                None,
                                None,
                                location_type,
                            )
                            response = {"time": request.session["start_time"]}
                            feed = render_to_response(
                                "partial_spraycan_feed.html", locals(), context_instance=RequestContext(request)
                            )
                            objReturn = {"feed": mark_safe(feed.content), "ttags": mark_safe(ttags.content)}
                            jsonReturn = simplejson.dumps(objReturn)
                            thereturn = render_to_response(
                                "ajax_ttag_create.html", locals(), context_instance=RequestContext(request)
                            )
                        if "wall_owner_id" in ttagdata and ttagdata["wall_owner_id"] != ttagdata["user_id"]:
                            # send notification email to the wall owner
                            from webapp.views.email import notifyOfWallPost

                            notifyOfWallPost(request, ttagdata["wall_owner_id"], ttagdata["user_id"])
                else:
                    if len(request.POST["Comment"]):
                        thereturn = HttpResponse(str(form.errors))
                    else:
                        import urllib

                        thereturn = HttpResponseRedirect(
                            paths.HTTPS
                            + request.get_host()
                            + "/spraycan/url/?location="
                            + urlquote_plus(request.POST["location"])
                        )
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)