def create(self, validated_data):
        user = self.context['request'].user

        try:
            img = validated_data.get('image')
        except:
            img = None
        
        try:
            file = validated_data.get('file')
        except:
            file = None

        body=validated_data.get('body')

        recipient = get_object_or_404(User, username=validated_data['recipient']['username'])
        msg = MessageModel(recipient=recipient,
                           body=body,
                           image=img,
                           file=file,
                           user=user,
                           is_read= False)
        
        msg.save()
        return msg
示例#2
0
    def create(self, validated_data):
        user = self.context.get("request").user
        recipient = get_object_or_404(
            User, username=validated_data['recipient']['username'])
        msg = MessageModel(recipient=recipient,
                           body=validated_data['body'],
                           user=user)

        #user = self.context['request'].user
        # data = self.context['request'].data
        # recipient = data['recipient']
        # msg = data['body']

        # #print(user)

        # now = datetime.utcnow()+timedelta(hours=5.5)
        # monthNames = ["Jan", "Feb", "March", "April", "May", "June",
        # "July", "August", "Sep", "Oct", "Nov", "Dec"]
        # month = monthNames[int(now.strftime('%m '))-1]
        # dd = now.strftime('%d')
        # year =now.strftime('%Y')
        # date = month + " " +dd + "," + year
        # time = now.strftime('%I:%M %p')

        msg.save()
        return msg
示例#3
0
 def create(self, validated_data):
     user = self.context['request'].user
     recipient = get_object_or_404(
         User, username=validated_data['recipient']['username']
     )
     msg = MessageModel(recipient=recipient, body=validated_data['body'], user=user,files=validated_data['files'])
     msg.save()
     return msg
 def create(self, validated_data):
     user = self.context['request'].user
     recipient = get_object_or_404(
         Client_Personal_Info, Email=validated_data['recipient']['Email'])
     msg = MessageModel(recipient=recipient,
                        body=validated_data['body'],
                        user=user)
     msg.save()
     return msg
示例#5
0
 def create(self, validated_data):
     user = self.context["request"].user
     room = validated_data["group"]  # but why does this return THE room?
     msg = MessageModel(
         group=room,
         user=user,
         body=validated_data["body"],
     )
     msg.save()
     return msg
示例#6
0
 def create(self, validated_data):
     print("validate data is %s" % validated_data)
     user = self.context['request'].user
     recipient = get_object_or_404(User,
                                   id=validated_data['recipient']['id'])
     msg = MessageModel(recipient=recipient,
                        body=validated_data['body'],
                        user=user)
     msg.save()
     return msg
示例#7
0
 def create(self, validated_data):
     print(validated_data)
     print(self.context['request'].POST)
     user = self.context['request'].user
     attachment= urlparse(self.context['request'].POST['filepath']).path[1:]
     recipient = get_object_or_404(
         User, username=validated_data['recipient']['username'])
     msg = MessageModel(recipient=recipient,
                        body=validated_data['body'],
                        user=user,attachment=attachment, attachmentName = self.context['request'].POST['filename'])
     msg.save()
     #,
     return msg
from django.contrib.auth.models import User
from core.models import MessageModel, Domain
user = User.objects.all()
user_list = []
for item in user:
    user_list.append(item)
username = user_list[0]
rep = user_list[1]
tenant = MessageModel(schema_name='tenant1', user=username, recipient=rep, body='hello',)
tenant.save()
domain = Domain()
domain.domain = 't1.chatapp.com'
domain.tenant = tenant
domain.is_primary = True
domain.save()