def save(self): if not self.hash: random.seed() salt = sha(str(random.random())).hexdigest() self.hash = sha(salt).hexdigest() if not self.ip: self.ip = threadlocals.get_current_ip() super(Person, self).save()
def create_forum_topic(article, forum_name): if article.id == None: # forum topic not created, lets create user = get_object_or_404(User, username=threadlocals.get_current_user()) forum = Forum.objects.filter(name=forum_name).order_by("id")[0] topic = Topic( forum=forum, title=article.title, ) topic.save() post = Post( topic=topic, author=user, text=article.text, ip=threadlocals.get_current_ip(), hidden=not article.status, ) post.save() topic.topic_latest_post = post topic.posts = 1 topic.hidden = not article.status topic.topic_latest_post = post topic.forum.posts += 1 topic.forum.topics += 1 if article.status: topic.forum.forum_latest_post = post topic.forum.save() topic.save() article.topic = topic else: # this is modified, let's update the forum topic topic = article.topic topic.tags.clear() for tag in article.tags.all(): topic.tags.add(tag) topic.hidden = not article.status topic.locked = not article.status topic.title = article.title topic.save() post = topic.post_set.order_by("created")[0] post.text = article.text post.hidden = not article.status post.edited = article.update post.save() if article.status: try: ping_google() # we're catching SitemapNotFound exception # no need to import this exception class since there is only 1 exception in the function. except: pass
def create_forum_topic(article, forum_name): if article.id == None: # forum topic not created, lets create user = get_object_or_404(User, username=threadlocals.get_current_user()) forum = Forum.objects.filter(name=forum_name).order_by("id")[0] topic = Topic( forum = forum, title = article.title, ) topic.save() post = Post( topic=topic, author=user, text=article.text, ip=threadlocals.get_current_ip(), hidden=not article.status, ) post.save() topic.topic_latest_post = post topic.posts = 1 topic.hidden = not article.status topic.topic_latest_post = post topic.forum.posts += 1 topic.forum.topics += 1 if article.status: topic.forum.forum_latest_post = post topic.forum.save() topic.save() article.topic = topic else: # this is modified, let's update the forum topic topic = article.topic topic.tags.clear() for tag in article.tags.all(): topic.tags.add(tag) topic.hidden = not article.status topic.locked = not article.status topic.title = article.title topic.save() post = topic.post_set.order_by("created")[0] post.text = article.text post.hidden = not article.status post.edited = article.update post.save() if article.status: try: ping_google() # we're catching SitemapNotFound exception # no need to import this exception class since there is only 1 exception in the function. except: pass
def pastedtext_add(request): if request.method == "POST": form = PastedTextForm(request.POST.copy()) if form.is_valid(): paste = form.save(commit=False) paste.author = request.user paste.ip = threadlocals.get_current_ip() paste.save() return HttpResponseRedirect(paste.get_absolute_url()) else: form = PastedTextForm() return render_response(request, "paste/pastedtext_add.html", {"form":form})
def save(self): new_post = False if not self.id: new_post = True if not self.ip: self.ip = threadlocals.get_current_ip() super(Post, self).save() if new_post: t = Topic.objects.get(pk=self.topic.id) t.topic_latest_post_id = self.id t.posts += 1 t.save() f = Forum.objects.get(pk=self.topic.forum.id) f.forum_latest_post_id = self.id f.posts += 1 f.save()