def save(self, new_data, request, user_to = None): # current date datetime_now = datetime.now() # save topic topic = Topic() topic.theme = new_data['theme'] topic.user1 = request.user if user_to is None: user_to = User.objects.get(id = new_data['userToId']) topic.user2 = user_to topic.create_on = datetime_now topic.update_on = datetime_now topic.save() # save message message = Message() message.user_from = topic.user1 message.user_to = topic.user2 message.topic = topic message.body = new_data['body'] message.sent_on = datetime.now() message.save() return message
def form_valid(self, form): klass=Klass.objects.get(klass_name=self.kwargs['class_url']) new_msg=form.save(commit=False) topic=Topic.objects.get(id=int(self.kwargs['topic_id'])) new_msg.topic=topic new_msg.entered_on=datetime.now() new_msg.author=self.request.user new_msg.klass=klass new_msg.save() topic_update=Topic( id=topic.id, topic=topic.topic, homework=topic.homework, last_msg=datetime.now(), klass=klass, ) topic_update.save() return HttpResponseRedirect(reverse('message_view', args=(self.kwargs['class_url'],topic.id,)))
def form_valid(self, form): class_url=self.kwargs['class_url'] class_db=Classes.objects.get(classes=class_url) new_msg=form.save(commit=False) topic=Topic.objects.get(id=int(self.kwargs['topic_id'])) new_msg.topic=topic new_msg.entered_on=datetime.now() new_msg.author=self.request.user new_msg.class_db=class_db new_msg.save() topic_update=Topic( id=topic.id, topic=topic.topic, homework=topic.homework, last_msg=datetime.now(), class_db=class_db, ) topic_update.save() return HttpResponseRedirect(reverse_lazy('message-list-view', args=(self.kwargs['class_url'],topic.id,)))
def form_valid(self, form): klass=Klass.objects.get(klass_name=self.kwargs['class_url']) topic=Topic.objects.get(id=int(self.kwargs['topic_id'])) msg_replied_to=Msg.objects.get(id=int(self.kwargs['message_id'])) reply_msg=form.save(commit=False) reply_msg.topic=topic reply_msg.entered_on=datetime.now() reply_msg.msg_replied_to=msg_replied_to reply_msg.author=self.request.user reply_msg.klass=klass reply_msg.save() topic_update=Topic( id=topic.id, topic=topic.topic, homework=topic.homework, last_msg=datetime.now(), klass=klass, ) topic_update.save() return HttpResponseRedirect('/'+klass.klass_name+'/messages/'+str(topic.id)+'/messages')