def delete(request, data_type, data_value): try : thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables(request, '') if loggedin : user_name = user['user_name'] if data_type == 'id' : hub_id = data_value respHub = ttagGetHubByHubId(hub_id) #print respHub if respHub['result'] == 'OK' and respHub['data']['hub']['user']['user_id'] == loggedin_user : if not request.POST : hub = respHub['data']['hub'] thereturn = render_to_response('partial_userhub_confirmdelete.html',locals(),context_instance=RequestContext(request)) else : if 'hub_id' in locals() : response = ttagDeleteHub(loggedin_user, request.COOKIES['access_token'], hub_id) if request.is_ajax() : thereturn = HttpResponse(mark_safe('<article class="deleted">Hub deleted</article>')) else : thereturn = HttpResponseRedirect(request.META['HTTP_REFERER']) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def updateHub(request,data_type,data_value): hub_id = data_value authed, user = ttagServiceAuth(request) if authed: access_token = request.COOKIES['access_token'] user_id = user["_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 = ttagUpdateHub(user_id, access_token, hub_id,hub_name, hub_desc,"true", "0") if response["result"] == "OK": hub = response["data"]["hub"] return render_to_response('hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: hub = response["data"]["hub"] return render_to_response('hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: response = ttagGetHubByHubId(hub_id) if response["result"] == "OK": hub = response["data"]["hub"] return render_to_response('hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: return HttpResponse(response["msg"]) else: return HttpResponse("Invalid request")
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"])
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('/')
def get_hub_by_id(request, hub_id, user): if not hub_id in hub_registry.hubs_by_id: hub_registry.hubs_by_id[hub_id] = None response = ttagGetHubByHubId(hub_id) if("data" in response and "hub" in response["data"]): hub = Hub(request, response["data"]["hub"]) hub_registry.hubs_by_id[hub_id] = processHub(hub, user) return hub_registry.hubs_by_id[hub_id]
def page(request, page): try : from webapp.views.user import PROFILE_ITEM_ROWS as ITEMS_PER_ROW thereturn = loginscreen(request) hubs = {} loggedin, user, loggedin_user, follow, data = getUserVariables(request, '') if loggedin : notifications = ttagPost("/notification/get-all", {'access_token': request.COOKIES['access_token']}) for notice in notifications['data'] : if notice['notification_type'] == 'REPLY_TTAG' : if 'ttag_location_type' in notice['notification_data']['value'] : if notice['notification_data']['value']['ttag_location_type'] == 'wall' : notice['notification_data']['value']['ttag_title'] = notice['notification_data']['value']['ttag_title'].replace(data['full_name']+"'s Wall",'your Wall') elif notice['notification_data']['value']['ttag_location_type'] == 'HUB' : hub_id = notice['notification_data']['value']['ttag_location'].split('#')[0] if hub_id not in hubs : hubdata = ttagGetHubByHubId(hub_id) hubs[hub_id] = hubdata else : hubdata = hubs[hub_id] if hubdata['result'] == 'OK' : notice['notification_data']['value']['ttag_title'] = hubdata['data']['hub']['hub_name'] response = {'notifications':notifications['data']} page = int(page) next = True if page > 1 else False more = True if page * 15 < len(notifications['data']) else False location = 'Notifications' if next and request.is_ajax() : thereturn = render_to_response("partial_notifications_notices.html",locals(),context_instance=RequestContext(request)) elif request.is_ajax() : userpanel = render_to_response("partial_notifications_details.html",locals(),context_instance=RequestContext(request)) userdetails = render_to_response("partial_user_details.html",locals(),context_instance=RequestContext(request)) jsonReturn = simplejson.dumps({"context":mark_safe(userdetails.content),"results":mark_safe(userpanel.content)}) thereturn = HttpResponse(mark_safe(jsonReturn)) else : thereturn = render_to_response('notifications_details.html', locals(), context_instance=RequestContext(request)) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
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"])
def updateHub(request, data_type, data_value): hub_id = data_value authed, user = ttagServiceAuth(request) if authed: access_token = request.COOKIES['access_token'] user_id = user["_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 = ttagUpdateHub(user_id, access_token, hub_id, hub_name, hub_desc, "true", "0") if response["result"] == "OK": hub = response["data"]["hub"] return render_to_response( 'hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: hub = response["data"]["hub"] return render_to_response( 'hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: response = ttagGetHubByHubId(hub_id) if response["result"] == "OK": hub = response["data"]["hub"] return render_to_response( 'hub/hub_update.html', locals(), context_instance=RequestContext(request)) else: return HttpResponse(response["msg"]) else: return HttpResponse("Invalid request")
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('/')
def delete(request, data_type, data_value): try: thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables( request, '') if loggedin: user_name = user['user_name'] if data_type == 'id': hub_id = data_value respHub = ttagGetHubByHubId(hub_id) #print respHub if respHub['result'] == 'OK' and respHub['data']['hub']['user'][ 'user_id'] == loggedin_user: if not request.POST: hub = respHub['data']['hub'] thereturn = render_to_response( 'partial_userhub_confirmdelete.html', locals(), context_instance=RequestContext(request)) else: if 'hub_id' in locals(): response = ttagDeleteHub( loggedin_user, request.COOKIES['access_token'], hub_id) if request.is_ajax(): thereturn = HttpResponse( mark_safe( '<article class="deleted">Hub deleted</article>' )) else: thereturn = HttpResponseRedirect( request.META['HTTP_REFERER']) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def page(request, page): try: from webapp.views.user import PROFILE_ITEM_ROWS as ITEMS_PER_ROW thereturn = loginscreen(request) hubs = {} loggedin, user, loggedin_user, follow, data = getUserVariables( request, '') if loggedin: notifications = ttagPost( "/notification/get-all", {'access_token': request.COOKIES['access_token']}) for notice in notifications['data']: if notice['notification_type'] == 'REPLY_TTAG': if 'ttag_location_type' in notice['notification_data'][ 'value']: if notice['notification_data']['value'][ 'ttag_location_type'] == 'wall': notice['notification_data']['value'][ 'ttag_title'] = notice['notification_data'][ 'value']['ttag_title'].replace( data['full_name'] + "'s Wall", 'your Wall') elif notice['notification_data']['value'][ 'ttag_location_type'] == 'HUB': hub_id = notice['notification_data']['value'][ 'ttag_location'].split('#')[0] if hub_id not in hubs: hubdata = ttagGetHubByHubId(hub_id) hubs[hub_id] = hubdata else: hubdata = hubs[hub_id] if hubdata['result'] == 'OK': notice['notification_data']['value'][ 'ttag_title'] = hubdata['data']['hub'][ 'hub_name'] response = {'notifications': notifications['data']} page = int(page) next = True if page > 1 else False more = True if page * 15 < len(notifications['data']) else False location = 'Notifications' if next and request.is_ajax(): thereturn = render_to_response( "partial_notifications_notices.html", locals(), context_instance=RequestContext(request)) elif request.is_ajax(): userpanel = render_to_response( "partial_notifications_details.html", locals(), context_instance=RequestContext(request)) userdetails = render_to_response( "partial_user_details.html", locals(), context_instance=RequestContext(request)) jsonReturn = simplejson.dumps({ "context": mark_safe(userdetails.content), "results": mark_safe(userpanel.content) }) thereturn = HttpResponse(mark_safe(jsonReturn)) else: thereturn = render_to_response( 'notifications_details.html', locals(), context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)