Exemplo n.º 1
0
def create_notice(user_id, text, attachment=''):
    new_notice = Notice()
    new_notice.text = text
    new_notice.attachment = attachment
    new_notice.date_of_create = datetime.now()
    new_notice.last_sending = datetime.now()
    new_notice.user_id = user_id
    new_notice.save()
Exemplo n.º 2
0
def new(request, node_slug):
    context = {}
    try:
        node = Node.objects.get(slug=node_slug)
    except Node.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            last_topic = Topic.objects.filter(
                author=request.user).order_by('-created_on')[:1]
            last_topic = last_topic.first()
            if last_topic and last_topic.title == form.clean()['title'] and (
                (timezone.now() - last_topic.created_on).seconds < 10):
                messages.error(request, '你是否正在尝试连续提交两次相同的内容?')
                return HttpResponseRedirect(
                    reverse("bbs:topic", args=(last_topic.id, )))
            else:
                topic = form.save(commit=False)
                topic.node = node
                request.user.topic_num += 1
                request.user.calculate_au()
                request.user.save()
                topic.author = request.user
                topic.last_reply = request.user
                topic.updated_on = timezone.now()
                topic.save()
                node.num_topics += 1
                node.save()

                # --- 解析@ ---

                team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
                at_name_list = set(re.findall(team_name_pattern,
                                              topic.content))
                if at_name_list:
                    for at_name in at_name_list:
                        if at_name != topic.author.username:
                            try:
                                at_user = User.objects.get(username=at_name)
                                if at_user:
                                    notice = Notice(from_user=topic.author,
                                                    to_user=at_user,
                                                    topic=topic,
                                                    content='')
                                    notice.save()
                            except:
                                pass

                # --- 解析@ ---

                return HttpResponseRedirect(
                    reverse("bbs:topic", args=(topic.id, )))
    else:
        form = TopicForm()

    return render(request, 'bbs/new.html', {'node': node, 'form': form})
Exemplo n.º 3
0
def reply(request, topic_id):

    try:
        topic = Topic.objects.get(id=topic_id)
        comment_list = Comment.objects.filter(topic=topic).order_by('created_on')
    except Topic.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = ReplyForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            request.user.comment_num += 1
            request.user.calculate_au()
            request.user.save()
            comment.author = request.user

            try:
                topic = Topic.objects.get(id=topic_id)
            except Topic.DoesNotExist:
                raise Http404

            comment.topic = topic
            comment.save()

            # --- 解析@ ---

            #team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
            team_name_pattern = re.compile('(?<=@)([0-9a-zA-Z.]+)', re.UNICODE)
            at_name_list = set(re.findall(team_name_pattern, comment.content))
            if at_name_list:
                for at_name in at_name_list:
                    if at_name != comment.author.username and at_name != comment.topic.author.username:
                        try:
                            at_user = User.objects.get(username=at_name)
                            if at_user:
                                notice = Notice(from_user=comment.author,to_user=at_user    ,topic=comment.topic,content=comment.content)
                                notice.save()
                        except:
                            pass

            # --- 解析@ ---

            topic.num_comments += 1
            topic.updated_on = timezone.now()
            topic.last_reply = request.user
            topic.save()
            return HttpResponseRedirect(reverse("bbs:topic" ,args=(topic_id,)))
    else:
        form = ReplyForm()

    return render(request,"bbs/topic.html",{"node":node,"topic":topic,"form":form,"comment_list":comment_list})
Exemplo n.º 4
0
def new(request, node_slug):
    context = {}
    try:
        node = Node.objects.get(slug=node_slug)
    except Node.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            last_topic = Topic.objects.filter(author=request.user).order_by('-created_on')[:1]
            last_topic = last_topic.first()
            if last_topic and last_topic.title == form.clean()['title'] and ((timezone.now()-last_topic.created_on).seconds < 10):
                messages.error(request,'你是否正在尝试连续提交两次相同的内容?');
                return HttpResponseRedirect(reverse("bbs:topic" ,args=(last_topic.id,)))
            else:
                topic = form.save(commit=False)
                topic.node = node
                request.user.topic_num += 1
                request.user.calculate_au()
                request.user.save()
                topic.author = request.user
                topic.last_reply = request.user
                topic.updated_on = timezone.now()
                topic.save()
                node.num_topics += 1
                node.save()

                # --- 解析@ ---

                team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
                at_name_list = set(re.findall(team_name_pattern, topic.content))
                if at_name_list:
                    for at_name in at_name_list:
                        if at_name != topic.author.username:
                            try:
                                at_user = User.objects.get(username=at_name)
                                if at_user:
                                    notice = Notice(from_user=topic.author,to_user=at_user,topic=topic,content='')
                                    notice.save()
                            except:
                                pass

                # --- 解析@ ---

                return HttpResponseRedirect(reverse("bbs:topic" ,args=(topic.id,)))
    else:
        form = TopicForm()

    return render(request,'bbs/new.html',{'node':node,'form':form})
Exemplo n.º 5
0
def new(request, node_slug):
    context = {}
    try:
        node = Node.objects.get(slug=node_slug)
    except Node.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            topic = form.save(commit=False)
            topic.node = node
            request.user.topic_num += 1
            request.user.calculate_au()
            request.user.save()
            topic.author = request.user
            topic.last_reply = request.user
            topic.updated_on = timezone.now()
            topic.save()
            node.num_topics += 1
            node.save()

            # --- 解析@ ---

            team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
            at_name_list = set(re.findall(team_name_pattern, topic.content))
            if at_name_list:
                for at_name in at_name_list:
                    if at_name != topic.author.username:
                        try:
                            at_user = User.objects.get(username=at_name)
                            if at_user:
                                notice = Notice(from_user=topic.author,to_user=at_user,topic=topic,content='')
                                notice.save()
                        except:
                            pass

            # --- 解析@ ---

            return HttpResponseRedirect(reverse("bbs:topic" ,args=(topic.id,)))
    else:
        form = TopicForm()

    return render(request,'bbs/new.html',{'node':node,'form':form})
Exemplo n.º 6
0
 def save(self):
     notice = Notice(text=self.cleaned_data['text'],
                     user=self.user,
                     project=self.project)
     notice.save()
     return notice
Exemplo n.º 7
0
def reply(request, topic_id):

    try:
        topic = Topic.objects.get(id=topic_id)
        # comment ---
        comment_list = Comment.objects.filter(
            topic=topic).order_by('created_on')
        paginator = Paginator(comment_list, NUM_COMMENT_PER_PAGE)
        page = request.GET.get('page')
        if page == None:
            page = paginator.num_pages

        try:
            comment_list = paginator.page(page)
        except PageNotAnInteger:
            comment_list = paginator.page(1)
        except EmptyPage:
            comment_list = paginator.page(paginator.num_pages)
        # comment ---
    except Topic.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = ReplyForm(request.POST)
        if form.is_valid():
            last_comment = Comment.objects.filter(
                author=request.user).order_by('-created_on')[:1]
            last_comment = last_comment.first()
            if last_comment and last_comment.content == form.clean(
            )['content'] and (
                (timezone.now() - last_comment.created_on).seconds < 10):
                messages.error(request, '你是否正在尝试连续提交两次相同的回复?')
            else:
                comment = form.save(commit=False)
                request.user.comment_num += 1
                request.user.calculate_au()
                request.user.save()
                comment.author = request.user

                try:
                    topic = Topic.objects.get(id=topic_id)
                except Topic.DoesNotExist:
                    raise Http404

                comment.topic = topic
                comment.save()

                # --- 解析@ ---

                #team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
                team_name_pattern = re.compile('(?<=@)([0-9a-zA-Z_.]+)',
                                               re.UNICODE)
                at_name_list = set(
                    re.findall(team_name_pattern, comment.content))
                if at_name_list:
                    for at_name in at_name_list:
                        if at_name != comment.author.username and at_name != comment.topic.author.username:
                            try:
                                at_user = User.objects.get(username=at_name)
                                if at_user:
                                    notice = Notice(from_user=comment.author,
                                                    to_user=at_user,
                                                    topic=comment.topic,
                                                    content=comment.content)
                                    notice.save()
                            except:
                                pass

                # --- 解析@ ---

                topic.num_comments += 1
                topic.updated_on = timezone.now()
                topic.last_reply = request.user
                topic.save()
                return HttpResponseRedirect(
                    reverse("bbs:topic", args=(topic_id, )))
    else:
        form = ReplyForm()

    return render(
        request, "bbs/topic.html", {
            "node": node,
            "topic": topic,
            "form": form,
            "comment_list": comment_list,
            'paginator': paginator
        })
Exemplo n.º 8
0
def reply(request, topic_id):

    try:
        topic = Topic.objects.get(id=topic_id)
        # comment ---
        comment_list = Comment.objects.filter(topic=topic).order_by('created_on')
        paginator = Paginator(comment_list, NUM_COMMENT_PER_PAGE)
        page = request.GET.get('page')
        if page == None:
            page = paginator.num_pages

        try:
            comment_list = paginator.page(page)
        except PageNotAnInteger:
            comment_list = paginator.page(1)
        except EmptyPage:
            comment_list = paginator.page(paginator.num_pages)
        # comment ---
    except Topic.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = ReplyForm(request.POST)
        if form.is_valid():
            last_comment = Comment.objects.filter(author=request.user).order_by('-created_on')[:1]
            last_comment = last_comment.first()
            if last_comment and last_comment.content == form.clean()['content'] and ((timezone.now()-last_comment.created_on).seconds < 10):
                messages.error(request,'你是否正在尝试连续提交两次相同的回复?');
            else:
                comment = form.save(commit=False)
                request.user.comment_num += 1
                request.user.calculate_au()
                request.user.save()
                comment.author = request.user

                try:
                    topic = Topic.objects.get(id=topic_id)
                except Topic.DoesNotExist:
                    raise Http404

                comment.topic = topic
                comment.save()

                # --- 解析@ ---

                #team_name_pattern = re.compile('(?<=@)(\w+)', re.UNICODE)
                team_name_pattern = re.compile('(?<=@)([0-9a-zA-Z_.]+)', re.UNICODE)
                at_name_list = set(re.findall(team_name_pattern, comment.content))
                if at_name_list:
                    for at_name in at_name_list:
                        if at_name != comment.author.username and at_name != comment.topic.author.username:
                            try:
                                at_user = User.objects.get(username=at_name)
                                if at_user:
                                    notice = Notice(from_user=comment.author,to_user=at_user    ,topic=comment.topic,content=comment.content)
                                    notice.save()
                            except:
                                pass

                # --- 解析@ ---

                topic.num_comments += 1
                topic.updated_on = timezone.now()
                topic.last_reply = request.user
                topic.save()
                return HttpResponseRedirect(reverse("bbs:topic" ,args=(topic_id,)))
    else:
        form = ReplyForm()

    return render(request,"bbs/topic.html",{"node":node,"topic":topic,"form":form,"comment_list":comment_list,'paginator':paginator})