def remove_song(request,pk): if request.user.username in settings.STAFFS: song = Song.objects.get(pk=pk) song.activate = False song.save() return HttpResponse(utils._build_json(dict(result=True)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def add_song(request): if request.user.username in settings.STAFFS: if request.method == 'POST': data = request.POST youtube_url = data.get('link') if (youtube_url.find('www.youtube.com/watch?v=') >= 0): start = youtube_url.find('v=') + 2 end = youtube_url.find('&', start - 2) code = youtube_url[start:] if end < 0 else youtube_url[ start:end] # fetch youtube feed json data json_string = urllib.urlopen( 'http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=json' % code).read() json = utils._parse_json(json_string) s = Song(sid=code, owner=request.user, title=json['entry']['title']['$t'], activate=True) s.save() return HttpResponse(utils._build_json( dict(result=True, title=json['entry']['title']['$t'])), mimetype='application/javascript') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def list_message(request): # args={} # res = facebook.GraphAPI(RR_TOKEN).request('me/home',args) # messages = [] # for message in res['data']: # messages.append(dict( # id=message['id'], # uid=message['from']['id'], # name=message['from']['name'], # message='' if not 'message' in message else message['message'], # date=message['created_time'], # primary=True # )) # return HttpResponse(utils._build_json(dict(messages=messages,count=len(res['data']))),mimetype='application/json') if request.user.username in settings.STAFFS: messageInstances = Message.objects.filter(activate=True) messages = [] for messageInstance in messageInstances: messages.append( dict(id=messageInstance.pk, uid=messageInstance.owner.username, name=str(messageInstance.owner.profile), message=messageInstance.detail, date=messageInstance.date_added.strftime( "%b %d, %Y - %H:%M:%S"), primary=True if request.user.username == messageInstance.owner.username else False)) return HttpResponse(utils._build_json( dict(messages=messages, count=len(messageInstances))), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def list_message(request): # args={} # res = facebook.GraphAPI(RR_TOKEN).request('me/home',args) # messages = [] # for message in res['data']: # messages.append(dict( # id=message['id'], # uid=message['from']['id'], # name=message['from']['name'], # message='' if not 'message' in message else message['message'], # date=message['created_time'], # primary=True # )) # return HttpResponse(utils._build_json(dict(messages=messages,count=len(res['data']))),mimetype='application/json') if request.user.username in settings.STAFFS: messageInstances = Message.objects.filter(activate=True) messages = [] for messageInstance in messageInstances: messages.append(dict( id=messageInstance.pk, uid=messageInstance.owner.username, name=str(messageInstance.owner.profile), message=messageInstance.detail, date=messageInstance.date_added.strftime("%b %d, %Y - %H:%M:%S"), primary=True if request.user.username==messageInstance.owner.username else False ) ) return HttpResponse(utils._build_json(dict(messages=messages,count=len(messageInstances))),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def get_playlist(request): if request.user.username in settings.STAFFS: songs = Song.objects.filter(activate=True) playlist = [] for song in songs: playlist.append(dict(name=str(song.owner.profile),uid=song.owner.username,id=song.pk,sid=song.sid,title=song.title,date=song.date_added.strftime("%b %d, %Y"))) return HttpResponse(utils._build_json(dict(result=True,playlist=playlist)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def remove_message(request,pk): if request.user.username in settings.STAFFS: messageInstance = Message.objects.get(pk=pk) messageInstance.date_updated=datetime.datetime.now() messageInstance.activate=False messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def remove_song(request, pk): if request.user.username in settings.STAFFS: song = Song.objects.get(pk=pk) song.activate = False song.save() return HttpResponse(utils._build_json(dict(result=True)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def remove_message(request, pk): if request.user.username in settings.STAFFS: messageInstance = Message.objects.get(pk=pk) messageInstance.date_updated = datetime.datetime.now() messageInstance.activate = False messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def add_message(request): if request.user.username in settings.STAFFS: if request.method == 'POST': user = request.user data = request.POST message = data.get('message') if message=='Add your message here...': return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json') messageInstance = Message(owner=user,detail=message,activate=True) messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def edit_message(request): if request.user.username in settings.STAFFS: if request.method == 'POST': user = request.user data = request.POST pk = data.get('id') message = data.get('message') messageInstance = Message.objects.get(pk=pk) messageInstance.detail = message messageInstance.date_updated = datetime.datetime.now() messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def edit_message(request): if request.user.username in settings.STAFFS: if request.method == 'POST': user = request.user data = request.POST pk = data.get('id') message = data.get('message') messageInstance = Message.objects.get(pk=pk) messageInstance.detail = message messageInstance.date_updated = datetime.datetime.now() messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def get_photos(request, page=1, limit=25, person=0): if request.user.username in settings.STAFFS: albums = Album.objects.all() pictures = [] sources = [] if len(albums) >= int(page) & int(page)>0: args = {'limit': 200} album = albums[int(page)-1] photos = facebook.GraphAPI(album.owner.profile.access_token).request(str(album)+'/photos',args) for photo in photos['data']: pictures.append(photo['picture']) sources.append(photo['source']) res = dict(pictures=pictures,sources=sources,page=page,limit=limit,albums=len(albums)) else: args = { 'offset': (int(page)-len(albums)-1)*int(limit), 'limit': limit, } i = 0 for staff in settings.STAFFS: photos = facebook.GraphAPI(request.user.profile.access_token).request(staff+'/photos',args) i=i+1 index = 0 for photo in photos['data']: for tag in photo['tags']['data']: banned = True if tag['id'] in settings.BANNED else False if not banned: pictures.insert(index,photo['picture']) sources.insert(index,photo['source']) index = index+i # person_index = person_index+1 if person_index+1<len(settings.STAFFS) else 0 res = dict(pictures=pictures,sources=sources,page=page,limit=limit,albums=len(albums)) return HttpResponse(utils._build_json(res),mimetype='application/json')
def add_message(request): if request.user.username in settings.STAFFS: if request.method == 'POST': user = request.user data = request.POST message = data.get('message') if message == 'Add your message here...': return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json') messageInstance = Message(owner=user, detail=message, activate=True) messageInstance.save() return HttpResponse(utils._build_json(dict(result=True)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def get_playlist(request): if request.user.username in settings.STAFFS: songs = Song.objects.filter(activate=True) playlist = [] for song in songs: playlist.append( dict(name=str(song.owner.profile), uid=song.owner.username, id=song.pk, sid=song.sid, title=song.title, date=song.date_added.strftime("%b %d, %Y"))) return HttpResponse(utils._build_json( dict(result=True, playlist=playlist)), mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)), mimetype='application/json')
def add_song(request): if request.user.username in settings.STAFFS: if request.method == 'POST': data = request.POST youtube_url = data.get('link') if(youtube_url.find('www.youtube.com/watch?v=')>=0): start = youtube_url.find('v=') + 2 end = youtube_url.find('&',start-2) code = youtube_url[start:] if end<0 else youtube_url[start:end] # fetch youtube feed json data json_string = urllib.urlopen('http://gdata.youtube.com/feeds/api/videos/%s?v=2&alt=json' % code).read() json = utils._parse_json(json_string) s = Song(sid=code,owner=request.user,title=json['entry']['title']['$t'],activate=True) s.save() return HttpResponse(utils._build_json(dict(result=True,title=json['entry']['title']['$t'])),mimetype='application/javascript') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json') return HttpResponse(utils._build_json(dict(result=False)),mimetype='application/json')
def get_photos(request, page=1, limit=25, person=0): if request.user.username in settings.STAFFS: albums = Album.objects.all() pictures = [] sources = [] if len(albums) >= int(page) & int(page) > 0: args = {'limit': 200} album = albums[int(page) - 1] photos = facebook.GraphAPI( album.owner.profile.access_token).request( str(album) + '/photos', args) for photo in photos['data']: pictures.append(photo['picture']) sources.append(photo['source']) res = dict(pictures=pictures, sources=sources, page=page, limit=limit, albums=len(albums)) else: args = { 'offset': (int(page) - len(albums) - 1) * int(limit), 'limit': limit, } i = 0 for staff in settings.STAFFS: photos = facebook.GraphAPI( request.user.profile.access_token).request( staff + '/photos', args) i = i + 1 index = 0 for photo in photos['data']: for tag in photo['tags']['data']: banned = True if tag['id'] in settings.BANNED else False if not banned: pictures.insert(index, photo['picture']) sources.insert(index, photo['source']) index = index + i # person_index = person_index+1 if person_index+1<len(settings.STAFFS) else 0 res = dict(pictures=pictures, sources=sources, page=page, limit=limit, albums=len(albums)) return HttpResponse(utils._build_json(res), mimetype='application/json')
def add_album(request,aid): if request.user.username in settings.STAFFS: album = Album(owner=request.user,aid=aid) album.save(); return HttpResponse(utils._build_json(dict(result=True)),mimetype='application/json')
def add_album(request, aid): if request.user.username in settings.STAFFS: album = Album(owner=request.user, aid=aid) album.save() return HttpResponse(utils._build_json(dict(result=True)), mimetype='application/json')