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 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 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 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 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 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))