示例#1
0
def detectTags(request):
    text = request.POST.get("text")
    tagsCount = CONTAINER.getTagManager().tagsCount()
    minPart = calculateMinPart(tagsCount)
    tags = CONTAINER.getTagDetector().detect(text, limit=5, minPart = minPart)
    tagsNames = [tag.name for tag in tags]
    return HttpResponse(", ".join(tagsNames), content_type="text/plain")
示例#2
0
def index(request):
    tags = CONTAINER.getTagManager().getTags()
    tagMax = tags and max([tag.count for tag in tags]) or 0
    thoughts = CONTAINER.getThoughtManager().latest(settings.THOUGHTS_PER_PAGE)
    showMore = len(thoughts) == settings.THOUGHTS_PER_PAGE
    loadMoreUrl = reverse("latestPage", args=[1])

    return render(request, "thought/index.html",
            {'thoughts': thoughts, 'tags': tags, 'tagMax': tagMax,
             'showMore': showMore, 'loadMoreUrl': loadMoreUrl})
示例#3
0
def tag(request, tag):
    tags = CONTAINER.getTagManager().getTags()
    tagMax = tags and max([each.count for each in tags]) or 0
    thoughts = CONTAINER.getThoughtManager().searchByTag(tag, settings.THOUGHTS_PER_PAGE)
    showMore = len(thoughts) == settings.THOUGHTS_PER_PAGE
    loadMoreUrl = reverse("tagPage", args=[tag, 1])

    return render(request, "thought/tag.html", {
        "tag": tag, 'thoughts': thoughts, 'tags': tags,
        'tagMax': tagMax, 'showMore': showMore,
        'loadMoreUrl': loadMoreUrl
    })
示例#4
0
def post(request):
    error = None
    thought = Thought()

    if request.method == 'POST':
        thought.text = request.POST.get('text')

        if thought.text:
            thought.date = datetime.now()
            thought.tags = getTagsList(request.POST.get('tags'))
            CONTAINER.getThoughtManager().create(thought)

            return redirect('index')
        else:
            error = "Thought shouldn't be empty, otherwise who may need it?"

    return render(request, "thought/post.html", {'thought': thought, 'error': error})
示例#5
0
def edit(request, id):
    error = None
    thought = CONTAINER.getThoughtManager().get(id)

    if thought is None:
        raise Http404()

    if request.method == 'POST':
        thought.text = request.POST.get('text')
        if thought.text:
            thought.tags = getTagsList(request.POST.get('tags'))
            CONTAINER.getThoughtManager().save(thought)

            return redirect('index')
        else:
            error = "Thought shouldn't be empty, otherwise who may need it?"

    tags = (thought.get_tags() and ", ".join(thought.get_tags()) or "")
    return render(request, "thought/edit.html", {'thought': thought, 'tags': tags, 'error': error})
示例#6
0
def latestPage(request, page):
    page = int(page)
    thoughts = CONTAINER.getThoughtManager().latest(
        settings.THOUGHTS_PER_PAGE,
        skip=page * settings.THOUGHTS_PER_PAGE)
    showMore = len(thoughts) == settings.THOUGHTS_PER_PAGE
    loadMoreUrl = reverse("latestPage", args=[page + 1])

    return render(request, "thought/thoughts_page.html", {
        'thoughts': thoughts, "showMore": showMore,
        'loadMoreUrl': loadMoreUrl
    })
示例#7
0
def tagPage(request, tag, page):
    page = int(page)
    thoughts = CONTAINER.getThoughtManager().searchByTag(
        tag, settings.THOUGHTS_PER_PAGE,
        skip=page * settings.THOUGHTS_PER_PAGE)

    showMore = len(thoughts) == settings.THOUGHTS_PER_PAGE
    loadMoreUrl = reverse("tagPage", args=[tag, page + 1])

    return render(request, "thought/thoughts_page.html", {
        'thoughts': thoughts,
        'showMore': showMore,
        'loadMoreUrl': loadMoreUrl
    })
示例#8
0
def searchTags(request, keyword):
    tags = CONTAINER.getTagManager().searchTags(keyword)
    tagNames = [tag.name for tag in tags]
    return HttpResponse(",".join(tagNames), content_type="text/plain")
示例#9
0
def remove(request, id):
    CONTAINER.getThoughtManager().deleteById(id)
    return HttpResponseRedirect(reverse('index'))
示例#10
0
def thought(request, id):
    thought = CONTAINER.getThoughtManager().get(id)
    return render(request, "thought/thought.html", {'thought': thought})