Beispiel #1
0
def userFavorite(request):
    try :
        authed, user = ttagServiceAuth(request)
        thereturn = loginscreen(request)
        if authed and 'favorite_id' in request.POST :
            thereturn = custompopup(request,'<p>Could not complete request</p>')
            form = Favorite(request.POST)
            if form.is_valid() :
                access_token = request.COOKIES['access_token']
                faves = ttagRequestLists(user['_id'])
                id = ''
                if faves['data']['favorites'] :
                    for item in faves['data']['favorites'] :
                        if 'favorite_id' in item and item['favorite_id'] == form.getFavorite_Id() and item['favorite_type'] == form.getFavorite_Type() :
                            id = item['_id']
                            break;
                postData = {'access_token': access_token, 'user_id': user['_id'], 'type': form.getFavorite_Type()}
                postURL = "/action/favorite"
                if len(id) == 0 :
                    postData['favorite_id'] = form.getFavorite_Id()
                    postData['values'] = {'title': form.getFavorite_Title(), 'category': form.getFavorite_Category(), 'description': form.getFavorite_Description()}
                else :
                    postData['id'] = id
                    postURL = "/action/unfavorite"
                response = ttagPost(postURL,postData)
                if request.is_ajax() :
                    thereturn = render_to_response("follow_ajax.html",{'request': request, 'response': response, 'id': id}, context_instance=RequestContext(request))
                else :
                    thereturn = HttpResponseRedirect(request.META['HTTP_REFERER'])
            else :
                thereturn = custompopup(request,'<p>'+str(form.errors)+'</p>')
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #2
0
def resetFormPost(request):
    try:
        showPopup = True
        if (request.method == 'POST') and ('reset_token' in request.session):
            form = PasswordResetForm(request.POST)  # bound form
            if form.is_valid():
                reset_token = request.session['reset_token']
                service_response = ttagServiceFPChange(reset_token,
                                                       form.getNew_Password())
                json_obj = simplejson.loads(service_response.read())
                if json_obj['result'] == 'OK':
                    ##inform user password was changed
                    return custompopup(
                        request,
                        "Your password has been changed. You can close this dialog and sign in with your new password."
                    )
                else:
                    ##inform user pass was not changed
                    return custompopup(
                        request,
                        'There was a problem, password was not changed.')
        else:
            form = PasswordResetForm()  # unbound form
        return render_to_response('resetform.html' if not request.is_ajax()
                                  else 'partial_resetform.html',
                                  locals(),
                                  context_instance=RequestContext(request))
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #3
0
def userDelete(request):
    try :
        response = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin :
            access_token = request.COOKIES['access_token']
            if request.method == 'GET' :
                pagetitle = 'TTAGIT - User Account Delete Request Confirmation'
                showPopup = True
                response = render_to_response('user_confirmdelete.html' if not request.is_ajax() else 'partial_user_confirmdelete.html', locals(), context_instance=RequestContext(request))
            else :
                json_obj = ttagServiceAccountDelete(access_token)
                if json_obj['result'] == 'OK' :
                    response = custompopup(request,'<p>Your Acccount was deleted</p>', reverse('index-page'))
                    request.COOKIES['access_token'] = ''
                else :
                    response = custompopup(request,'<p>Your Account was not deleted</p>')
            return response
#        only during development!!!
#        elif 'user_name' in request.GET :
#            ttagPost('/delete-user',{'user_name':request.GET['user_name']})
#            response = HttpResponse('Your Account was deleted')
#        elif 'email' in request.GET :
#            ttagPost('/delete-user',{'email':request.GET['email']})
#            response = HttpResponse('Your Account was deleted')
        return response
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #4
0
def userFavorite(request):
    try:
        authed, user = ttagServiceAuth(request)
        thereturn = loginscreen(request)
        if authed and 'favorite_id' in request.POST:
            thereturn = custompopup(request,
                                    '<p>Could not complete request</p>')
            form = Favorite(request.POST)
            if form.is_valid():
                access_token = request.COOKIES['access_token']
                faves = ttagRequestLists(user['_id'])
                id = ''
                if faves['data']['favorites']:
                    for item in faves['data']['favorites']:
                        if 'favorite_id' in item and item[
                                'favorite_id'] == form.getFavorite_Id(
                                ) and item[
                                    'favorite_type'] == form.getFavorite_Type(
                                    ):
                            id = item['_id']
                            break
                postData = {
                    'access_token': access_token,
                    'user_id': user['_id'],
                    'type': form.getFavorite_Type()
                }
                postURL = "/action/favorite"
                if len(id) == 0:
                    postData['favorite_id'] = form.getFavorite_Id()
                    postData['values'] = {
                        'title': form.getFavorite_Title(),
                        'category': form.getFavorite_Category(),
                        'description': form.getFavorite_Description()
                    }
                else:
                    postData['id'] = id
                    postURL = "/action/unfavorite"
                response = ttagPost(postURL, postData)
                if request.is_ajax():
                    thereturn = render_to_response(
                        "follow_ajax.html", {
                            'request': request,
                            'response': response,
                            'id': id
                        },
                        context_instance=RequestContext(request))
                else:
                    thereturn = HttpResponseRedirect(
                        request.META['HTTP_REFERER'])
            else:
                thereturn = custompopup(request,
                                        '<p>' + str(form.errors) + '</p>')
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #5
0
def listCreated(request, user_name):
    try :
        thereturn = custompopup(request,'<p>Sorry, we were unable to display this page.</p>')
        loggedin, user, loggedin_user, follow, data = getUserVariables(request, user_name)
        logged_in_user = get_logged_in_user(request)
        request_user = get_user_by_name(request, user_name)
        if request_user != False :
            hubs = get_hubs_by_user(request, request_user)
            if len(hubs) == 0 :
                if loggedin and user_name == user['user_name'] :
                    thereturn = render_to_response('partial_user_nocreatedhubsmyself.html',locals(),context_instance=RequestContext(request))
                else :
                    thereturn = render_to_response('partial_user_nocreatedhubs.html',locals(),context_instance=RequestContext(request))
            else :
                response = {'data': {'hubs': hubs }}
                if loggedin :
                    from webapp.views.user import getUserHubs
                    response['data']['joinedhubs'] = getUserHubs(user['user_name'])
                    if user_name == user['user_name'] :
                        response['data']['createdhubs'] = [hub.hub_id for hub in response['data']['hubs']]
                thereturn = render_to_response('partial_user_createdhubs.html',locals(),context_instance=RequestContext(request))
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #6
0
def actionJoin(request, data_type, data_value, quit=False):
    try :
        thereturn = loginscreen(request)
        user = get_logged_in_user(request)
        loggedin = user and user.is_current_user
        thereturn = loginscreen(request)
        if loggedin:
            user_id = user["_id"]
            hub_id = data_value
            hub = get_hub_by_id(request, hub_id, user)
            access_token= request.COOKIES['access_token']
            if  data_type == "id":
                if quit:
                    response = ttagQuitJoinedHub(user_id, access_token, hub_id)
                else:
                    response = ttagJoinHub(user_id, access_token, hub_id)
            else:
                return custompopup(request,'<p>Hub not found</p>')
            if response["result"] == "OK":
                if not request.is_ajax() :
                    return HttpResponseRedirect(request.META['HTTP_REFERER'])
                else :
                    hub.joined = True if not quit else False
                    return render_to_response('partial_hub_join.html',locals(),context_instance=RequestContext(request))
            else:
                return HttpResponse(response["msg"])
        else:
            return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #7
0
def ttagShow(request, ttag_id, useHTML, appendCode=""):
    try:
        loggedin, data = ttagServiceAuth(request)
        thereturn = custompopup(request, '<p>Could not complete request</p>')
        response = ttagPost("/find/ttag", {'ttag_id': ttag_id})
        if 'result' in response and response['result'] == 'OK':
            if loggedin:
                loggedin_user = data['_id']
                from webapp.views.user import getUserFollowers
                response['data']['followers'] = getUserFollowers(loggedin_user)
            servertime = datetime.datetime.fromtimestamp(
                int(response['time']) / 1000)
            context = {
                'pagetitle': 'ttagit - Flagged Ttag',
                'request': request,
                'ttag': response['data']['ttag'],
                'servertime': servertime,
                'appendCode': appendCode
            }
            thereturn = render_to_response(
                'ttag_show.html',
                context,
                context_instance=RequestContext(request))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #8
0
def ttagLink(request, ttag_id):
    try:
        response = ttagPost("/find/ttag", {"ttag_id": ttag_id})
        theReturn = custompopup(request, "<p>Sorry, we failed to find that ttag!</p>")
        if "result" in response and response["result"] == "OK":
            ttag = response["data"]["ttag"]
            if ttag["location_type"] == "wall":
                theReturn = HttpResponseRedirect(ttag["location"])
            elif ttag["location_type"] == "URL":
                theReturn = HttpResponseRedirect(
                    paths.HTTPS
                    + request.get_host()
                    + reverse("spraycan-url")
                    + "?location="
                    + urlquote_plus(ttag["location"])
                )
            elif ttag["location_type"] == "HUB":
                hubid = ttag["location"].split("#")[0]
                theReturn = HttpResponseRedirect(
                    paths.HTTPS + request.get_host() + reverse("hub-wall", args=("id/", hubid))
                )
        return theReturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #9
0
def actionJoin(request, data_type, data_value, quit=False):
    try:
        thereturn = loginscreen(request)
        user = get_logged_in_user(request)
        loggedin = user and user.is_current_user
        thereturn = loginscreen(request)
        if loggedin:
            user_id = user["_id"]
            hub_id = data_value
            hub = get_hub_by_id(request, hub_id, user)
            access_token = request.COOKIES['access_token']
            if data_type == "id":
                if quit:
                    response = ttagQuitJoinedHub(user_id, access_token, hub_id)
                else:
                    response = ttagJoinHub(user_id, access_token, hub_id)
            else:
                return custompopup(request, '<p>Hub not found</p>')
            if response["result"] == "OK":
                if not request.is_ajax():
                    return HttpResponseRedirect(request.META['HTTP_REFERER'])
                else:
                    hub.joined = True if not quit else False
                    return render_to_response(
                        'partial_hub_join.html',
                        locals(),
                        context_instance=RequestContext(request))
            else:
                return HttpResponse(response["msg"])
        else:
            return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #10
0
def userFollow(request, user_name):
    try:
        authed, user = ttagServiceAuth(request)
        thereturn = loginscreen(request)
        if authed:
            thereturn = custompopup(request,
                                    '<p>Could not complete request</p>')
            access_token = request.COOKIES['access_token']
            location = request.META[
                'HTTP_REFERER'] if 'location' not in request.POST else request.POST[
                    'location']
            followers = ttagRequestFollowers(user['_id'])
            found = False
            follower_id = 0
            if 'data' in followers and 'users' in followers[
                    'data'] and followers['data']['users'] != None:
                for follower in followers['data']['users']:
                    if follower['user_name'] == str(user_name):
                        found = True
                        follower_id = follower['user_id']
                        break
            if found:
                response = ttagPost(
                    "/follow/delete", {
                        'access_token': access_token,
                        'user_id': user['_id'],
                        'follower_id': follower_id,
                        'followee_id': user['_id']
                    })
            else:
                f_user = ttagRequestUserProfile(user_name)
                follower_id = f_user['data']['_id']
                response = ttagPost(
                    "/follow/create", {
                        'access_token': access_token,
                        'user_id': user['_id'],
                        'follower_id': follower_id,
                        'followee_id': user['_id']
                    })
                if response["result"] == "OK":
                    from webapp.views.email import notifyOfUserFollowing
                    # send reply notification
                    notifyOfUserFollowing(request, follower_id, user["_id"])
            response['found'] = found
            # localprint(request, response)
            if request.is_ajax():
                thereturn = render_to_response(
                    'partial_user_follow.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                thereturn = HttpResponseRedirect(location)
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #11
0
def resetFormPost(request):
    try :
        showPopup = True
        if (request.method == 'POST') and ('reset_token' in request.session):
            form = PasswordResetForm(request.POST)         # bound form
            if form.is_valid(): 
                reset_token = request.session['reset_token']
                service_response =  ttagServiceFPChange(reset_token,form.getNew_Password())
                json_obj = simplejson.loads(service_response.read())
                if json_obj['result'] == 'OK':
                    ##inform user password was changed
                    return custompopup(request, "Your password has been changed. You can close this dialog and sign in with your new password.")
                else:
                    ##inform user pass was not changed
                    return custompopup(request, 'There was a problem, password was not changed.')
        else :
            form = PasswordResetForm()                  # unbound form
        return render_to_response('resetform.html' if not request.is_ajax() else 'partial_resetform.html', locals(), context_instance=RequestContext(request))
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #12
0
def userDelete(request):
    try:
        response = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin:
            access_token = request.COOKIES['access_token']
            if request.method == 'GET':
                pagetitle = 'TTAGIT - User Account Delete Request Confirmation'
                showPopup = True
                response = render_to_response(
                    'user_confirmdelete.html' if not request.is_ajax() else
                    'partial_user_confirmdelete.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                json_obj = ttagServiceAccountDelete(access_token)
                if json_obj['result'] == 'OK':
                    response = custompopup(request,
                                           '<p>Your Acccount was deleted</p>',
                                           reverse('index-page'))
                    request.COOKIES['access_token'] = ''
                else:
                    response = custompopup(
                        request, '<p>Your Account was not deleted</p>')
            return response


#        only during development!!!
#        elif 'user_name' in request.GET :
#            ttagPost('/delete-user',{'user_name':request.GET['user_name']})
#            response = HttpResponse('Your Account was deleted')
#        elif 'email' in request.GET :
#            ttagPost('/delete-user',{'email':request.GET['email']})
#            response = HttpResponse('Your Account was deleted')
        return response
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #13
0
def ttagShowOriginal(request, ttag_id, parent_id):
    try:
        thereturn = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin:
            thereturn = custompopup(
                request,
                '<p>There was a problem retrieving the original Tag</p>')
            response = ttagPost(
                '/ttag/get', {
                    'access_token': request.COOKIES['access_token'],
                    'user_id': data['_id'],
                    'ttag_id': parent_id,
                    'search_on': 'ttag'
                })
            loggedin_user = data['_id']
            from webapp.views.user import getUserFollowers
            if 'result' in response and response['result'] == 'OK':
                response['data']['followers'] = getUserFollowers(loggedin_user)
                servertime = datetime.datetime.fromtimestamp(
                    int(response['time']) / 1000)
                ttag = response['data']['ttag']
                child = ttagPost(
                    '/ttag/get', {
                        'access_token': request.COOKIES['access_token'],
                        'user_id': data['_id'],
                        'ttag_id': ttag_id,
                        'search_on': 'ttag'
                    })
                if 'result' in child and child[
                        'result'] == 'OK' and 'data' in child and child[
                            'data'] != None:
                    reply = child['data']['ttag']
                    child['data']['followers'] = response['data']['followers']
                    thereturn = render_to_response(
                        'ttag_showoriginal.html',
                        locals(),
                        context_instance=RequestContext(request))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #14
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)
Beispiel #15
0
def ttagShowOriginal(request, ttag_id, parent_id):
    try:
        thereturn = loginscreen(request)
        loggedin, data = ttagServiceAuth(request)
        if loggedin:
            thereturn = custompopup(request, "<p>There was a problem retrieving the original Tag</p>")
            response = ttagPost(
                "/ttag/get",
                {
                    "access_token": request.COOKIES["access_token"],
                    "user_id": data["_id"],
                    "ttag_id": parent_id,
                    "search_on": "ttag",
                },
            )
            loggedin_user = data["_id"]
            from webapp.views.user import getUserFollowers

            if "result" in response and response["result"] == "OK":
                response["data"]["followers"] = getUserFollowers(loggedin_user)
                servertime = datetime.datetime.fromtimestamp(int(response["time"]) / 1000)
                ttag = response["data"]["ttag"]
                child = ttagPost(
                    "/ttag/get",
                    {
                        "access_token": request.COOKIES["access_token"],
                        "user_id": data["_id"],
                        "ttag_id": ttag_id,
                        "search_on": "ttag",
                    },
                )
                if "result" in child and child["result"] == "OK" and "data" in child and child["data"] != None:
                    reply = child["data"]["ttag"]
                    child["data"]["followers"] = response["data"]["followers"]
                    thereturn = render_to_response(
                        "ttag_showoriginal.html", locals(), context_instance=RequestContext(request)
                    )
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #16
0
def listCreated(request, user_name):
    try:
        thereturn = custompopup(
            request, '<p>Sorry, we were unable to display this page.</p>')
        loggedin, user, loggedin_user, follow, data = getUserVariables(
            request, user_name)
        logged_in_user = get_logged_in_user(request)
        request_user = get_user_by_name(request, user_name)
        if request_user != False:
            hubs = get_hubs_by_user(request, request_user)
            if len(hubs) == 0:
                if loggedin and user_name == user['user_name']:
                    thereturn = render_to_response(
                        'partial_user_nocreatedhubsmyself.html',
                        locals(),
                        context_instance=RequestContext(request))
                else:
                    thereturn = render_to_response(
                        'partial_user_nocreatedhubs.html',
                        locals(),
                        context_instance=RequestContext(request))
            else:
                response = {'data': {'hubs': hubs}}
                if loggedin:
                    from webapp.views.user import getUserHubs
                    response['data']['joinedhubs'] = getUserHubs(
                        user['user_name'])
                    if user_name == user['user_name']:
                        response['data']['createdhubs'] = [
                            hub.hub_id for hub in response['data']['hubs']
                        ]
                thereturn = render_to_response(
                    'partial_user_createdhubs.html',
                    locals(),
                    context_instance=RequestContext(request))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #17
0
def ttagThumbup(request, ttag_id):
    try:
        authed, user = ttagServiceAuth(request)
        thereturn = custompopup(request, "<p>Could not complete request</p>")
        if authed:
            ttag = ttagPost(
                '/ttag/get', {
                    'access_token': request.COOKIES['access_token'],
                    'user_id': user['_id'],
                    'ttag_id': ttag_id,
                    'search_on': 'ttag'
                })
            if ttag['result'] == 'OK':
                location = request.META[
                    'HTTP_REFERER'] if 'location' not in request.POST else request.POST[
                        'location']
                ttaglocation = ttag['data']['ttag']['location']
                response = ttagPost(
                    "/action/thumbup", {
                        'access_token': request.COOKIES['access_token'],
                        'user_id': user['_id'],
                        'location': ttaglocation,
                        'ttag_id': ttag_id
                    })
                if request.is_ajax():
                    ttag = ttag['data']['ttag']
                    ttag['metadatas']['thumbup_count'] = ttag['metadatas'][
                        'thumbup_count'] + 1
                    thereturn = render_to_response(
                        'partial_ttag_thumbup.html',
                        locals(),
                        context_instance=RequestContext(request))
                else:
                    thereturn = HttpResponseRedirect(location)
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #18
0
def ttagThumbup(request, ttag_id):
    try:
        authed, user = ttagServiceAuth(request)
        thereturn = custompopup(request, "<p>Could not complete request</p>")
        if authed:
            ttag = ttagPost(
                "/ttag/get",
                {
                    "access_token": request.COOKIES["access_token"],
                    "user_id": user["_id"],
                    "ttag_id": ttag_id,
                    "search_on": "ttag",
                },
            )
            if ttag["result"] == "OK":
                location = request.META["HTTP_REFERER"] if "location" not in request.POST else request.POST["location"]
                ttaglocation = ttag["data"]["ttag"]["location"]
                response = ttagPost(
                    "/action/thumbup",
                    {
                        "access_token": request.COOKIES["access_token"],
                        "user_id": user["_id"],
                        "location": ttaglocation,
                        "ttag_id": ttag_id,
                    },
                )
                if request.is_ajax():
                    ttag = ttag["data"]["ttag"]
                    ttag["metadatas"]["thumbup_count"] = ttag["metadatas"]["thumbup_count"] + 1
                    thereturn = render_to_response(
                        "partial_ttag_thumbup.html", locals(), context_instance=RequestContext(request)
                    )
                else:
                    thereturn = HttpResponseRedirect(location)
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #19
0
def ttagLink(request, ttag_id):
    try:
        response = ttagPost("/find/ttag", {'ttag_id': ttag_id})
        theReturn = custompopup(request,
                                "<p>Sorry, we failed to find that ttag!</p>")
        if 'result' in response and response['result'] == 'OK':
            ttag = response['data']['ttag']
            if ttag["location_type"] == "wall":
                theReturn = HttpResponseRedirect(ttag["location"])
            elif ttag["location_type"] == "URL":
                theReturn = HttpResponseRedirect(
                    paths.HTTPS + request.get_host() +
                    reverse('spraycan-url') + "?location=" +
                    urlquote_plus(ttag["location"]))
            elif ttag["location_type"] == "HUB":
                hubid = ttag["location"].split("#")[0]
                theReturn = HttpResponseRedirect(
                    paths.HTTPS + request.get_host() +
                    reverse('hub-wall', args=("id/", hubid)))
        return theReturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #20
0
def userFollow(request, user_name):
    try :
        authed, user = ttagServiceAuth(request)
        thereturn = loginscreen(request)
        if authed :
            thereturn = custompopup(request,'<p>Could not complete request</p>')
            access_token = request.COOKIES['access_token']
            location = request.META['HTTP_REFERER'] if 'location' not in request.POST else request.POST['location']
            followers = ttagRequestFollowers(user['_id'])
            found = False
            follower_id = 0
            if 'data' in followers and 'users' in followers['data'] and followers['data']['users'] != None :
                for follower in followers['data']['users'] :
                    if follower['user_name'] == str(user_name) :
                        found = True
                        follower_id = follower['user_id']
                        break
            if found :
                response = ttagPost("/follow/delete", {'access_token': access_token, 'user_id': user['_id'], 'follower_id': follower_id, 'followee_id': user['_id']})
            else :
                f_user = ttagRequestUserProfile(user_name)
                follower_id = f_user['data']['_id']
                response = ttagPost("/follow/create", {'access_token': access_token, 'user_id': user['_id'], 'follower_id': follower_id, 'followee_id': user['_id']})
                if response["result"] == "OK":
                    from webapp.views.email import notifyOfUserFollowing
                    # send reply notification
                    notifyOfUserFollowing(request, follower_id, user["_id"])
            response['found'] = found
            # localprint(request, response)
            if request.is_ajax() :
                thereturn = render_to_response('partial_user_follow.html',locals(),context_instance=RequestContext(request))
            else :
                thereturn = HttpResponseRedirect(location)
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Beispiel #21
0
def ttagShow(request, ttag_id, useHTML, appendCode=""):
    try:
        loggedin, data = ttagServiceAuth(request)
        thereturn = custompopup(request, "<p>Could not complete request</p>")
        response = ttagPost("/find/ttag", {"ttag_id": ttag_id})
        if "result" in response and response["result"] == "OK":
            if loggedin:
                loggedin_user = data["_id"]
                from webapp.views.user import getUserFollowers

                response["data"]["followers"] = getUserFollowers(loggedin_user)
            servertime = datetime.datetime.fromtimestamp(int(response["time"]) / 1000)
            context = {
                "pagetitle": "ttagit - Flagged Ttag",
                "request": request,
                "ttag": response["data"]["ttag"],
                "servertime": servertime,
                "appendCode": appendCode,
            }
            thereturn = render_to_response("ttag_show.html", context, context_instance=RequestContext(request))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Beispiel #22
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)