Esempio n. 1
0
def submit_thread(request):
    """This view is intended to handle submission of thread.
    If submission don't include title and include url,
    then get title through function 'parse_title'.

    :param request: Django request object
    :return: If success, redirect to thread list sorted by date to check submitted thread. If not, error massage
    """
    try:
        title = request.POST["title"].strip()
        url = request.POST["url"].strip()
        content = request.POST["content"].strip()

        if not title and not url:
            request.session["error"] = "입력한 정보가 올바르지 않습니다"
            return redirect("new_thread")

        elif not title and url:
            title = parse_title(url)

        thread = Thread(title=title, url=url, content=content, writer_id=request.user.id)
        thread.save()
        return redirect("/?sort=date&page=1")

    except KeyError:
        request.session["error"] = "올바른 요청이 아닙니다"
        return redirect("new_thread")
Esempio n. 2
0
 def test_parse_google_title(self):
     google_title = parse_title('http://www.google.com')
     self.assertEqual('Google', google_title)