def create_topic(author, forum, title, subtitle, text, key): """create topic in forum""" (tags, title_only) = get_tag_by_title(title[:80]) # Creating the thread n_topic = Topic() n_topic.forum = forum n_topic.title = title_only n_topic.subtitle = subtitle n_topic.pubdate = datetime.now() n_topic.author = author n_topic.key = key n_topic.save() n_topic.add_tags(tags) n_topic.save() # Add the first message post = Post() post.topic = n_topic post.author = author post.text = text post.text_html = emarkdown(text) post.pubdate = datetime.now() post.position = 1 post.save() n_topic.last_message = post n_topic.save() follow(n_topic, user=author) return n_topic
def send_post(topic, text): post = Post() post.topic = topic post.author = topic.author post.text = text post.text_html = emarkdown(text) post.pubdate = datetime.now() post.position = topic.last_message.position + 1 post.save() topic.last_message = post topic.save()
def send_post( request, topic, author, text, ): post = Post() post.topic = topic post.author = author post.pubdate = datetime.now() if topic.last_message is not None: post.position = topic.last_message.position + 1 else: post.position = 1 post.update_content( text, on_error=lambda m: messages.error( request, _('Erreur du serveur Markdown:\n{}').format('\n- '.join(m)))) post.ip_address = get_client_ip(request) post.hat = get_hat_from_request(request) post.save() topic.last_message = post topic.save() return topic
def send_post( request, topic, author, text, ): post = Post() post.topic = topic post.author = author post.pubdate = datetime.now() if topic.last_message is not None: post.position = topic.last_message.position + 1 else: post.position = 1 post.update_content(text) post.ip_address = get_client_ip(request) post.save() topic.last_message = post topic.save() return topic
def send_post(request, topic, author, text,): post = Post() post.topic = topic post.author = author post.pubdate = datetime.now() if topic.last_message is not None: post.position = topic.last_message.position + 1 else: post.position = 1 post.update_content( text, on_error=lambda m: messages.error( request, _('Erreur du serveur Markdown:\n{}').format('\n- '.join(m)))) post.ip_address = get_client_ip(request) post.hat = get_hat_from_request(request) post.save() topic.last_message = post topic.save() return topic
def send_post( request, topic, author, text, send_by_mail=False, ): post = Post() post.topic = topic post.author = author post.update_content(text) post.pubdate = datetime.now() if topic.last_message is not None: post.position = topic.last_message.position + 1 else: post.position = 1 post.ip_address = get_client_ip(request) post.save() topic.last_message = post topic.save() # Send mail if send_by_mail: subject = u"{} - {} : {}".format( settings.ZDS_APP['site']['litteral_name'], _(u'Forum'), topic.title) from_email = "{} <{}>".format( settings.ZDS_APP['site']['litteral_name'], settings.ZDS_APP['site']['email_noreply']) followers = topic.get_followers_by_email() for follower in followers: receiver = follower.user if receiver == post.author: continue last_read = TopicRead.objects.filter(topic=topic, post__position=post.position - 1, user=receiver).count() if last_read > 0: context = { 'username': receiver.username, 'title': topic.title, 'url': settings.ZDS_APP['site']['url'] + post.get_absolute_url(), 'author': post.author.username, 'site_name': settings.ZDS_APP['site']['litteral_name'] } message_html = render_to_string('email/forum/new_post.html', context) message_txt = render_to_string('email/forum/new_post.txt', context) msg = EmailMultiAlternatives(subject, message_txt, from_email, [receiver.email]) msg.attach_alternative(message_html, "text/html") msg.send() # Follow topic on answering if not topic.is_followed(user=post.author): follow(topic) return topic