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)
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)
def url(request, location=None, start_time=None, partial='spraycan.html', renderJSON=False, thetemplate=None, user_name=None, location_type='URL', payload={}, allowPublic=False, to_time=INFINITE_TIME): if location == None and 'location_type' in request.GET: location_type = request.GET['location_type'] if location == None: location = request.GET.get('location', "") renderJSON = (request.is_ajax()) if start_time == None: start_time = START_TIME if 'start_time' not in request.GET else request.GET[ 'start_time'] if 'to_time' in request.GET: to_time = request.GET['to_time'] thereturn = loginscreen(request) if not request.is_ajax(): theredirect = "http://www.ttagit.com" if 'location' not in request.GET else request.GET[ 'location'] thereturn = HttpResponseRedirect(theredirect) loggedin, data = ttagServiceAuth(request) if data != None: data['loggedin'] = loggedin if loggedin or allowPublic: thereturn = buildURL(request, data, location, location_type, user_name, start_time, renderJSON, partial, thetemplate, payload, to_time) return thereturn
def create(request, user_name=''): try: thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables( request, user_name) if loggedin: user_name = user['user_name'] if not request.POST: thereturn = render_to_response( 'partial_user_createhub.html', locals(), context_instance=RequestContext(request)) else: 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(loggedin_user, request.COOKIES['access_token'], hub_name, hub_desc, "", "", "true", "0") if request.is_ajax(): thereturn = render_to_response( 'partial_user_hubcreated.html', locals(), context_instance=RequestContext(request)) else: from django.core.urlresolvers import reverse thereturn = HttpResponseRedirect( reverse('userhub-created', args=(user_name))) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def ttagRemove(request, ttag_id): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: if request.method == "POST": response = ttagPost( "/user-data/remove-ttag", {"ttag_id": ttag_id, "user_id": user["_id"], "access_token": request.COOKIES["access_token"]}, ) location = request.POST["location"] if request.is_ajax(): thereturn = HttpResponse(mark_safe('<article class="deleted">Ttag deleted</article>')) else: thereturn = HttpResponseRedirect(location) else: location = request.META["HTTP_REFERER"] if "location" not in request.GET else request.GET["location"] user_name = user["user_name"] thereturn = render_to_response( "partial_ttag_confirmdelete.html", locals(), context_instance=RequestContext(request) ) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def ttagRemove(request, ttag_id): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: if request.method == 'POST': response = ttagPost( '/user-data/remove-ttag', { 'ttag_id': ttag_id, 'user_id': user['_id'], 'access_token': request.COOKIES['access_token'] }) location = request.POST['location'] if request.is_ajax(): thereturn = HttpResponse( mark_safe( '<article class="deleted">Ttag deleted</article>')) else: thereturn = HttpResponseRedirect(location) else: location = request.META[ 'HTTP_REFERER'] if 'location' not in request.GET else request.GET[ 'location'] user_name = user['user_name'] thereturn = render_to_response( 'partial_ttag_confirmdelete.html', locals(), context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
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)
def search(request, user_name=''): try: thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables( request, user_name) if loggedin: user_name = user['user_name'] if not request.POST: thereturn = render_to_response( 'partial_user_searchhub.html', locals(), context_instance=RequestContext(request)) elif 'query' in request.POST and len(request.POST['query']) > 0: response = ttagGetHubsByName(request.POST['query']) if response['result'] == 'OK': response['data']['hubs'] = processRawHubs( response['data']['hubs'], request) from webapp.views.user import getUserHubs response['data']['joinedhubs'] = getUserHubs( user['user_name']) thereturn = render_to_response( 'partial_userhub_searchresults.html', locals(), context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
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 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)
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)
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)
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)
def userAvatarUpload(request, isAndroid=False): try : authed, data = ttagServiceAuth(request) if authed and request.method == 'POST' : aToken = request.COOKIES['access_token'] formdata = {'gender':'','google_map_address':'','pro_description':''} if len(str(request.POST.get('avatar_src',""))) > 0 and len(str(request.POST.get('avatar_name',""))) > 0 and len(str(request.POST.get('avatar_type',""))) > 0 : files = {} from django.core.files.uploadedfile import SimpleUploadedFile import base64 files['avatar_upload'] = SimpleUploadedFile(request.POST['avatar_name'],base64.b64decode(mark_safe(request.POST['avatar_src'])),request.POST['avatar_type']) else : files = request.FILES for key in data : formdata[key] = data[key] upload = UploadFileForm(request.POST, files) statusmsg = "User Avatar update successful!" print request.POST if 'avatar_upload' not in request.POST and 'avatar_src' not in request.POST and len(str(request.POST.get('avatar_url',''))) > 0 : upload = SettingsAvatarForm(request.POST) if upload.is_valid() : avatar_url = upload.clean_AvatarURL() if not upload.is_valid() : statusmsg = ''.join(["User Avatar update failed: ",upload.errors.as_text().replace('\r','').replace('\n','')]) svcResp = {'result':'ERROR','msg':statusmsg} else : from website.settings import MEDIA_URL if 'avatar_delete' in request.POST or 'avatar_upload' in request.POST : avatar_url = '' if 'avatar_upload' in files : avatar_url = ''.join([MEDIA_URL,handleUploadedAvatar(files['avatar_upload'], data['user_name'], aToken)]) if 'avatar_url' in locals() and avatar_url != data['avatar_url'] : svcResp = ttagServiceAvatarChange(aToken,avatar_url) if svcResp.get('result',"OK") == 'OK' : svcResp['data'], data['avatar_url'] = {'filename':avatar_url}, avatar_url else : statusmsg = ''.join(["User Avatar update failed: ",svcResp['msg']]) svcResp['msg'] = statusmsg else : svcResp = {'result':'OK','msg':'Nothing changed'} svcResp = mark_safe(simplejson.dumps(svcResp)) form = SettingsForm(formdata) context = {'request':request,'loggedin':True,'data':data,'form':form,'settings_message':statusmsg, 'location':'Settings', 'svcResp':svcResp} ajax_page = 'user_avataruploaded.html' if not isAndroid else 'android_avataruploaded.html' page = ajax_page if ( request.is_ajax() or isAndroid ) else 'home_settings.html' thereturn = render_to_response(page,context,context_instance=RequestContext(request)) if request.is_ajax() and not isAndroid and 'avatar_url' in locals() and len(str(avatar_url)) > 0 : jsonReturn = simplejson.dumps({'userAvatar':mark_safe('<img data-dj-view="userAvatar" src="'+avatar_url+'" alt="" />'),'userAvatarForm':mark_safe(thereturn.content)}) thereturn = render_to_response('ajax_ttag_create.html',locals(),context_instance=RequestContext(request)) return thereturn else : return loginscreen(request) except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def delete(request): try : thereturn = loginscreen(request) if 'notification' in request.POST : notifications = request.POST.getlist('notification') deleted = ttagPost("/notification/delete",{'access_token':request.COOKIES['access_token'],'notifications':notifications}) if deleted['result'] == 'OK' : thereturn = HttpResponse("Notifications deleted successfully.") if request.is_ajax() : thereturn = render_to_response('ajax_notification.html', locals(), context_instance=RequestContext(request)) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def hash(request): location = request.GET['location'] start_time = '0' if 'start_time' not in request.GET else request.GET[ 'start_time'] location_type = 'hashtag' thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: ttags = ttagPost( "/find/hashtag", { 'hashtag': str(location), 'items_per_page': '10000', 'page_number': '0' }) localprint(request, ttags) if ttags['result'] == 'OK': import datetime response = { 'time': ttags['time'], 'data': { 'founder': { 'location_type': 'hashtag', 'location': location }, 'favorite': False, 'ttags': [] if ttags['data']['ttags'] == None else ttags['data']['ttags'], 'spams': [] if 'spams' not in ttags['data'] or ttags['data']['spams'] == None or 'ttag_list' not in ttags['data']['spams'] or ttags['data']['spams']['ttag_list'] == None else ttags['data']['spams']['ttag_list'], 'thumbups': [] if 'thumbups' not in ttags['data'] or ttags['data']['thumbups'] == None or 'ttag_list' not in ttags['data']['thumbups'] or ttags['data']['thumbups']['ttag_list'] == None else ttags['data']['thumbups']['ttag_list'] } } loggedin_user = data['_id'] servertime = datetime.datetime.fromtimestamp( int(ttags['time']) / 1000) thereturn = render_to_response( "spraycan.html", locals(), context_instance=RequestContext(request)) return thereturn
def userWallSpraycan(request, user_name): try : thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables(request, user_name) if loggedin : ttaguser = data if request.is_ajax() : spraycanURL = '/'.join(['','user',data['_id'],'wall']) location = spraycanURL thereturn = render_to_response('partial_user_minispraycan.html',locals(),context_instance=RequestContext(request)) else : thereturn = userWallView(request, user_name) return thereturn; except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def ttagDelete(request, ttag_id): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: response = ttagPost( "/ttag/delete", {"ttag_id": ttag_id, "user_id": user["_id"], "access_token": request.COOKIES["access_token"]}, ) location = request.META["HTTP_REFERER"] if "location" not in request.GET else request.GET["location"] if request.is_ajax(): thereturn = HttpResponse(mark_safe('<article class="deleted">Ttag deleted</article>')) else: thereturn = HttpResponseRedirect(location) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def search(request, user_name=''): try : thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables(request, user_name) if loggedin : user_name = user['user_name'] if not request.POST : thereturn = render_to_response('partial_user_searchhub.html',locals(),context_instance=RequestContext(request)) elif 'query' in request.POST and len(request.POST['query']) > 0 : response = ttagGetHubsByName(request.POST['query']) if response['result'] == 'OK' : response['data']['hubs'] = processRawHubs(response['data']['hubs'], request) from webapp.views.user import getUserHubs response['data']['joinedhubs'] = getUserHubs(user['user_name']) thereturn = render_to_response('partial_userhub_searchresults.html',locals(),context_instance=RequestContext(request)) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
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)
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)
def url(request, location=None, start_time=None, partial='spraycan.html', renderJSON=False, thetemplate=None, user_name=None, location_type='URL', payload={}, allowPublic=False, to_time=INFINITE_TIME): if location == None and 'location_type' in request.GET : location_type = request.GET['location_type'] if location == None : location = request.GET.get('location',"") renderJSON = ( request.is_ajax() ) if start_time == None : start_time = START_TIME if 'start_time' not in request.GET else request.GET['start_time'] if 'to_time' in request.GET : to_time = request.GET['to_time'] thereturn = loginscreen(request) if not request.is_ajax() : theredirect = "http://www.ttagit.com" if 'location' not in request.GET else request.GET['location'] thereturn = HttpResponseRedirect(theredirect) loggedin, data = ttagServiceAuth(request) if data != None : data['loggedin'] = loggedin if loggedin or allowPublic : thereturn = buildURL(request, data, location, location_type, user_name, start_time, renderJSON, partial, thetemplate, payload, to_time) return thereturn
def userWallSpraycan(request, user_name): try: thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables( request, user_name) if loggedin: ttaguser = data if request.is_ajax(): spraycanURL = '/'.join(['', 'user', data['_id'], 'wall']) location = spraycanURL thereturn = render_to_response( 'partial_user_minispraycan.html', locals(), context_instance=RequestContext(request)) else: thereturn = userWallView(request, user_name) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
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)
def hash(request): location = request.GET['location'] start_time = '0' if 'start_time' not in request.GET else request.GET['start_time'] location_type = 'hashtag' thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin : ttags = ttagPost("/find/hashtag",{'hashtag': str(location), 'items_per_page': '10000', 'page_number': '0'}) localprint(request, ttags) if ttags['result'] == 'OK' : import datetime response = {'time': ttags['time'], 'data':{ 'founder': {'location_type':'hashtag','location':location}, 'favorite': False, 'ttags':[] if ttags['data']['ttags'] == None else ttags['data']['ttags'], 'spams':[] if 'spams' not in ttags['data'] or ttags['data']['spams'] == None or 'ttag_list' not in ttags['data']['spams'] or ttags['data']['spams']['ttag_list'] == None else ttags['data']['spams']['ttag_list'], 'thumbups':[] if 'thumbups' not in ttags['data'] or ttags['data']['thumbups'] == None or 'ttag_list' not in ttags['data']['thumbups'] or ttags['data']['thumbups']['ttag_list'] == None else ttags['data']['thumbups']['ttag_list']}} loggedin_user = data['_id'] servertime = datetime.datetime.fromtimestamp(int(ttags['time'])/1000) thereturn = render_to_response("spraycan.html", locals(), context_instance=RequestContext(request)) return thereturn
def delete(request): try: thereturn = loginscreen(request) if 'notification' in request.POST: notifications = request.POST.getlist('notification') deleted = ttagPost( "/notification/delete", { 'access_token': request.COOKIES['access_token'], 'notifications': notifications }) if deleted['result'] == 'OK': thereturn = HttpResponse("Notifications deleted successfully.") if request.is_ajax(): thereturn = render_to_response( 'ajax_notification.html', locals(), context_instance=RequestContext(request)) 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)
def create(request, user_name=''): try : thereturn = loginscreen(request) loggedin, user, loggedin_user, follow, data = getUserVariables(request, user_name) if loggedin : user_name = user['user_name'] if not request.POST : thereturn = render_to_response('partial_user_createhub.html',locals(),context_instance=RequestContext(request)) else : 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(loggedin_user, request.COOKIES['access_token'], hub_name, hub_desc, "", "", "true", "0") if request.is_ajax() : thereturn = render_to_response('partial_user_hubcreated.html',locals(),context_instance=RequestContext(request)) else : from django.core.urlresolvers import reverse thereturn = HttpResponseRedirect(reverse('userhub-created', args=(user_name))) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
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)
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)
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 ttagDelete(request, ttag_id): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: response = ttagPost( '/ttag/delete', { 'ttag_id': ttag_id, 'user_id': user['_id'], 'access_token': request.COOKIES['access_token'] }) location = request.META[ 'HTTP_REFERER'] if 'location' not in request.GET else request.GET[ 'location'] if request.is_ajax(): thereturn = HttpResponse( mark_safe( '<article class="deleted">Ttag deleted</article>')) else: thereturn = HttpResponseRedirect(location) 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)
def search(request): try : thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin : if 'search' in request.POST : atusername = '' emailform = SpraycanSearchEmail(request.POST) usernameform = SpraycanSearchUsername(request.POST) if emailform.is_valid() : resp = ttagPost('/validate/request-username-by-email',{'email':emailform.getSpraycan_Search()}) if resp['result'] == 'OK' and resp['find_by_email'] : atusername = resp['user_name'] elif usernameform.is_valid() : resp = ttagRequestUserProfile(usernameform.getSpraycan_Search()[1:]) if resp['result'] == 'OK' : atusername = resp['data']['user_name'] if atusername != '' : # from django.core.urlresolvers import reverse # return render_to_response("javascript_redirect.html", {"redirect_url" : reverse('user-profile', kwargs={'user_name':atusername,'view_type':'','page':'','time':''}),'hidespraycan':'true'}) from webapp.views.user import userWallView return userWallView(request, atusername) form = SpraycanSearch(request.POST) if form.is_valid() : urlform = SpraycanSearchURL(request.POST) if urlform.is_valid() : #show spraycan for URL thereturn = url(request, urlform.getSpraycan_Search()) else : #show search results import datetime from webapp.views.user import getUserFollowers location_type = 'search' loggedin_user = data['_id'] filter = request.POST.get('filter', "All") ttags = ttagPost('/find/url-keyword-hashtag',{'query':form.getSpraycan_Search(),'items_per_page':'100','page_number':'0'}) response = {'time': ttags['time'], 'data':{ 'founder': {}, 'favorite': False, 'ttags':[] if filter not in ['All','Tags'] or ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else ttags['data']['ttags'], 'users': [] if filter not in ['All','Users'] or ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else ttags['data']['users'], 'hashtags': [] if filter not in ['All','HashTags'] or ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else ttags['data']['hashtags'], 'location': [] if filter not in ['All','Locations'] or ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else ttags['data']['location'], 'hubs': [] if filter not in ['All','Hubs'] or ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else ttags['data']['hubs'], 'spams':[], 'thumbups':[]}} from webapp.models.hub import processRawHubs response['data']['hubs'] = processRawHubs(response['data']['hubs'], request) response['data']['followers'] = getUserFollowers(loggedin_user) from webapp.views.user import getUserHubs response['data']['joinedhubs'] = getUserHubs(data['user_name']) response['data']['searchcounts'] = { 'ttags': 0 if ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else len(ttags['data']['ttags']), 'users': 0 if ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else len(ttags['data']['users']), 'hashtags': 0 if ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else len(ttags['data']['hashtags']), 'location': 0 if ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else len(ttags['data']['location']), 'hubs': 0 if ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else len(ttags['data']['hubs']) } servertime = datetime.datetime.fromtimestamp(int(ttags['time'])/1000) if request.is_ajax() : thetemplate = 'base_ajax.html' thereturn = render_to_response("spraycan.html", locals(), context_instance=RequestContext(request)) if request.is_ajax() : usercontext = mark_safe(render_to_response('partial_user_details.html',locals(),context_instance=RequestContext(request)).content) import simplejson jsonReturn = simplejson.dumps({'context':usercontext,'results':mark_safe(thereturn.content)}) thereturn = HttpResponse(mark_safe(jsonReturn)); return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def ttagReply(request, ttag_id): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: ttagdata = ttagPost( "/ttag/get", { "access_token": request.COOKIES["access_token"], "user_id": data["_id"], "ttag_id": ttag_id, "search_on": "ttag", }, ) if "result" in ttagdata and ttagdata["result"] == "OK": ttag = ttagdata["data"]["ttag"] if "Comment" in request.POST: form = TtagReply(request.POST) if form.is_valid(): import re, urllib hashtags = "".join(re.findall(r"\#\w+", request.POST["Comment"])) root_id = ttag_id if ttag["root_id"] == "0" else ttag["root_id"] ttagdata = { "access_token": request.COOKIES["access_token"], "user_id": data["_id"], "parent_user_id": form.getTtag_ParentUser(), "location": ttag["location"], "location_type": ttag["location_type"], "ttag_content": form.getTtag_Comment(), "root_id": root_id, "parent_id": ttag_id, "title": ttag["title"], "hashtags": hashtags, "meta_url": urlquote_plus(form.getTtag_metaurl()), "meta_thumbnail": urlquote_plus(form.getTtag_metathumbnail()), "meta_title": urlquote_plus(form.getTtag_metatitle()), "meta_desc": urlquote_plus(form.getTtag_metadesc()), "wall_owner_id": ttag.get("wall_owner_id", ""), } request.is_wallowner = ttag["wall_owner_id"] == data["_id"] reply = ttagPost("/ttag/create", ttagdata) if reply["result"] == "OK": from webapp.views.email import notifyOfReply # send reply notification notifyOfReply( request, ttagdata["parent_user_id"], ttagdata["user_id"], ttagdata["parent_id"], reply["data"]["ttag"]["_id"], ) # return template if not request.is_ajax(): thereturn = HttpResponseRedirect(request.POST["location"]) else: thereturn = ttagShowOriginal(request, reply["data"]["ttag"]["_id"], ttag_id) else: thereturn = HttpResponse(reply["msg"]) else: thereturn = HttpResponse(str(form.errors)) else: context = { "request": request, "data": data, "loggedin": loggedin, "pagetitle": "ttagit - Ttag Reply Form", "reply_id": ttag_id, "ttag": ttagdata["data"]["ttag"], "servertime": datetime.datetime.fromtimestamp(int(ttagdata["time"]) / 1000), } thereturn = render_to_response("ttag_reply.html", context, context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def ttagCreate(request): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: if "Comment" in request.POST: form = TtagPost(request.POST) print [form.is_valid(), len(str(request.POST["Comment"])), len(request.POST.get("meta_thumbnail", ""))] print form.errors if form.is_valid() and ( len(str(request.POST["Comment"])) or len(request.POST.get("meta_thumbnail", "")) ): import re, urllib location_type = ( "URL" if ("location_type" not in request.POST or request.POST["location_type"] not in ["wall", "HUB"]) else request.POST["location_type"] ) remotetitle = "" if location_type == "URL": getTitle = ttagPost( "/find/get-title", {"location": form.getTtag_Location(), "location_type": "URL"} ) try: remotetitle = getTitle["data"]["location_data"]["title"] except: import urllib2 import socket timeout = 3 socket.setdefaulttimeout(timeout) try: req = urllib2.Request(form.getTtag_Location()) remotecontent = urllib2.urlopen(req).read() except: remotecontent = mark_safe("<title></title>") # remotetitle = re.search(r"<title>(.*?)</title>", remotecontent).group(1) title_dict = get_title(remotecontent, request) if title_dict["status"] == "OK": remotetitle = title_dict["msg"] elif title_dict["status"] == "ERROR": remotetitle = "" elif location_type == "wall": if "wall_owner_id" in request.POST: wallOwner = ttagServiceByUserID(form.clean_Ttag_WallOwnerID()) if wallOwner["result"] == "OK": remotetitle = wallOwner["data"]["user"]["full_name"] + "'s Wall" hashtags = "".join(re.findall(r"\#\w+", request.POST["Comment"])) root_id = "0" ttag_id = "0" ttagdata = { "access_token": request.COOKIES["access_token"], "user_id": user["_id"], "location": form.getTtag_Location(), "location_type": location_type, "ttag_content": form.getTtag_Comment(), "root_id": root_id, "parent_id": ttag_id, "title": remotetitle.strip(), "hashtags": hashtags, "meta_url": urlquote_plus(form.getTtag_metaurl()), "meta_thumbnail": urlquote_plus(form.getTtag_metathumbnail()), "meta_title": urlquote_plus(form.getTtag_metatitle()), "meta_desc": urlquote_plus(form.getTtag_metadesc()), } if "wall_owner_id" in request.POST: ttagdata["wall_owner_id"] = form.clean_Ttag_WallOwnerID() request.is_wallowner = form.clean_Ttag_WallOwnerID() == user["_id"] create = ttagPost("/ttag/create", ttagdata) if create["result"] == "OK": if not request.is_ajax(): import urllib thereturn = HttpResponseRedirect( paths.HTTPS + request.get_host() + "/spraycan/url/?location=" + urlquote_plus(request.POST["location"]) ) elif "position" in request.POST and request.POST["position"] == "minispraycan": thereturn = render_to_response("partial_user_minispraycansuccess.html", locals()) else: location = form.getTtag_Location() from webapp.views import spraycan ttags = spraycan.url( request, location, request.POST["start_time"], "partial_spraycan_ttags.html", False, None, None, location_type, ) response = {"time": request.session["start_time"]} feed = render_to_response( "partial_spraycan_feed.html", locals(), context_instance=RequestContext(request) ) objReturn = {"feed": mark_safe(feed.content), "ttags": mark_safe(ttags.content)} jsonReturn = simplejson.dumps(objReturn) thereturn = render_to_response( "ajax_ttag_create.html", locals(), context_instance=RequestContext(request) ) if "wall_owner_id" in ttagdata and ttagdata["wall_owner_id"] != ttagdata["user_id"]: # send notification email to the wall owner from webapp.views.email import notifyOfWallPost notifyOfWallPost(request, ttagdata["wall_owner_id"], ttagdata["user_id"]) else: if len(request.POST["Comment"]): thereturn = HttpResponse(str(form.errors)) else: import urllib thereturn = HttpResponseRedirect( paths.HTTPS + request.get_host() + "/spraycan/url/?location=" + urlquote_plus(request.POST["location"]) ) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def search(request): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: if 'search' in request.POST: atusername = '' emailform = SpraycanSearchEmail(request.POST) usernameform = SpraycanSearchUsername(request.POST) if emailform.is_valid(): resp = ttagPost('/validate/request-username-by-email', {'email': emailform.getSpraycan_Search()}) if resp['result'] == 'OK' and resp['find_by_email']: atusername = resp['user_name'] elif usernameform.is_valid(): resp = ttagRequestUserProfile( usernameform.getSpraycan_Search()[1:]) if resp['result'] == 'OK': atusername = resp['data']['user_name'] if atusername != '': # from django.core.urlresolvers import reverse # return render_to_response("javascript_redirect.html", {"redirect_url" : reverse('user-profile', kwargs={'user_name':atusername,'view_type':'','page':'','time':''}),'hidespraycan':'true'}) from webapp.views.user import userWallView return userWallView(request, atusername) form = SpraycanSearch(request.POST) if form.is_valid(): urlform = SpraycanSearchURL(request.POST) if urlform.is_valid(): #show spraycan for URL thereturn = url(request, urlform.getSpraycan_Search()) else: #show search results import datetime from webapp.views.user import getUserFollowers location_type = 'search' loggedin_user = data['_id'] filter = request.POST.get('filter', "All") ttags = ttagPost( '/find/url-keyword-hashtag', { 'query': form.getSpraycan_Search(), 'items_per_page': '100', 'page_number': '0' }) response = { 'time': ttags['time'], 'data': { 'founder': {}, 'favorite': False, 'ttags': [] if filter not in ['All', 'Tags'] or ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else ttags['data']['ttags'], 'users': [] if filter not in ['All', 'Users'] or ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else ttags['data']['users'], 'hashtags': [] if filter not in ['All', 'HashTags'] or ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else ttags['data']['hashtags'], 'location': [] if filter not in ['All', 'Locations'] or ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else ttags['data']['location'], 'hubs': [] if filter not in ['All', 'Hubs'] or ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else ttags['data']['hubs'], 'spams': [], 'thumbups': [] } } from webapp.models.hub import processRawHubs response['data']['hubs'] = processRawHubs( response['data']['hubs'], request) response['data']['followers'] = getUserFollowers( loggedin_user) from webapp.views.user import getUserHubs response['data']['joinedhubs'] = getUserHubs( data['user_name']) response['data']['searchcounts'] = { 'ttags': 0 if ttags['data'] == None or 'ttags' not in ttags['data'] or ttags['data']['ttags'] == None else len( ttags['data']['ttags']), 'users': 0 if ttags['data'] == None or 'users' not in ttags['data'] or ttags['data']['users'] == None else len( ttags['data']['users']), 'hashtags': 0 if ttags['data'] == None or 'hashtags' not in ttags['data'] or ttags['data']['hashtags'] == None else len( ttags['data']['hashtags']), 'location': 0 if ttags['data'] == None or 'location' not in ttags['data'] or ttags['data']['location'] == None else len( ttags['data']['location']), 'hubs': 0 if ttags['data'] == None or 'hubs' not in ttags['data'] or ttags['data']['hubs'] == None else len( ttags['data']['hubs']) } servertime = datetime.datetime.fromtimestamp( int(ttags['time']) / 1000) if request.is_ajax(): thetemplate = 'base_ajax.html' thereturn = render_to_response( "spraycan.html", locals(), context_instance=RequestContext(request)) if request.is_ajax(): usercontext = mark_safe( render_to_response('partial_user_details.html', locals(), context_instance=RequestContext( request)).content) import simplejson jsonReturn = simplejson.dumps({ 'context': usercontext, 'results': mark_safe(thereturn.content) }) thereturn = HttpResponse(mark_safe(jsonReturn)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def image(request, isAndroid=False): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: if request.method == "GET": ttagimage = TtagImage() thereturn = render_to_response( "mce_image_uploadform.html", locals(), context_instance=RequestContext(request) ) else: import urllib post = {} files = {} for key in request.POST: post[key] = request.POST[key] post["image_url"] = urllib.unquote_plus(post.get("image_url", "")) if "background_upload" in request.FILES: files = request.FILES if "image_data" in post and len(post["image_data"]) > 0: from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.base import ContentFile import base64 files["background_upload"] = SimpleUploadedFile( post["image_filename"], base64.b64decode(mark_safe(post["image_data"])), "image/gif" ) upload = UploadBackgroundForm({}, files) if len(str(post.get("image_url", ""))) == 0 and upload.is_valid(): from webapp.genUtil import handleUploadedAvatar from website.settings import MEDIA_URL post["image_url"] = "".join( [ MEDIA_URL, handleUploadedAvatar( files["background_upload"], data["user_name"], request.COOKIES["access_token"], "", False, ), ] ) ttagimage = TtagImage(post, files) if ttagimage.is_valid(): import simplejson preview = mark_safe( simplejson.dumps( { "result": "OK", "data": { "html_data": { "thumbnail_list": [ttagimage.clean_ImageURL()], "title": ttagimage.clean_MetaTitle(), "m_title": ttagimage.clean_MetaTitle(), "m_desc": ttagimage.clean_MetaDesc(), } }, } ) ) if isAndroid: thereturn = HttpResponse(preview) else: # thereturn = HttpResponse(mark_safe('<img src="'+mark_safe(post['image_url'])+'" />')) thereturn = render_to_response( "mce_image_uploadhandle.html", locals(), context_instance=RequestContext(request) ) else: thereturn = render_to_response( "mce_image_uploadform.html", locals(), context_instance=RequestContext(request) ) thereturn = thereturn return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def settingsChangePost(request): try : form = SettingsForm() loggedin, data = ttagServiceAuth(request) checkUser = False if (request.method == "POST"): form = SettingsForm(request.POST) if loggedin : aToken = request.COOKIES['access_token'] else : aToken = '' return loginscreen(request) if form.is_valid() and data['user_name'] != form.getUser_Name() : checkUser = ttagRequestUserProfile(form.getUser_Name()) if checkUser['result'] == 'OK' : form._errors['user_name'] = form.error_class([u"Sorry, that username already exists"]) if form.is_valid(): serviceResponse = ttagServiceAccountChange(aToken, full_name = form.getFull_Name(), find_by_email = 'true' if 'find_by_email' in request.POST else 'false', location = form.getLocation(), site_link = form.getWebsite(), self_description = form.getBio(), country = form.getCountry(), time_zone = form.getTime_Zone(), email_on_new_follower = 'true' if 'email_on_new_follower' in request.POST else 'false', email_on_reply = 'true' if 'email_on_reply' in request.POST else 'false', email_on_followed_ttag = 'true' if 'email_on_followed_ttag' in request.POST else 'false', gender = form.getGender(), google_map_address = form.getGoogleMap_Address(), pro_description = form.getPro_Description(), ) json_obj = simplejson.loads(serviceResponse.read()) if checkUser != False : updateUsername = ttagPost('/user/update-username',{'new_username': form.getUser_Name(),'access_token':aToken}) if updateUsername['result'] == 'OK' : data['user_name'] = form.getUser_Name() if json_obj['result'] == 'OK': settings_message = mark_safe('Account settings changed.') if data['email'] != form.getEmail() : emailresp = ttagPost('/user/update-email',{'access_token':aToken,'new_email':form.getEmail()}) if emailresp['result'] != 'OK' : settings_message = mark_safe('Email not updated: '+emailresp['msg']) else: settings_message = mark_safe("Account settings not changed! "+json_obj['msg']) ## Check if password change request should be sent if len(form.getNew_Password()) > 0 and len(form.getCurrent_Password()) > 0 : pwdResponse = ttagServicePasswordChange(aToken, form.getCurrent_Password(), form.getNew_Password() ) resp = pwdResponse.read() jsonPwdResp = simplejson.loads(resp) if jsonPwdResp['result'] == 'OK': settings_message += mark_safe('<br />Password changed.') elif jsonPwdResp['msg'] == 'Incorrect old password. Change password failed' : form._errors['current_password'] = form.error_class([u"Current Password was incorrect"]) else: settings_message += mark_safe('<br />Password not changed') return render_to_response('home_settings.html', locals(), context_instance=RequestContext(request)) except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def ttagReply(request, ttag_id): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: ttagdata = ttagPost( '/ttag/get', { 'access_token': request.COOKIES['access_token'], 'user_id': data['_id'], 'ttag_id': ttag_id, 'search_on': 'ttag' }) if 'result' in ttagdata and ttagdata['result'] == 'OK': ttag = ttagdata['data']['ttag'] if 'Comment' in request.POST: form = TtagReply(request.POST) if form.is_valid(): import re, urllib hashtags = ''.join( re.findall(r"\#\w+", request.POST['Comment'])) root_id = ttag_id if ttag['root_id'] == '0' else ttag[ 'root_id'] ttagdata = { 'access_token': request.COOKIES['access_token'], 'user_id': data['_id'], 'parent_user_id': form.getTtag_ParentUser(), 'location': ttag['location'], 'location_type': ttag['location_type'], 'ttag_content': form.getTtag_Comment(), 'root_id': root_id, 'parent_id': ttag_id, 'title': ttag['title'], 'hashtags': hashtags, 'meta_url': urlquote_plus(form.getTtag_metaurl()), 'meta_thumbnail': urlquote_plus(form.getTtag_metathumbnail()), 'meta_title': urlquote_plus(form.getTtag_metatitle()), 'meta_desc': urlquote_plus(form.getTtag_metadesc()), 'wall_owner_id': ttag.get('wall_owner_id', "") } request.is_wallowner = ( ttag['wall_owner_id'] == data['_id']) reply = ttagPost("/ttag/create", ttagdata) if reply['result'] == 'OK': from webapp.views.email import notifyOfReply # send reply notification notifyOfReply(request, ttagdata["parent_user_id"], ttagdata["user_id"], ttagdata["parent_id"], reply['data']['ttag']['_id']) # return template if not request.is_ajax(): thereturn = HttpResponseRedirect( request.POST['location']) else: thereturn = ttagShowOriginal( request, reply['data']['ttag']['_id'], ttag_id) else: thereturn = HttpResponse(reply['msg']) else: thereturn = HttpResponse(str(form.errors)) else: context = { 'request': request, 'data': data, 'loggedin': loggedin, 'pagetitle': 'ttagit - Ttag Reply Form', 'reply_id': ttag_id, 'ttag': ttagdata['data']['ttag'], 'servertime': datetime.datetime.fromtimestamp( int(ttagdata['time']) / 1000) } thereturn = render_to_response( 'ttag_reply.html', context, context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def image(request, isAndroid=False): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: if request.method == 'GET': ttagimage = TtagImage() thereturn = render_to_response( 'mce_image_uploadform.html', locals(), context_instance=RequestContext(request)) else: import urllib post = {} files = {} for key in request.POST: post[key] = request.POST[key] post['image_url'] = urllib.unquote_plus( post.get('image_url', "")) if 'background_upload' in request.FILES: files = request.FILES if 'image_data' in post and len(post['image_data']) > 0: from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.base import ContentFile import base64 files['background_upload'] = SimpleUploadedFile( post['image_filename'], base64.b64decode(mark_safe(post['image_data'])), 'image/gif') upload = UploadBackgroundForm({}, files) if len(str(post.get('image_url', ""))) == 0 and upload.is_valid(): from webapp.genUtil import handleUploadedAvatar from website.settings import MEDIA_URL post['image_url'] = ''.join([ MEDIA_URL, handleUploadedAvatar(files['background_upload'], data['user_name'], request.COOKIES['access_token'], '', False) ]) ttagimage = TtagImage(post, files) if ttagimage.is_valid(): import simplejson preview = mark_safe( simplejson.dumps({ 'result': 'OK', 'data': { 'html_data': { 'thumbnail_list': [ttagimage.clean_ImageURL()], 'title': ttagimage.clean_MetaTitle(), 'm_title': ttagimage.clean_MetaTitle(), 'm_desc': ttagimage.clean_MetaDesc() } } })) if isAndroid: thereturn = HttpResponse(preview) else: #thereturn = HttpResponse(mark_safe('<img src="'+mark_safe(post['image_url'])+'" />')) thereturn = render_to_response( 'mce_image_uploadhandle.html', locals(), context_instance=RequestContext(request)) else: thereturn = render_to_response( 'mce_image_uploadform.html', locals(), context_instance=RequestContext(request)) thereturn = thereturn return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def ttagCreate(request): try: thereturn = loginscreen(request) authed, user = ttagServiceAuth(request) if authed: if 'Comment' in request.POST: form = TtagPost(request.POST) print[ form.is_valid(), len(str(request.POST['Comment'])), len(request.POST.get('meta_thumbnail', "")) ] print form.errors if form.is_valid() and ( len(str(request.POST['Comment'])) or len(request.POST.get('meta_thumbnail', ""))): import re, urllib location_type = 'URL' if ( 'location_type' not in request.POST or request.POST['location_type'] not in ['wall', 'HUB'] ) else request.POST['location_type'] remotetitle = "" if location_type == 'URL': getTitle = ttagPost( '/find/get-title', { 'location': form.getTtag_Location(), 'location_type': 'URL' }) try: remotetitle = getTitle['data']['location_data'][ 'title'] except: import urllib2 import socket timeout = 3 socket.setdefaulttimeout(timeout) try: req = urllib2.Request(form.getTtag_Location()) remotecontent = urllib2.urlopen(req).read() except: remotecontent = mark_safe('<title></title>') #remotetitle = re.search(r"<title>(.*?)</title>", remotecontent).group(1) title_dict = get_title(remotecontent, request) if title_dict['status'] == 'OK': remotetitle = title_dict['msg'] elif title_dict['status'] == 'ERROR': remotetitle = "" elif location_type == 'wall': if 'wall_owner_id' in request.POST: wallOwner = ttagServiceByUserID( form.clean_Ttag_WallOwnerID()) if wallOwner['result'] == "OK": remotetitle = wallOwner['data']['user'][ 'full_name'] + "'s Wall" hashtags = ''.join( re.findall(r"\#\w+", request.POST['Comment'])) root_id = '0' ttag_id = '0' ttagdata = { 'access_token': request.COOKIES['access_token'], 'user_id': user['_id'], 'location': form.getTtag_Location(), 'location_type': location_type, 'ttag_content': form.getTtag_Comment(), 'root_id': root_id, 'parent_id': ttag_id, 'title': remotetitle.strip(), 'hashtags': hashtags, 'meta_url': urlquote_plus(form.getTtag_metaurl()), 'meta_thumbnail': urlquote_plus(form.getTtag_metathumbnail()), 'meta_title': urlquote_plus(form.getTtag_metatitle()), 'meta_desc': urlquote_plus(form.getTtag_metadesc()) } if 'wall_owner_id' in request.POST: ttagdata[ 'wall_owner_id'] = form.clean_Ttag_WallOwnerID() request.is_wallowner = ( form.clean_Ttag_WallOwnerID() == user['_id']) create = ttagPost("/ttag/create", ttagdata) if create['result'] == 'OK': if not request.is_ajax(): import urllib thereturn = HttpResponseRedirect( paths.HTTPS + request.get_host() + '/spraycan/url/?location=' + urlquote_plus(request.POST['location'])) elif 'position' in request.POST and request.POST[ 'position'] == 'minispraycan': thereturn = render_to_response( 'partial_user_minispraycansuccess.html', locals()) else: location = form.getTtag_Location() from webapp.views import spraycan ttags = spraycan.url( request, location, request.POST['start_time'], 'partial_spraycan_ttags.html', False, None, None, location_type) response = {'time': request.session['start_time']} feed = render_to_response( 'partial_spraycan_feed.html', locals(), context_instance=RequestContext(request)) objReturn = { 'feed': mark_safe(feed.content), 'ttags': mark_safe(ttags.content) } jsonReturn = simplejson.dumps(objReturn) thereturn = render_to_response( 'ajax_ttag_create.html', locals(), context_instance=RequestContext(request)) if "wall_owner_id" in ttagdata and ttagdata[ "wall_owner_id"] != ttagdata["user_id"]: # send notification email to the wall owner from webapp.views.email import notifyOfWallPost notifyOfWallPost(request, ttagdata["wall_owner_id"], ttagdata["user_id"]) else: if len(request.POST['Comment']): thereturn = HttpResponse(str(form.errors)) else: import urllib thereturn = HttpResponseRedirect( paths.HTTPS + request.get_host() + '/spraycan/url/?location=' + urlquote_plus(request.POST['location'])) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
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)
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)