def fill_chats(): info = (('MoneyMakers', True), ('1xbet', True), ('Mom', False)) for title, is_group_chat in info: chat = Chat(title=title, is_group_chat=is_group_chat, icon='C:\\icons') chat.save()
def create_chat(is_group, user_id, second_user_id): chat = Chat(title='aa', is_group_chat=is_group) chat.save() first_member = Member(user=User.objects.get(pk=user_id), chat=chat) second_member = Member(user=User.objects.get(pk=second_user_id), chat=chat) first_member.save() second_member.save()
def landing(request): global idx idx = idx + 1 chat = Chat() chat.save() user = chat.user_set.create(email = 'suleimenov'+str(idx)+'@gmail.com', facebookId = 10100409621467214 + idx) user.save() return render_to_response('landing.html', { 'chat_id':chat.session_id });
def get_or_create_chat(chat_id, chat_type, chat_name): chat = Chat.objects.get_or_none(id=chat_id) if not chat: chat = Chat( id=chat_id, chat_type=chat_type, chat_name=chat_name, ) chat.save() return chat
def create_chat(request): form = CreateChatForm(request.POST) if form.is_valid(): session = boto3.session.Session() user = User.objects.get(username=request.POST['username']) opponent = User.objects.get(username=request.POST['opponent']) user_chats = [elem.chat for elem in Member.objects.filter(user=user)] s3_client = session.client( service_name='s3', endpoint_url='http://hb.bizmrg.com', aws_access_key_id='6Da62vVLUi6AKbFnnRoeA3', aws_secret_access_key= 'gDYg4Bu15yUpNYGKmmpiVNGvLRWhUAJ3m1GGRvg8KTbU', ) avatar = s3_client.generate_presigned_url( 'get_object', Params={ 'Bucket': 'tsyrkov_messanger_bucket', 'Key': opponent.avatar, }, ExpiresIn=3600) topic = request.POST['username'] + ' with ' + request.POST['opponent'] for chat in user_chats: if Member.objects.filter(chat=chat).filter(user=opponent).exists(): return JsonResponse({ 'opponent': opponent.username, 'avatar': avatar, 'author': '', 'last_message': '', 'read': False, 'topic': topic, 'date': '', }) chat = Chat( topic=topic, is_group_chat=False, ) chat.save() member_1 = Member(chat=chat, user=user) member_2 = Member(chat=chat, user=opponent) member_1.save() member_2.save() return JsonResponse({ 'opponent': opponent.username, 'avatar': avatar, 'author': '', 'last_message': '', 'read': False, 'topic': topic, 'date': '', }) return JsonResponse({'errors': form.errors}, status=400)
def post(request): if request.method == "POST": msg = request.POST.get('msgbox', None) consultation_id = request.session['consultation_id'] consultation_obj = consultation.objects.get(id=consultation_id) c = Chat(consultation_id=consultation_obj,sender=request.user, message=msg) #msg = c.user.username+": "+msg if msg != '': c.save() print("msg saved"+ msg ) return JsonResponse({ 'msg': msg }) else: return HttpResponse('Request must be POST.')
def create_chat(request): user1 = get_object_or_404(User, id=request.data['participants'][0]) user2 = get_object_or_404(User, id=request.data['participants'][1]) contact1 = get_object_or_404(Contact, user=user1) contact2 = get_object_or_404(Contact, user=user2) chat = Chat() chat.save() chat.participants.add(contact1) chat.participants.add(contact2) serializer = ChatSerializers(data=chat) if serializer.is_valid(): serializer.save() print(serializer.data) return Response(serializer.data)
def setUp(self): self.client = Client() user1 = User(username=user_names[1]) user1.save() user1.set_password(user_passwords[1]) user1.save() user2 = User(username=user_names[2]) user2.save() user2.set_password(user_passwords[2]) user2.save() chat1 = Chat(name=chat_names[1]) chat1.save() chat1.members.add(user1) chat1.members.add(user2) chat1.save() chat_ids[1] = chat1.id chat2 = Chat(name=chat_names[2]) chat2.save() chat_ids[2] = chat2.id
def create_pers_chat(request): form = ChatForm(request.POST) if form.is_valid(): chat = Chat() chat.is_group_chat = False chat.topic = form.topic chat.last_messege = '' chat.save() return JsonResponse({'new chat': chat.topic})
def user_start_chat(request, user_id): # create one-on-one chat if request.method == 'GET': # add check for user trying to chat with himself # then, check for chat already present # otherwise, start new chat target = User.objects.filter(id=user_id).get() user_self = request.user # change to being the initiating user chat_obj = Chat(name='test_chat') # look about naming chat_obj.save() chat_obj.members.add(target) chat_obj.members.add(user_self) # chat_obj.save() return JsonResponse({ 'New chat': chat_obj.name, 'chat id': chat_obj.id }) else: return HttpResponseNotAllowed(['GET'])
def chat(request): if request.method == "GET": # 从数据库获取动态 chats = Chat.objects.filter( Q(sender=2, receiver=1) | Q(sender=1, receiver=2)) data = [] for c in chats: sender_id = c.sender_id data.append({ 'sender_id': sender_id, 'create_time': c.create_time, 'content': c.content }) res = { 'code': 200, 'data': data, } return JsonResponse(res) else: # ajax像数据库上传动态 params = json.loads(request.body.decode('utf-8')) content = params.get('content') print(content) sender = Passport.object.get(id=2) receiver = Passport.object.get(id=1) chat = Chat(sender=sender, content=content, receiver=receiver, create_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) chat.save() # Article.objects.create(passport_id=2,content=content) # return HttpResponse('{"status": "200"}', content_type='application/json') return JsonResponse({ 'code': 200, 'msg': '评论成功', })
def send_rejection_msg(profile, photo, reason): support = profile.matching_support chat = Chat.get_chat(profile, support) msg_body = ('Ваша фотография нарушала правила сайта и была удалена. ' 'Пожалуйста, згрузите новое фото. Это должна быть ' 'ваша фотография. Запрещено использовать фотографии:\n' '- несовершеннолетних детей\n' '- фотографии из Интернета и фото знаменитостей\n' '- изображения эротического характера\n' '- фотографии животных\n' '- предметы / картинки / рисунки') Message.objects.create(sender=support, receiver=profile, body=msg_body, chat=chat)
def test_cannot_create_chat_for_regular_user(self): assert Chat.objects.get_collective_chat( ) # created by initial migration chat = self.turker.chat assert chat.id assert chat.title == self.turker.username regular_user = baker.make(User, user_type=USER_TYPE.Regular.value) chat = Chat(turker=regular_user) with pytest.raises(ValueError): chat.save() chat = Chat() # can have only one collective chat with pytest.raises(ValueError): chat.save()
def emulate_message(messaged): prof_emu = find_profile_and_emulator(messaged) if not prof_emu: return profile, emulator = prof_emu chat = Chat.get_chat(profile, emulator) Message.objects.create( chat=chat, receiver=profile, sender=emulator, body='Привет') contact_kwargs = { 'emulator': emulator, 'contacted': profile, 'type': 'message' } Contact.objects.create(**contact_kwargs)
def reply(req): form = ReplyForm(req.POST) if form.is_valid(): profile = form.cleaned_data['profile'] moderator = profile.matching_support if not moderator: return HttpResponse('No matching support', status=500) chat = Chat.get_chat(profile, moderator) Message.objects.filter(chat=chat, receiver=moderator).update(is_read=True) Message.objects.create(sender=moderator, receiver=profile, body=form.cleaned_data['body'], chat=chat) if profile.user.email: send_feedback_email(profile, form.cleaned_data['body']) return HttpResponse('ok') return HttpResponse(str(form.errors), status=400)
def write_button_handler(request, pk): curr_us = get_object_or_404(User, id=pk) chat = Chat.objects.filter(members=curr_us).filter(members=request.user) messages = [] if len(chat) > 0: chat = chat[0] messages = Message.objects.filter(chat=chat) else: chat = Chat() chat.save() chat.members.add(curr_us) chat.members.add(request.user) chat.save() return render(request, 'chats/room.html', context={'messages': messages, 'room_name': str(chat.id)})
def create_chat(request): print(request.POST) token = request.headers.get('Authorization')[6:] form = ChatForm(request.POST) if form.is_valid(): if request.POST['is_group_chat'] == 'false': print('passed false') group_chat_status = False UserInput = User.objects.filter( username=request.POST['username']).values('id') if len(UserInput) is 0: return HttpResponse('Bad Request', status=400) firstMember_me = Token.objects.filter( key=token).values('user_id')[0]['user_id'] secondMember = UserInput[0]['id'] arr = [] for element in Member.objects.filter( user_id=firstMember_me).values('chat_id'): arr.append(element['chat_id']) for element in Member.objects.filter( user_id=secondMember).values('chat_id'): if element['chat_id'] in arr: print('Already exists') return JsonResponse({'error': 'Already exists'}, status=400) chat = Chat(is_group_chat=group_chat_status, topic=request.POST['topic'], last_message='') chat.save() Member.objects.create(user_id=firstMember_me, chat_id=chat.id) Member.objects.create(user_id=secondMember, chat_id=chat.id) return JsonResponse( { 'Result': 'Chat created', 'id': chat.id, 'topic': chat.topic }, json_dumps_params={'ensure_ascii': False}) elif request.POST['is_group_chat'] == 'true': print('passed true') print(request.POST.getlist('username')) print(request.POST['topic']) group_chat_status = True my_id = Token.objects.filter( key=token).values('user_id')[0]['user_id'] userlist = request.POST.getlist('username') chat = Chat(is_group_chat=group_chat_status, topic=request.POST['topic'], last_message='') chat.save() Member.objects.create(user_id=my_id, chat_id=chat.id) if len(userlist) == 0: return JsonResponse({'result': 'users not seleceted'}) else: for user in userlist: user_id = User.objects.filter( username=user).values('id')[0]['id'] Member.objects.create(user_id=user_id, chat_id=chat.id) return JsonResponse( { 'Result': 'Group chat created', 'id': chat.id, 'topic': chat.topic }, json_dumps_params={'ensure_ascii': False}) else: print('nothing passed') return JsonResponse({'error': 'is_group_chat is bad'}, status=400) return JsonResponse({'error': form.errors}, status=400, json_dumps_params={'ensure_ascii': False})
def add_chat(request): print('add_chat') # 直接產生一個聊天室 Chat().save() return HttpResponseRedirect(reverse('index'))
from offices.models import Office from chats.models import Chat from logs.models import Log from staff.models import Member import pytz tz = pytz.timezone("Africa/Douala") new_office = Office(office_name_kr="카메룬 사무소", office_name_en="Cameroon KOICA Office", office_timezone="Duala") new_office.save() print(new_office) new_chat = Chat(chat_id="13012319", chat_name="두번째테스트", office_fk=new_office, is_active=True) new_chat.save() print(new_chat) new_member = Member(telegram_id="1234", first_name="전", last_name="다민", office_fk=new_office) new_member.save() print(new_member) new_log = Log(chat_fk=new_chat, member_fk=new_member, first_name=new_member.first_name, last_name=new_member.last_name,