def deleteStatus(request): response = dict() userid = request.REQUEST['userid'] statusid = request.REQUEST['statusid'] try: userProfile = UserProfile.getUser(userid) cacheKey = Status.getCacheKey(statusid) status = cache.get(cacheKey) if status is None: status = Status.getStatus(statusid) except UserProfile.DoesNotExist: return errorResponse("Invalid user id") except Status.DoesNotExist: return errorResponse("Invalid statusid") if status.user == userProfile: status.deleted = True status.save() response['success'] = True createDeleteStatusNotification(status) sendDeleteStatusNotfication(status) else: response['success'] = False response['error'] = "Can not delete another user's status" return HttpResponse(json.dumps(response))
def suggestLocationTime(request): response = dict() userid = request.REQUEST['userid'] statusid = request.REQUEST['statusid'] suggestionType = request.REQUEST['type'] location = request.REQUEST.get('location', None) time = request.REQUEST.get('time', None) if suggestionType != 'location' or suggestionType != 'time': return errorResponse('type must be location or time') try: userProfile = UserProfile.getUser(userid) except UserProfile.DoesNotExist: return errorResponse('Invalid User') try: cacheKey = Status.getCacheKey(statusid) status = Status.getStatus(statusid) except Status.DoesNotExist: return errorResponse('Invalid status id') if suggestionType == 'location': location = getLocationObjectFromJson(json.loads(location)) locationSuggestion = LocationSuggestion.objects.get_or_create(user=userProfile, status=status, location=location) if suggestionType == 'time': date = datetime.strptime(time, DATETIME_FORMAT) timeSuggestion = TimeSuggestion.objects.get_or_create(user=userProfile, status=status, dateSuggested=time) response['success'] = True return HttpResponse(json.dumps(response))
def cancelStatus(request): response = dict() userid = request.REQUEST['userid'] statusid = request.REQUEST['statusid'] try: userProfile = UserProfile.getUser(userid) cacheKey = Status.getCacheKey(statusid) status = cache.get(cacheKey) if status is None: status = Status.getStatus(statusid) except UserProfile.DoesNotExist: return errorResponse("Invalid user id") except Status.DoesNotExist: return errorResponse("Invalid statusid") if status.user != userProfile: return errorResponse("User does not own this status") now = datetime.utcnow() if status.expires > now: status.expires = now status.save() response['success'] = True return HttpResponse(json.dumps(response))
def create_test_status(): user = create_test_user('1') user_profile = get_users_profile(user.id) status = Status( user = user, user_profile = user_profile, title = 'Test Status', content = 'Testing test!', ) status.save() return status
def profile(request): """ This function is used to query the data for a user that already logged in to show them to the profile page. """ # p = request.user # id_to_exclude = [i.id for i in request.user.friends.id] other_users = SiteUser.objects.exclude(id=request.user.id) friends = request.user.friends.all() frequest = FriendRequest.objects.all() statuses = Status.objects.filter(owner_id=request.user.id) status_list = [] for status in statuses: status_list.append(status) if request.method == 'POST': status_form = StatusCreationForm(request.POST) if status_form.is_valid(): cleaned_data = status_form.cleaned_data new_status = Status(content=cleaned_data.get('content'), owner=request.user) new_status.save() messages.success(request, 'Status has been created') return redirect('profile') else: status_form = StatusCreationForm() sent_friend_requests = FriendRequest.objects.filter(from_user=request.user) received_friend_requests = FriendRequest.objects.filter( to_user=request.user) sent_to_ids = [] for friend_request in sent_friend_requests: sent_to_ids.append(friend_request.get_to_user_id()) received_from_ids = [] for friend_request in received_friend_requests: received_from_ids.append(friend_request.get_from_user_id()) context = { 'other_users': other_users, 'friends': friends, 'frequest': frequest, 'sent_to_ids': sent_to_ids, 'received_from_ids': received_from_ids, 'statuses': status_list, 'status_form': status_form, } return render(request, 'users/profile.html', context)
def create_objects(self): self.object.save() self.object.projectstatus_set.create( status=Status.get_default_status()) self.object.projectuser_set.create( user=self.request.user, permission=ProjectPermission.founder_permission())
def getStatusDetails(request): response = dict() statusid = request.REQUEST['statusid'] lastmessageid = request.REQUEST.get('lastmessageid', None) try: status = Status.getStatus(statusid) except Status.DoesNotExist: return errorResponse("Invalid status") messagesJson = getNewStatusMessages(status, lastmessageid) locationSuggestions = list() for locationSugg in status.locationSuggestions.all(): locationSuggestions.append(createLocationSuggestionJson(locationSugg)) timeSuggestions = list() for timeSugg in status.timeSuggestions.all(): timeSuggestions.append(createTimeSuggestionJson(timeSugg)) response['success'] = True response['messages'] = messagesJson attending, invited, userDetails = createAttendingAndInvitedAndUserDetailsJsonResponse(status) response['attending'] = attending response['invited'] = invited response['users'] = userDetails response['locationsuggestions'] = locationSuggestions response['timesuggestions'] = timeSuggestions response['deleted'] = status.deleted response.update(createStatusJsonObject(status)) return HttpResponse(json.dumps(response))
def sendStatusMessage(request): response = dict() text = request.REQUEST['text'] userid = request.REQUEST['userid'] statusid = request.REQUEST['statusid'] lastMessageId = request.REQUEST.get('lastmessageid', None) try: userProfile = UserProfile.getUser(userid) except UserProfile.DoesNotExist: return errorResponse('Invalid User') try: status = Status.getStatus(statusid) except Status.DoesNotExist: return errorResponse('Invalid status id') message = StatusMessage.objects.create(user=userProfile, text=text, status=status) sendStatusMessageNotification(message) createCreateStatusMessageNotification(message) response['success'] = True response['messages'] = getNewStatusMessages(status, lastMessageId) return HttpResponse(json.dumps(response))
def rsvpStatus(request): response = dict() userId = request.REQUEST['userid'] statusId = request.REQUEST['statusid'] attending = request.REQUEST['attending'] try: userProfile = UserProfile.getUser(userId) except UserProfile.DoesNotExist: return errorResponse('Invalid User') try: status = Status.getStatus(statusId) except Status.DoesNotExist: return errorResponse('Invalid Status') if attending == 'true' or attending == 'True': status.attending.add(userProfile) createAttendingStatusNotification(status, userProfile) sendAttendingStatusPushNotification(status, userProfile) elif attending == 'false' or attending == 'False': status.attending.remove(userProfile) else: return errorResponse("Invalid Attending value. Must be true or false") response['success'] = True return HttpResponse(json.dumps(response))
def inviteToStatus(request): response = dict() userid = request.REQUEST['userid'] statusId = request.REQUEST['statusid'] friends = request.REQUEST.get('friends', '[]') friends = json.loads(friends) try: userProfile = UserProfile.getUser(userid) except UserProfile.DoesNotExist: return errorResponse('Invalid User') try: status = Status.getStatus(statusId) except Status.DoesNotExist: return errorResponse('Invalid Status') # if status.user != userProfile: # if status.visibility == Status.VIS_FRIENDS or status.visibility == Status.VIS_CUSTOM: # return errorResponse("Cant invite people to private events") buddyupFriends = list() facebookFriends = list() for friendId in friends: friendId = str(friendId) if friendId[:2] == 'fb': friendId = friendId[2:] try: friend = UserProfile.objects.get(facebookUID=friendId) if friend != status.user and friend not in status.attending.all(): buddyupFriends.append(friend) except UserProfile.DoesNotExist: try: fbFriend = FacebookUser.objects.get(facebookUID=friendId) except FacebookUser.DoesNotExist: fbFriend = FacebookUser.objects.create(facebookUID=friendId) facebookFriends.append(fbFriend) else: try: friend = UserProfile.getUser(friendId) if friend != status.user and friend not in status.attending.all(): buddyupFriends.append(friend) except UserProfile.DoesNotExist: pass status.invited.add(*buddyupFriends) status.fbInvited.add(*facebookFriends) createInvitedToStatusNotification(buddyupFriends, userProfile, status) sendInvitedToStatusNotification(status, userProfile, buddyupFriends) response['success'] = True return HttpResponse(json.dumps(response))
def submit(request): if request.method == "POST": form = submitForm(request.POST) if form.is_valid(): t = form.cleaned_data['team_id'] p = form.cleaned_data['pid'] print t s = Status(team_id=t, pid=p) s.save() return HttpResponseRedirect('/status/') else: form = submitForm() return render(request, 'submit.html', {'form': form})
def add_order_statuses(): with open('data/statuses.json') as json_file: items = json.load(json_file) objects = [Status(**item).create() for item in items] click.echo("Finished adding statuses") return objects
def create_objects(self): self.object.save() self.object.projectstatus_set.create( status = Status.get_defult_status() ) self.object.projectuser_set.create(user= self.request.user, permission_id = 1 )
def create_objects(self): self.object.save() self.object.projectstatus_set.create(status = Status.dafault_value() ) self.object.projectuser_set.create(user = self.request.user, permission_id = EPermission.maker )
def data_saver(): delta = datetime.timedelta(days=1) time = datetime.datetime.utcnow() - delta data = Status() data.user_count = User.objects.using('boobsdb').count() data.new_user_count = User.objects.filter( created_at__gt=time).using('boobsdb').count() data.view_count = Show.objects.using('boobsdb').count() data.new_view_count = Show.objects.filter( created_at__gt=time).using('boobsdb').count() data.image_count = Img.objects.using('boobsdb').count() data.new_image_count = Img.objects.filter( created_at__gt=time).using('boobsdb').count() data.like_count = Show.objects.filter(rating=1).using('boobsdb').count() data.new_like_count = Show.objects.filter(rating=1).filter( rated_at__gt=time).using('boobsdb').count() data.dislike_count = Show.objects.filter( rating=-1).using('boobsdb').count() data.new_dislike_count = Show.objects.filter(rating=-1).filter( rated_at__gt=time).using('boobsdb').count() data.report_count = Show.objects.filter( reported_at__isnull=False).using('boobsdb').count() data.new_report_count = Show.objects.filter( reported_at__isnull=False).filter( reported_at__gt=time).using('boobsdb').count() data.inline_query_count = Inlinequery.objects.using('boobsdb').count() data.new_inline_query_count = Inlinequery.objects.filter( created_at__gt=time).using('boobsdb').count() data.save_data()
def data_to_table(): lines = DataFromAvtomat.objects.filter(flag=False) for line in lines: string_from_avtomat = line.line time = line.time if len(string_from_avtomat) == 38: data = parsing_line38(string_from_avtomat) if data == 'error': continue elif len(string_from_avtomat) == 48: data = parsing_line48(string_from_avtomat) if data == 'error': continue try: avtomat = Avtomat.objects.get(number=data['number']) except Avtomat.DoesNotExist: avtomat = Avtomat(number=data['number']) avtomat.save() try: status = Status.objects.get(avtomat=avtomat) except Status.DoesNotExist: status = Status(avtomat=avtomat, time=time) if len(string_from_avtomat) == 48 and status.grn == data['grn']: status.ev_bill_time += int( (time - status.time).total_seconds() / 60) else: status.ev_bill_time = 0 if len(string_from_avtomat) == 48 and status.kop == data['kop']: status.ev_coin_time += int( (time - status.time).total_seconds() / 60) else: status.ev_coin_time = 0 status.time = time status.how_money = data['how_money'] status.water_balance = data['water_balance'] status.water_price = data['water_price'] status.ev_water = data['ev_water'] status.ev_bill = data['ev_bill'] status.ev_volt = data['ev_volt'] status.ev_counter_water = data['ev_counter_water'] status.event = data['event'] status.ev_register = data['ev_register'] status.grn = data['grn'] status.kop = data['kop'] status.time_to_block = data['time_to_block'] status.save() Statistic(avtomat=avtomat, time=time, water_balance=data['water_balance'], how_money=data['how_money'], water_price=data['water_price'], ev_water=data['ev_water'], ev_bill=data['ev_bill'], ev_volt=data['ev_volt'], ev_counter_water=data['ev_counter_water'], ev_register=data['ev_register'], grn=data['grn'], kop=data['kop'], event=data['event']).save(force_insert=True) if data['event'] == 3: Collection(avtomat=avtomat, how_money=data['how_money'], time=time, time_in_message=data['time_in_message']).save( force_insert=True) line.delete()
def data_to_table(): lines = DataFromAvtomat.objects.filter(flag=False) for line in lines: string_from_avtomat = line.line time = line.time if len(string_from_avtomat) == 38: data = parsing_line38(string_from_avtomat) if data == 'error': continue elif len(string_from_avtomat) == 48: data = parsing_line48(string_from_avtomat) if data == 'error': continue try: avtomat = Avtomat.objects.get(number=data['number']) except Avtomat.DoesNotExist: avtomat = Avtomat(number=data['number']) avtomat.save() try: status = Status.objects.get(avtomat=avtomat) except Status.DoesNotExist: status = Status(avtomat=avtomat, time=time) if len(string_from_avtomat) == 48 and status.grn == data['grn']: status.ev_bill_time += int((time - status.time).total_seconds() / 60) else: status.ev_bill_time = 0 if len(string_from_avtomat) == 48 and status.kop == data['kop']: status.ev_coin_time += int((time - status.time).total_seconds() / 60) else: status.ev_coin_time = 0 status.time = time status.how_money = data['how_money'] status.water_balance = data['water_balance'] status.water_price = data['water_price'] status.ev_water = data['ev_water'] status.ev_bill = data['ev_bill'] status.ev_volt = data['ev_volt'] status.ev_counter_water = data['ev_counter_water'] status.event = data['event'] status.ev_register = data['ev_register'] status.grn = data['grn'] status.kop = data['kop'] status.time_to_block = data['time_to_block'] status.save() Statistic(avtomat=avtomat, time=time, water_balance=data['water_balance'], how_money=data['how_money'], water_price=data['water_price'], ev_water=data['ev_water'], ev_bill=data['ev_bill'], ev_volt=data['ev_volt'], ev_counter_water=data['ev_counter_water'], ev_register=data['ev_register'], grn=data['grn'], kop=data['kop'], event=data['event']).save(force_insert=True) if data['event'] == 3: Collection(avtomat=avtomat, how_money=data['how_money'], time=time, time_in_message=data['time_in_message']).save(force_insert=True) line.delete()
def create_objects(self): self.object.save() self.object.projectstatus_set.create(status = Status.getDefaultStatus()) #crea un status por defaul despues de guardar self.object.projectuser_set.create(user= self.request.user, permission_id = EPermission.maker )
def sample_status(): return Status()
def postStatus(request): response = dict() text = request.REQUEST['text'] userid = request.REQUEST['userid'] groupids = request.REQUEST.get('groupids', '[]') expires = request.REQUEST.get('expires', None) starts = request.REQUEST.get('starts', None) locationData = request.REQUEST.get('location', '{}') statusid = request.REQUEST.get('statusid', 0) accessToken = request.REQUEST.get('accesstoken', None) shareOnFacebook = request.REQUEST.get('facebookshare', False) statusType = request.REQUEST.get('type', 'other') visibility = request.REQUEST.get('visibility', 'friends') visibilityFriends = request.REQUEST.get('visibilityfriends', '[]') imageUrl = request.REQUEST.get('imageurl', None) imageOrientation = request.REQUEST.get('imageorientation', None) groupids = json.loads(groupids) locationData = json.loads(locationData) if starts: starts = datetime.strptime(starts, DATETIME_FORMAT).replace(tzinfo=pytz.utc) else: starts = datetime.utcnow() if expires: expires = datetime.strptime(expires, DATETIME_FORMAT).replace(tzinfo=pytz.utc) else: expires = starts + timedelta(hours=8) try: userprofile = UserProfile.getUser(userid) except UserProfile.DoesNotExist: return errorResponse("User Id not valid") if statusid: try: status = Status.getStatus(statusid) createStatusChangedNotification(status) shouldPostNotification = False except Status.DoesNotExist: return errorResponse('status does not exist with that id') else: status = Status(user=userprofile) shouldPostNotification = True status.expires = expires status.text = text status.starts = starts status.statusType = statusType status.visibility = visibility status.imageOrientation = imageOrientation if imageUrl: status.imageUrl = imageUrl if locationData: location = getLocationObjectFromJson(locationData) status.location = location status.save() status.attending.add(userprofile) if status.visibility == 'custom': visibilityFriends = json.loads(visibilityFriends) for friendId in visibilityFriends: if str(friendId)[:2] == 'fb': friendId = str(friendId)[2:] try: friendProfile = UserProfile.objects.get(facebookUID=friendId) status.friendsVisible.add(friendProfile) except UserProfile.DoesNotExist: try: facebookUser = FacebookUser.objects.get(facebookUID=friendId) except FacebookUser.DoesNotExist: facebookUser = FacebookUser.objects.create(facebookUID=friendId) status.fbFriendsVisible.add(facebookUser) else: try: friendProfile = UserProfile.getUser(friendId) status.friendsVisible.add(friendProfile) except UserProfile.DoesNotExist: pass if groupids: groups = Group.objects.filter(id__in=groupids) status.groups.add(*groups) else: status.groups.clear() status.save() if shareOnFacebook: if accessToken is not None: fbProfile = FacebookProfile(userprofile, accessToken) fbProfile.shareStatus(status, request) if shouldPostNotification: sendFavoritesStatusPushNotification(status) else: sendEditStatusNotification(status) response['success'] = True response['statusid'] = status.id cacheKey = status.getCacheKeyNoneStatic() statusDuration = status.getStatusDuration() cache.set(cacheKey, status, statusDuration) return HttpResponse(json.dumps(response))