def _save_message(self): """Save the new message""" new_message = None author = self.author rendered = self.parser.render(self.cleaned_data['content']) if not author.is_authenticated(): author = None new_message = Message( channel=self.channel, author=author, user_agent=self.cleaned_data['user_agent'][:150], ip=self.cleaned_data['ip'], raw=self.cleaned_data['content'], web_render=rendered['web_render'], remote_render=rendered['remote_render'], ) new_message.save() # If message contains URLs, archive them if rendered['urls']: self._save_urls(new_message, rendered['urls']) return new_message
def _save_message(self): """Save the new message""" new_message = None author = self.author rendered = self.parser.render(self.cleaned_data['content']) created = datetime.datetime.utcnow().replace(tzinfo=utc) if not author.is_authenticated(): author = None new_message = Message( created=created, # Enforce the same time that the one stored in created clock=created.astimezone(pytz.timezone(settings.TIME_ZONE)).time(), channel=self.channel, author=author, user_agent=self.cleaned_data['user_agent'][:150], ip=self.cleaned_data['ip'], raw=self.cleaned_data['content'], web_render=rendered['web_render'], remote_render=rendered['remote_render'], ) new_message.save() # If anonymous, save the id to a list (limited to X items) in session if author is None: owned_ids = self.session.get('tribune_owned_post_ids', [])[:TRIBUNE_SESSION_MAX_OWNED_IDS - 1] owned_ids.insert(0, new_message.id) self.session['tribune_owned_post_ids'] = owned_ids # If authenticated, allways empty (to avoid conflict) else: self.session['tribune_owned_post_ids'] = [] # If message contains URLs, archive them if rendered['urls']: self._save_urls(new_message, rendered['urls']) return new_message
def _save_message(self): """Save the new message""" new_message = None author = self.author rendered = self.parser.render(self.cleaned_data['content']) created = datetime.datetime.utcnow().replace(tzinfo=utc) if not author.is_authenticated(): author = None new_message = Message( created=created, # Enforce the same time that the one stored in created clock=created.astimezone(pytz.timezone(settings.TIME_ZONE)).time(), channel=self.channel, author=author, user_agent=self.cleaned_data['user_agent'][:150], ip=self.cleaned_data['ip'], raw=self.cleaned_data['content'], web_render=rendered['web_render'], remote_render=rendered['remote_render'], ) new_message.save() # If anonymous, save the id to a list (limited to X items) in session if author is None: owned_ids = self.session.get('tribune_owned_post_ids', [])[:TRIBUNE_SESSION_MAX_OWNED_IDS-1] owned_ids.insert(0, new_message.id) self.session['tribune_owned_post_ids'] = owned_ids # If authenticated, allways empty (to avoid conflict) else: self.session['tribune_owned_post_ids'] = [] # If message contains URLs, archive them if rendered['urls']: self._save_urls(new_message, rendered['urls']) return new_message