コード例 #1
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def user_index(request):
    user_info = users.get_current_user()
    if not user_info:
        return HttpResponseRedirect("/user/login/")
    if request.method == "GET":
        logging.error("method - get")
        u = models.MyUser.all().filter("user = "******"real_name": u.realname}
        u_form = UserInfoForm(f_data)
        context = {
            "static_path": STATIC_PATH,
            "user": u,
            "user_info": user_info,
            "form": u_form,
            "csrfmiddlewaretoken": str(csrf(request)["csrf_token"]),
        }
        return render_to_response("user_modify.html", context)
    if request.method == "POST":
        logging.error("method - post")
        try:
            u_form = UserInfoForm(request.POST)
            if not u_form.is_valid():
                return err_page(("Error"))

            u = models.MyUser.all().filter("user = "******"real_name")
            u.put()
            return HttpResponseRedirect("/user/")
        except Exception, x:
            return err_page(("user_index_POST_Error"))
コード例 #2
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def new_content(request):
    user_info = users.get_current_user()
    if not user_info:
        return HttpResponseRedirect("/user/login/")

    if request.method == "GET":
        c_form = ContentForm(auto_id=True)
        context = {"static_path": STATIC_PATH, "user_info": user_info, "form": c_form}
        return render_to_response("content_new.html", context)
    if request.method == "POST":
        try:
            w_form = ContentForm(request.POST)
            if not w_form.is_valid():
                return err_page("error_new_content_POST_form is valid")
            u = models.MyUser.all().filter("user = "******"error_new_content_POST invalid User")
            c = models.Content(
                owner=u,
                title=request.POST["title"].strip(),
                content=request.POST["content"].strip(),
                version=request.POST["version"].strip(),
                # title = unicode(request.POST['title'].strip(), 'utf8'),
                # content = unicode(request.POST['content'].strip(), 'utf8'),
                # version = unicode(request.POST['version'].strip(), 'utf8'),
                post_time=datetime.now(),
            )
            c.put()
            return HttpResponseRedirect("/content/" + str(c.key().id()) + "/read/")
        except Exception, x:
            logging.error("error_new_content_POST,  %s", x)
            return err_page("error_new_content_POST")
コード例 #3
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def read_content(request, content_id):
    if request.method == "GET":
        user_info = users.get_current_user()
        c = models.Content.get_by_id(int(content_id))
        if not c:
            return err_page("Wrong Request")
        context = {"static_path": STATIC_PATH, "user_info": user_info, "content": c}
        return render_to_response("content_read.html", context)
    return err_page("Wrong Request2")
コード例 #4
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def delete(request, content_id):
    user_info = users.get_current_user()
    if not user_info:
        return HttpResponseRedirect("/user/login/")
    if request.method == "GET":
        try:
            c = models.Content.get_by_id(int(content_id))
            if not c:
                return err_page("Wrong request")
            if c.owner.user != user_info:
                return err_page("You cannot delete this information.")
            c.delete()
            return HttpResponseRedirect("/")
        except Exception, x:
            return err_page("Delete Error")
コード例 #5
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def login(request):
    user_info = users.get_current_user()
    if not user_info:
        return HttpResponseRedirect(users.create_login_url("/user/login/"))
    try:
        u = models.MyUser.all().filter("user ="******"/")
        else:
            u = models.MyUser(user=user_info, nickname=user_info.nickname())
            u.put()
            return HttpResponseRedirect("/user/")
    except Exception:
        return err_page(("login_Error"))
コード例 #6
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
def modify(request, content_id):
    user_info = users.get_current_user()
    if not user_info:
        return HttpResponseRedirect("/user/login/")
    if request.method == "GET":
        c = models.Content.get_by_id(int(content_id))
        if not c:
            return err_page("Wrong request : modify_GET")
        if c.owner.user != user_info:
            return err_page("You cannot modify this information")
        form_data = {"title": c.title, "content": c.content, "version": c.version}
        c_form = ContentForm(form_data, auto_id=True)
        context = {"static_path": STATIC_PATH, "user_info": user_info, "form": c_form}
        return render_to_response("content_modify.html", context)
    if request.method == "POST":
        try:
            c_form = ContentForm(request.POST)
            if not c_form.is_valid():
                return err_page("Invalid input.")

            u = models.MyUser.all().filter("user = "******"Invalid user.")
            c = models.Content.get_by_id(int(content_id))
            if not c:
                return err_page("Wrong request")

            if c.owner.user != user_info:
                return err_page("You cannot modify this information.")

            c.nickname = u.nickname
            c.title = request.POST["title"].strip()
            c.content = request.POST["content"].strip()
            c.version = request.POST["version"].strip()
            c.post_time = datetime.now()
            c.put()

            return HttpResponseRedirect("/content/" + str(c.key().id()) + "/read/")
        except Exception, x:
            return err_page("Error")
コード例 #7
0
ファイル: views.py プロジェクト: ckbkkc/KakaoClub
            c = models.Content(
                owner=u,
                title=request.POST["title"].strip(),
                content=request.POST["content"].strip(),
                version=request.POST["version"].strip(),
                # title = unicode(request.POST['title'].strip(), 'utf8'),
                # content = unicode(request.POST['content'].strip(), 'utf8'),
                # version = unicode(request.POST['version'].strip(), 'utf8'),
                post_time=datetime.now(),
            )
            c.put()
            return HttpResponseRedirect("/content/" + str(c.key().id()) + "/read/")
        except Exception, x:
            logging.error("error_new_content_POST,  %s", x)
            return err_page("error_new_content_POST")
    return err_page("error_new_content ::: Wrong request")


def read_content(request, content_id):
    if request.method == "GET":
        user_info = users.get_current_user()
        c = models.Content.get_by_id(int(content_id))
        if not c:
            return err_page("Wrong Request")
        context = {"static_path": STATIC_PATH, "user_info": user_info, "content": c}
        return render_to_response("content_read.html", context)
    return err_page("Wrong Request2")


def modify(request, content_id):
    user_info = users.get_current_user()