示例#1
0
文件: hubold.py 项目: ttagit/website
def MainHub(request):
    loggedin, data = ttagServiceAuth(request)
    #"owner_id":"5064dd00559ae9da2b9e38b8","location_type":"HUB","user_id":"5064dd00559ae9da2b9e38b8","access_token":"ff891baeb4106593b40a5b9110c90f44"
    if loggedin:
        user_id = data["_id"]
        user_name = data["user_name"]
        response_hubs = ttagGetHubsByUserName(data['user_name'])
        #print response_hubs
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        block_title = "My Hubs"
        if response_hubs["result"] == "OK":
            hubs = response_hubs["data"]["hubs"]
            logined_and_different = False
            joined_hubs = ttagGetJoinedHubsByUserName(user_name)["data"]["hubs"]
            for hub in response_hubs["data"]["hubs"]:
                if hub["creater_id"] == user_id:
                    hub["owner"] = True
                else:
                    hub["owner"] = False
                hububub = ttagGetHubByHubId(hub["hub_id"])
                #print hububub
                hub["joined"] = False
                for joined_hub in joined_hubs:
                    #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                    if joined_hub["_id"] == hub["_id"]:
                        hub["joined"] = True
                        break
            
            return render_to_response('hub/user_hubs.html', locals(), context_instance=RequestContext(request))
        else:
            return HttpResponse(response_hubs["msg"])
    else:
        return HttpResponseRedirect('/')
示例#2
0
文件: hubold.py 项目: ttagit/website
def getHubMembers(request,data_type,data_value):
    loggedin, data = ttagServiceAuth(request)
    #"owner_id":"5064dd00559ae9da2b9e38b8","location_type":"HUB","user_id":"5064dd00559ae9da2b9e38b8","access_token":"ff891baeb4106593b40a5b9110c90f44"
    if loggedin:
        user_id = data["_id"]
        user_name = data["user_name"]
        response_hubs = ttagGetHubsByOwnerId(data['_id'], request.COOKIES['access_token'])
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        
        key_name = "hub_id"
        if data_type == "id":
            from_time = 0 if 'from_time' not in request.POST else request.POST['from_time']
            to_time = 4116171410000 if 'to_time' not in request.POST else request.POST['to_time']
            items_per_page = 10000 if 'items_per_page' not in request.POST else request.POST['items_per_page']
            page_number = 0 if 'page_number' not in request.POST else request.POST['page_number']
            response = ttagGetHubUsers(data_value, from_time, to_time, items_per_page, page_number)
        
        if response["result"] == "OK":
            hub_users= response["data"]["hub_users"]
            #context = {'hub_users': response["data"]["hub_users"],key_name:data_value}
            thereturn = render_to_response('hub/hub_members.html', locals(), context_instance=RequestContext(request))
            return thereturn
        else:
            return HttpResponse(response["msg"])
    else:
        return HttpResponseRedirect('/')
示例#3
0
文件: hubold.py 项目: ttagit/website
def getHubTags(request, data_type,data_value):
    loggedin, data = ttagServiceAuth(request)
    response_count = ttagRequestCount(data['_id'])
    counts = response_count['counts']
    
    if data_type == "id":
        
        hub_response = ttagGetHubByHubId(data_value)
        
        if hub_response["result"] == "OK":
            hub = hub_response["data"]["hub"]
            from_time = 0 if 'from_time' not in request.POST else request.POST['from_time']
            to_time = 4116171410000 if 'to_time' not in request.POST else request.POST['to_time']
            items_per_page = 10000 if 'items_per_page' not in request.POST else request.POST['items_per_page']
            page_number = 0 if 'page_number' not in request.POST else request.POST['page_number']
            response = ttagGetHubTtags(data_value,from_time,to_time,items_per_page,page_number)
        else:
            return HttpResponse(hub_response["msg"])
    else:
        return HttpResponse("Invalid data type")
    
    if response["result"] == "OK":
        ttags =  response["data"]["hub_ttags"]
        spraycan = True
        loggedin_user = data['_id']
        servertime = datetime.datetime.fromtimestamp(int(response['time'])/1000)
        
        thereturn = render_to_response('hub/hub_ttags.html', locals(), context_instance=RequestContext(request))
        return thereturn   
    else:
        return HttpResponse(response["msg"])
示例#4
0
文件: hubold.py 项目: ttagit/website
def findHubs(request):
    authed, data = ttagServiceAuth(request)
    response = ttagRequestCount(data['_id'])
    counts = response['counts']
    if authed: 
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        if 'hub_name' in request.POST and 'hub_desc' in request.POST:
            hub_name = request.POST["hub_name"]
            hub_desc = request.POST["hub_desc"]
            response = ttagCreateHub(user_id, access_token, hub_name, hub_desc,"true", "0")
            if response["result"] == "OK":
                #context = {"status":"created","hub":response["data"]["hub"]}
                status = "created"
                hub = response["data"]["hub"]
                return render_to_response('hub/hub_create.html', locals(), context_instance=RequestContext(request))
            else:
                status = "error"
                error_msg = response["msg"]                
                #context = {"status":"error","hub_name":hub_name,"hub_desc":hub_desc,"error_msg":response["msg"]}
                return render_to_response('hub/hub_create.html', locals(), context_instance=RequestContext(request))
        else:
            #context = {"status":"new"}
            status = "new"
            return render_to_response('hub/hub_create.html', locals(), context_instance=RequestContext(request))
    else:
        
        return HttpResponse("Invalid request")
示例#5
0
文件: home.py 项目: ttagit/website
def settingsView(request, popup=False):
    """Show the user settings dashboard page"""
    try :
        thereturn = loginscreen(request)
        from webapp.views.user import getUserVariables
        loggedin, user, loggedin_user, follow, data = getUserVariables(request, '')
        if loggedin: 
            if request.method != "POST":
                formdata = {'gender':'','google_map_address':'','pro_description':''}
                for key in data :
                    formdata[key] = data[key]
            else :
                formdata = request.POST
        
            form = SettingsForm(formdata)
            response = ttagRequestCount(data['_id'])
            if popup != False :
                showPopup = True
                popupPartial = "partial_"+popup+"_popup.html"
            pagetitle = "ttagit - User Settings Page"
            location = "Settings"
            if request.is_ajax() :
                from website.localsettings.paths import S3TATIC_URL
                userpanel = render_to_response("partial_home_settings.html",locals(),context_instance=RequestContext(request))
                userdetails = render_to_response("partial_user_details.html",locals(),context_instance=RequestContext(request))
                head = render_to_response("djview_head_resources.html",{'headScripts':mark_safe('<script type="text/javascript" src="'+S3TATIC_URL+'scripts/passwordstrength.js"></script><script type="text/javascript" src="'+S3TATIC_URL+'scripts/settings.js"></script>')},context_instance=RequestContext(request))
                jsonReturn = simplejson.dumps({"context":mark_safe(userdetails.content),"results":mark_safe(userpanel.content),'head':mark_safe(head.content)})
                thereturn = HttpResponse(mark_safe(jsonReturn))
            else :
                thereturn = render_to_response('home_settings.html', locals(), context_instance=RequestContext(request))
        return thereturn
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
示例#6
0
文件: user.py 项目: ttagit/website
def userProfileView(request, user_name='', view_type='', page='', time='', userdetails='', pagetitle='ttagit - User Profile Page', pagetemplate='user_profile.html', partial=None, hideMiniSpraycan=False):
    try :
        authed, data = ttagServiceAuth(request)
        follow = -1
        loggedin_user = '' if not authed else data['_id']
        if user_name != '' :
            if request.COOKIES.has_key('access_token'):
                response = ttagRequestUserProfileWithAccessToken(user_name,request.COOKIES['access_token'])
            else:
                response = ttagRequestUserProfile(user_name)
            if 'data' in response and response['data']['is_activated'] and not response['data']['is_deleted'] :
                data = response['data']
                if 'follow' in response :
                    follow = response['follow']
                if loggedin_user == data['_id'] :
                    follow = -1
            else :
                return HttpResponseRedirect(reverse('home-page'))
        elif data != None and 'user_name' in data :
            user_name = data['user_name']
        if not data or data == None :
            return HttpResponseRedirect(reverse('home-page'))
        response = ttagRequestCount(data['_id'])
        if 'counts' in response :
            counts = response['counts']
            servertime = response['time']
            counts['tags'] = counts['ttags']
            counts['following'] = counts['followees']
        else :
            counts = {'tags':0,'replies':0,'followers':0,'following':0}
            import time
            servertime = int(time.mktime(datetime.datetime.now().timetuple())*1000)
        if view_type not in ['tags','replies','following','followers','finds','favorites'] :
            view_type = 'tags'
        if partial is not None :
            return render_to_response(partial,locals(),context_instance=RequestContext(request))
        if not page or page == '' :
            page = 1
        page = int(page)
        if not time or time == '' :
            time = 0
        time = int(time)
        more = True if counts[view_type] > PROFILE_ITEM_ROWS * page and time == 0 else False
        if userdetails == '' :
            userdetails = getUserDetails(request, data, user_name, data['_id'], loggedin_user, view_type, page, time, more)
        if request.is_ajax() :
            return HttpResponse(userdetails)
        context = {'view_type': view_type, 'data': data, 'counts': counts, 'pagetitle': pagetitle, 'request': request, 'loggedin': False, 'details': userdetails, 'page': page, 'servertime': servertime,'follow':follow, 'showfollow': True, 'hideMiniSpraycan': hideMiniSpraycan}
        if authed :
            context['loggedin'] = True
        return render_to_response(pagetemplate, context, context_instance=RequestContext(request))
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
示例#7
0
文件: hubold.py 项目: ttagit/website
def findHubsGeneral(request):

    authed, data = ttagServiceAuth(request)
    joined_hubs = []
    block_title = ""
    if authed:
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        user_name = data["user_name"]

        if request.method == 'POST' and request.POST[
                'find_method'] == 'general':
            response = ttagGetHubsByName(request.POST['query'])
            if response["result"] == 'OK':
                hubs = response['data']['hubs']

                logined_and_different = False
                joined_hubs = ttagGetJoinedHubsByUserName(
                    user_name)["data"]["hubs"]
                for hub in response["data"]["hubs"]:

                    if hub["creater_id"] == user_id:
                        hub["owner"] = True
                    else:
                        hub["owner"] = False

                    hub["joined"] = False
                    for joined_hub in joined_hubs:
                        #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                        if joined_hub["_id"] == hub["_id"]:
                            hub["joined"] = True
                            break

                thereturn = render_to_response(
                    'hub/find_hubs_general.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                return HttpResponse(response["msg"])
        else:
            #context = {'hubs': response["data"]["hubs"],"user_id":user_id,"joined_hubs":joined_hubs,"logined_and_different":logined_and_different}
            thereturn = render_to_response(
                'hub/find_hubs_general.html',
                locals(),
                context_instance=RequestContext(request))
        return thereturn
    else:
        return HttpResponseRedirect('/')
示例#8
0
文件: hubold.py 项目: ttagit/website
def JoinedHub(request, data_type, data_value):
    loggedin, data = ttagServiceAuth(request)
    response_count = ttagRequestCount(data['_id'])
    counts = response_count['counts']
    
    if loggedin:
        if data_type == 'id':
            response_joined = ttagGetJoinedHubsByHubUserId(data_value)
        elif data_type == 'name':
            response_joined = ttagGetJoinedHubsByUserName(data_value)
            
        if response_joined["result"] == "OK":
            hubs = response_joined["data"]["hubs"]
            return render_to_response('hub/user_hubs.html', locals(), context_instance=RequestContext(request))
        else:
            return HttpResponse(response_joined.msg)
    else:
        return HttpResponseRedirect('/')
示例#9
0
文件: hubold.py 项目: ttagit/website
def findHubsGeneral(request):

    authed, data = ttagServiceAuth(request)
    joined_hubs = []
    block_title = ""
    if authed:
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        user_name = data["user_name"]
           
        if request.method == 'POST' and request.POST['find_method'] == 'general':
            response = ttagGetHubsByName(request.POST['query'])
            if response["result"] == 'OK':
                hubs = response['data']['hubs']
                
                logined_and_different = False
                joined_hubs = ttagGetJoinedHubsByUserName(user_name)["data"]["hubs"]
                for hub in response["data"]["hubs"]:
                    
                    if hub["creater_id"] == user_id:
                        hub["owner"] = True
                    else:
                        hub["owner"] = False
                    
                    hub["joined"] = False
                    for joined_hub in joined_hubs:
                        #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                        if joined_hub["_id"] == hub["_id"]:
                            hub["joined"] = True
                            break
                
                thereturn = render_to_response('hub/find_hubs_general.html', locals(), context_instance=RequestContext(request))
            else:
                return  HttpResponse(response["msg"])
        else:
            #context = {'hubs': response["data"]["hubs"],"user_id":user_id,"joined_hubs":joined_hubs,"logined_and_different":logined_and_different}
            thereturn = render_to_response('hub/find_hubs_general.html', locals(), context_instance=RequestContext(request))
        return thereturn                
    else:
        return HttpResponseRedirect('/')
示例#10
0
文件: hubold.py 项目: ttagit/website
def JoinedHub(request, data_type, data_value):
    loggedin, data = ttagServiceAuth(request)
    response_count = ttagRequestCount(data['_id'])
    counts = response_count['counts']

    if loggedin:
        if data_type == 'id':
            response_joined = ttagGetJoinedHubsByHubUserId(data_value)
        elif data_type == 'name':
            response_joined = ttagGetJoinedHubsByUserName(data_value)

        if response_joined["result"] == "OK":
            hubs = response_joined["data"]["hubs"]
            return render_to_response('hub/user_hubs.html',
                                      locals(),
                                      context_instance=RequestContext(request))
        else:
            return HttpResponse(response_joined.msg)
    else:
        return HttpResponseRedirect('/')
示例#11
0
文件: hubold.py 项目: ttagit/website
def getHubTags(request, data_type, data_value):
    loggedin, data = ttagServiceAuth(request)
    response_count = ttagRequestCount(data['_id'])
    counts = response_count['counts']

    if data_type == "id":

        hub_response = ttagGetHubByHubId(data_value)

        if hub_response["result"] == "OK":
            hub = hub_response["data"]["hub"]
            from_time = 0 if 'from_time' not in request.POST else request.POST[
                'from_time']
            to_time = 4116171410000 if 'to_time' not in request.POST else request.POST[
                'to_time']
            items_per_page = 10000 if 'items_per_page' not in request.POST else request.POST[
                'items_per_page']
            page_number = 0 if 'page_number' not in request.POST else request.POST[
                'page_number']
            response = ttagGetHubTtags(data_value, from_time, to_time,
                                       items_per_page, page_number)
        else:
            return HttpResponse(hub_response["msg"])
    else:
        return HttpResponse("Invalid data type")

    if response["result"] == "OK":
        ttags = response["data"]["hub_ttags"]
        spraycan = True
        loggedin_user = data['_id']
        servertime = datetime.datetime.fromtimestamp(
            int(response['time']) / 1000)

        thereturn = render_to_response(
            'hub/hub_ttags.html',
            locals(),
            context_instance=RequestContext(request))
        return thereturn
    else:
        return HttpResponse(response["msg"])
示例#12
0
文件: hubold.py 项目: ttagit/website
def findHubs(request):
    authed, data = ttagServiceAuth(request)
    response = ttagRequestCount(data['_id'])
    counts = response['counts']
    if authed:
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        if 'hub_name' in request.POST and 'hub_desc' in request.POST:
            hub_name = request.POST["hub_name"]
            hub_desc = request.POST["hub_desc"]
            response = ttagCreateHub(user_id, access_token, hub_name, hub_desc,
                                     "true", "0")
            if response["result"] == "OK":
                #context = {"status":"created","hub":response["data"]["hub"]}
                status = "created"
                hub = response["data"]["hub"]
                return render_to_response(
                    'hub/hub_create.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                status = "error"
                error_msg = response["msg"]
                #context = {"status":"error","hub_name":hub_name,"hub_desc":hub_desc,"error_msg":response["msg"]}
                return render_to_response(
                    'hub/hub_create.html',
                    locals(),
                    context_instance=RequestContext(request))
        else:
            #context = {"status":"new"}
            status = "new"
            return render_to_response('hub/hub_create.html',
                                      locals(),
                                      context_instance=RequestContext(request))
    else:

        return HttpResponse("Invalid request")
示例#13
0
文件: hubold.py 项目: ttagit/website
def MainHub(request):
    loggedin, data = ttagServiceAuth(request)
    #"owner_id":"5064dd00559ae9da2b9e38b8","location_type":"HUB","user_id":"5064dd00559ae9da2b9e38b8","access_token":"ff891baeb4106593b40a5b9110c90f44"
    if loggedin:
        user_id = data["_id"]
        user_name = data["user_name"]
        response_hubs = ttagGetHubsByUserName(data['user_name'])
        #print response_hubs
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        block_title = "My Hubs"
        if response_hubs["result"] == "OK":
            hubs = response_hubs["data"]["hubs"]
            logined_and_different = False
            joined_hubs = ttagGetJoinedHubsByUserName(
                user_name)["data"]["hubs"]
            for hub in response_hubs["data"]["hubs"]:
                if hub["creater_id"] == user_id:
                    hub["owner"] = True
                else:
                    hub["owner"] = False
                hububub = ttagGetHubByHubId(hub["hub_id"])
                #print hububub
                hub["joined"] = False
                for joined_hub in joined_hubs:
                    #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                    if joined_hub["_id"] == hub["_id"]:
                        hub["joined"] = True
                        break

            return render_to_response('hub/user_hubs.html',
                                      locals(),
                                      context_instance=RequestContext(request))
        else:
            return HttpResponse(response_hubs["msg"])
    else:
        return HttpResponseRedirect('/')
示例#14
0
文件: hubold.py 项目: ttagit/website
def getHubMembers(request, data_type, data_value):
    loggedin, data = ttagServiceAuth(request)
    #"owner_id":"5064dd00559ae9da2b9e38b8","location_type":"HUB","user_id":"5064dd00559ae9da2b9e38b8","access_token":"ff891baeb4106593b40a5b9110c90f44"
    if loggedin:
        user_id = data["_id"]
        user_name = data["user_name"]
        response_hubs = ttagGetHubsByOwnerId(data['_id'],
                                             request.COOKIES['access_token'])
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']

        key_name = "hub_id"
        if data_type == "id":
            from_time = 0 if 'from_time' not in request.POST else request.POST[
                'from_time']
            to_time = 4116171410000 if 'to_time' not in request.POST else request.POST[
                'to_time']
            items_per_page = 10000 if 'items_per_page' not in request.POST else request.POST[
                'items_per_page']
            page_number = 0 if 'page_number' not in request.POST else request.POST[
                'page_number']
            response = ttagGetHubUsers(data_value, from_time, to_time,
                                       items_per_page, page_number)

        if response["result"] == "OK":
            hub_users = response["data"]["hub_users"]
            #context = {'hub_users': response["data"]["hub_users"],key_name:data_value}
            thereturn = render_to_response(
                'hub/hub_members.html',
                locals(),
                context_instance=RequestContext(request))
            return thereturn
        else:
            return HttpResponse(response["msg"])
    else:
        return HttpResponseRedirect('/')
示例#15
0
def user_showstats(data):
    if '_id' in data :
        response = ttagRequestCount(data['_id'])
        return {'data': data, 'counts': response['counts']}
    else :
        return {'data': '', 'counts': ''}
示例#16
0
文件: hubold.py 项目: ttagit/website
def getUserHubs(request,data_type,data_value,hub_type):

    authed, data = ttagServiceAuth(request)
    joined_hubs = []
    block_title = ""
    if authed:
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        user_name = data["user_name"]
           
        if data_type == "name":            
            if hub_type == "created":
                block_title = "My Hubs"
                response = ttagGetHubsByUserName(data_value, request.COOKIES['access_token'])
            elif hub_type == "member":
                block_title = "Joined Hubs"
                response = ttagGetJoinedHubsByUserName(data_value)
            else:
                response = ttagGetHubsByUserName(data_value)
                
        elif  data_type == "id":
            if hub_type == "created":
                block_title = "My Hubs"
                response = ttagGetHubsByOwnerId(data_value, request.COOKIES['access_token'])
            elif hub_type == "member":
                block_title = "Joined Hubs"
                response = ttagGetJoinedHubsByHubUserId(data_value)
            else:
                response = ttagGetHubsByOwnerId(data_value)
        elif request.method == 'POST':
                if request.POST['find_method'] == 'id':
                    response = ttagGetHubsByOwnerId(request.POST['query'], access_token)
                elif request.POST['find_method'] == 'name':
                    response = ttagGetHubsByUserName(request.POST['query'])
                
                
        if response["result"] == "OK":
            logined_and_different = (data_value != user_name and len(user_name) > 0)
            if logined_and_different:
                joined_hubs = ttagGetJoinedHubsByUserName(user_name)["data"]["hubs"]
                for hub in response["data"]["hubs"]:
                    if hub["creater_id"] == user_id:
                        hub["owner"] = True
                    else:
                        hub["owner"] = False
                    
                    hub["joined"] = False
                    for joined_hub in joined_hubs:
                        #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                        if joined_hub["_id"] == hub["_id"]:
                            hub["joined"] = True
                            break
                        
            hubs = response['data']['hubs']
            #print 'user_id:' + user_id
            #context = {'hubs': response["data"]["hubs"],"user_id":user_id,"joined_hubs":joined_hubs,"logined_and_different":logined_and_different}
            thereturn = render_to_response('hub/user_hubs_joined.html', locals(), context_instance=RequestContext(request))
            return thereturn
        else:
            return HttpResponse(response["msg"])
                
    else:
        return HttpResponseRedirect('/')
    

        return thereturn   
示例#17
0
def user_showstats(data):
    if '_id' in data:
        response = ttagRequestCount(data['_id'])
        return {'data': data, 'counts': response['counts']}
    else:
        return {'data': '', 'counts': ''}
示例#18
0
文件: hubold.py 项目: ttagit/website
def getUserHubs(request, data_type, data_value, hub_type):

    authed, data = ttagServiceAuth(request)
    joined_hubs = []
    block_title = ""
    if authed:
        response_count = ttagRequestCount(data['_id'])
        counts = response_count['counts']
        access_token = request.COOKIES['access_token']
        user_id = data["_id"]
        user_name = data["user_name"]

        if data_type == "name":
            if hub_type == "created":
                block_title = "My Hubs"
                response = ttagGetHubsByUserName(
                    data_value, request.COOKIES['access_token'])
            elif hub_type == "member":
                block_title = "Joined Hubs"
                response = ttagGetJoinedHubsByUserName(data_value)
            else:
                response = ttagGetHubsByUserName(data_value)

        elif data_type == "id":
            if hub_type == "created":
                block_title = "My Hubs"
                response = ttagGetHubsByOwnerId(
                    data_value, request.COOKIES['access_token'])
            elif hub_type == "member":
                block_title = "Joined Hubs"
                response = ttagGetJoinedHubsByHubUserId(data_value)
            else:
                response = ttagGetHubsByOwnerId(data_value)
        elif request.method == 'POST':
            if request.POST['find_method'] == 'id':
                response = ttagGetHubsByOwnerId(request.POST['query'],
                                                access_token)
            elif request.POST['find_method'] == 'name':
                response = ttagGetHubsByUserName(request.POST['query'])

        if response["result"] == "OK":
            logined_and_different = (data_value != user_name
                                     and len(user_name) > 0)
            if logined_and_different:
                joined_hubs = ttagGetJoinedHubsByUserName(
                    user_name)["data"]["hubs"]
                for hub in response["data"]["hubs"]:
                    if hub["creater_id"] == user_id:
                        hub["owner"] = True
                    else:
                        hub["owner"] = False

                    hub["joined"] = False
                    for joined_hub in joined_hubs:
                        #print "Joined Hub:" + hub["hub_name"]+":" + joined_hub["_id"] + "======" + hub["_id"]+":"+hub["hub_name"]
                        if joined_hub["_id"] == hub["_id"]:
                            hub["joined"] = True
                            break

            hubs = response['data']['hubs']
            #print 'user_id:' + user_id
            #context = {'hubs': response["data"]["hubs"],"user_id":user_id,"joined_hubs":joined_hubs,"logined_and_different":logined_and_different}
            thereturn = render_to_response(
                'hub/user_hubs_joined.html',
                locals(),
                context_instance=RequestContext(request))
            return thereturn
        else:
            return HttpResponse(response["msg"])

    else:
        return HttpResponseRedirect('/')

        return thereturn
示例#19
0
文件: user.py 项目: ttagit/website
def userProfileView(request,
                    user_name='',
                    view_type='',
                    page='',
                    time='',
                    userdetails='',
                    pagetitle='ttagit - User Profile Page',
                    pagetemplate='user_profile.html',
                    partial=None,
                    hideMiniSpraycan=False):
    try:
        authed, data = ttagServiceAuth(request)
        follow = -1
        loggedin_user = '' if not authed else data['_id']
        if user_name != '':
            if request.COOKIES.has_key('access_token'):
                response = ttagRequestUserProfileWithAccessToken(
                    user_name, request.COOKIES['access_token'])
            else:
                response = ttagRequestUserProfile(user_name)
            if 'data' in response and response['data'][
                    'is_activated'] and not response['data']['is_deleted']:
                data = response['data']
                if 'follow' in response:
                    follow = response['follow']
                if loggedin_user == data['_id']:
                    follow = -1
            else:
                return HttpResponseRedirect(reverse('home-page'))
        elif data != None and 'user_name' in data:
            user_name = data['user_name']
        if not data or data == None:
            return HttpResponseRedirect(reverse('home-page'))
        response = ttagRequestCount(data['_id'])
        if 'counts' in response:
            counts = response['counts']
            servertime = response['time']
            counts['tags'] = counts['ttags']
            counts['following'] = counts['followees']
        else:
            counts = {'tags': 0, 'replies': 0, 'followers': 0, 'following': 0}
            import time
            servertime = int(
                time.mktime(datetime.datetime.now().timetuple()) * 1000)
        if view_type not in [
                'tags', 'replies', 'following', 'followers', 'finds',
                'favorites'
        ]:
            view_type = 'tags'
        if partial is not None:
            return render_to_response(partial,
                                      locals(),
                                      context_instance=RequestContext(request))
        if not page or page == '':
            page = 1
        page = int(page)
        if not time or time == '':
            time = 0
        time = int(time)
        more = True if counts[
            view_type] > PROFILE_ITEM_ROWS * page and time == 0 else False
        if userdetails == '':
            userdetails = getUserDetails(request, data, user_name, data['_id'],
                                         loggedin_user, view_type, page, time,
                                         more)
        if request.is_ajax():
            return HttpResponse(userdetails)
        context = {
            'view_type': view_type,
            'data': data,
            'counts': counts,
            'pagetitle': pagetitle,
            'request': request,
            'loggedin': False,
            'details': userdetails,
            'page': page,
            'servertime': servertime,
            'follow': follow,
            'showfollow': True,
            'hideMiniSpraycan': hideMiniSpraycan
        }
        if authed:
            context['loggedin'] = True
        return render_to_response(pagetemplate,
                                  context,
                                  context_instance=RequestContext(request))
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
示例#20
0
def settingsView(request, popup=False):
    """Show the user settings dashboard page"""
    try:
        thereturn = loginscreen(request)
        from webapp.views.user import getUserVariables
        loggedin, user, loggedin_user, follow, data = getUserVariables(
            request, '')
        if loggedin:
            if request.method != "POST":
                formdata = {
                    'gender': '',
                    'google_map_address': '',
                    'pro_description': ''
                }
                for key in data:
                    formdata[key] = data[key]
            else:
                formdata = request.POST

            form = SettingsForm(formdata)
            response = ttagRequestCount(data['_id'])
            if popup != False:
                showPopup = True
                popupPartial = "partial_" + popup + "_popup.html"
            pagetitle = "ttagit - User Settings Page"
            location = "Settings"
            if request.is_ajax():
                from website.localsettings.paths import S3TATIC_URL
                userpanel = render_to_response(
                    "partial_home_settings.html",
                    locals(),
                    context_instance=RequestContext(request))
                userdetails = render_to_response(
                    "partial_user_details.html",
                    locals(),
                    context_instance=RequestContext(request))
                head = render_to_response("djview_head_resources.html", {
                    'headScripts':
                    mark_safe(
                        '<script type="text/javascript" src="' + S3TATIC_URL +
                        'scripts/passwordstrength.js"></script><script type="text/javascript" src="'
                        + S3TATIC_URL + 'scripts/settings.js"></script>')
                },
                                          context_instance=RequestContext(
                                              request))
                jsonReturn = simplejson.dumps({
                    "context":
                    mark_safe(userdetails.content),
                    "results":
                    mark_safe(userpanel.content),
                    'head':
                    mark_safe(head.content)
                })
                thereturn = HttpResponse(mark_safe(jsonReturn))
            else:
                thereturn = render_to_response(
                    'home_settings.html',
                    locals(),
                    context_instance=RequestContext(request))
        return thereturn
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)