Ejemplo n.º 1
0
def users(request):
    if request.method == 'POST' and request.POST["_method"] == "NEW":
        from app_search.helpers.app_helper import AppHelper
        data = request.POST.copy()
        data['date_joined'] = datetime.date.today()
        data['is_active'] = True
        print("before")
        print(data)
        if 'password' not in data or 'password' in data and data['password'] == '':
            print("generate password")
            data['password'] = AppHelper.generate_password()

        print("@@@ password={0}".format(data['password']))
        uform = UserForm(data)
        pform = UserProfileForm(data)
        if uform.is_valid() and pform.is_valid():
            u = uform.save()
            p = pform.save(commit = False)
            p.user = u
            p.save()
            if user and p:
                message.flash(request, "登録に成功しました", "success")
                # TODO: passwordの通知方法
                return redirect('user', pk = user.id)
            else:
                message.flash(request, "登録に失敗しました", "danger")

        else:
            message.flash_with_errors(request, "入力エラーです。", uform.errors, pform.errors)

        # end of POST
        c = {}
        c.update(csrf(request))
        page = {}
        page.update(message.get_flash_message(request))
        page.update({'form': uform})
        c["page"] = page
        return render_to_response('users/new.jinja', c)

    paginate = Paginate()
    users = User.objects.all()

    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    page.update(paginate.paginate(0, 1))
    c["page"] = page
    c["users"] = users
    return render_to_response('users/index.jinja', c)
Ejemplo n.º 2
0
def m_show(request, m_id=None, format='html'):
    client = riak.RiakClient()
    bucket = client.bucket_type(settings.RIAK["STORE_BUCKET_TYPE"]).bucket(settings.RIAK["STORE_BUCKET"])

    #print("m_id={} format={}".format(m_id, format))

    m = bucket.get(m_id)
    if m == None or m.exists == False:
        return HttpResponseNotFound(render_to_response('404.html'))

    if request.method == 'POST' and request.POST["_method"] == "DELETE":
        print("delete object id={0}".format(m_id))
        m.delete()
        message.flash(request, "削除に成功しました", "success")
        return redirect('home')

    #
    page = {}
    page.update(message.get_flash_message(request))

    c = {}
    c.update(csrf(request))
    c.update({"m": m.data})
    c.update({"page": page})

    if format == "json":
        return HttpResponse(json.dumps(m.data, ensure_ascii=False, indent=2), content_type='application/json; encoding=utf-8')
    else:
        return render_to_response('search/show.jinja', c)
Ejemplo n.º 3
0
def location(request, pk):

    print("pk={}".format(pk))
    l = Location.find(pk)
    if l == None or l.exists == False:
        return HttpResponseNotFound(render_to_response('404.html'))

    if request.method == 'POST' and request.POST["_method"] == "DELETE":
        print("delete object id={0}".format(pk))
        l.delete()
        message.flash(request, "削除に成功しました", "success")
        return redirect('locations')

    #
    page = {}
    page.update(message.get_flash_message(request))

    c = {}
    c.update(csrf(request))
    c.update({"l": l.data})
    c.update({"page": page})

    if format == "json":
        return HttpResponse(json.dumps(l.data, ensure_ascii=False, indent=2), content_type='application/json; encoding=utf-8')
    else:
        return render_to_response('locations/show.jinja', c)
Ejemplo n.º 4
0
def new_location(request):
    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    page.update({'form': LocationForm()})
    c["page"] = page
    return render_to_response('locations/new.jinja', c)
Ejemplo n.º 5
0
def search_index(request):
    page = {"q": ""}
    page.update(message.get_flash_message(request))

    u = request.user

    return render_to_response('search/search_index.jinja',
                              {"page": page, "user": u}
                              )
Ejemplo n.º 6
0
def new_user(request):
    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    page.update({'form': UserForm()})
    page.update({'profile_form': UserProfileForm()})
    c["page"] = page
    return render_to_response('users/new.jinja', c)
Ejemplo n.º 7
0
def locations(request):

    paginate = Paginate()
    users = User.all()

    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    page.update(paginate.paginate(0, 1))
    c["page"] = page
    c["users"] = users
    return render_to_response('locations/index.jinja', c)
Ejemplo n.º 8
0
def profile(request):
    print(request.user)
    u = request.user
    if u == None:
        return HttpResponseNotFound(render_to_response('404.html'))

    page = {}
    page.update(message.get_flash_message(request))

    c = {}
    c.update(csrf(request))
    c.update({"u": u})
    c.update({"page": page})

    return render_to_response('accounts/profile.jinja', c)
Ejemplo n.º 9
0
def edit_user(request, pk):
    u = User.objects.get(id=pk)
    if u == None:
        return HttpResponseNotFound(render_to_response('404.html'))

    p = u.userprofile

    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    page.update({'id': u.id})
    page.update({'form': UserForm(instance=u)})
    page.update({'profile_form': UserProfileForm(instance=p)})
    c["page"] = page
    return render_to_response('users/edit.jinja', c)
Ejemplo n.º 10
0
def m_import_isbn(request):
    page = {}
    if request.method == 'POST':
        isbn = request.POST["isbn"]
        isbn = isbn.strip()
        m = ndl_search_opensearch.NdlHelper.import_from_net_by_isbn(isbn)
        if m:
            message.flash(request, "インポートに成功しました", "success")
            return redirect('m_show', m_id=m.key)
        else:
            message.flash(request, "インポートに失敗しました", "danger")

    c = {}
    c.update(csrf(request))
    page = {}
    page.update(message.get_flash_message(request))
    c["page"] = page
    return render_to_response('search/m_import_isbn.jinja', c)
Ejemplo n.º 11
0
def m_import_from_ndl_rss(request):
    if request.method == 'POST':
        url = request.POST["url"]
        url = url.strip()
        import_logger = ndl_search_opensearch.NdlHelper.imoprt_from_rss(url)
        if import_logger:
            message.flash(request, "インポートに成功しました", "success")
            return redirect('home')
        else:
            message.flash(request, "インポートに失敗しました", "danger")

    c = {}
    c.update(csrf(request))
    page = {}
    page.update({"url":"http://iss.ndl.go.jp/rss/ndlopac/index.xml"})
    page.update(message.get_flash_message(request))
    c["page"] = page
    return render_to_response('search/m_import_rss.jinja', c)
Ejemplo n.º 12
0
def user(request, pk):

    u = User.objects.get(id=pk)
    if u == None:
        return HttpResponseNotFound(render_to_response('404.html'))

    p = u.userprofile
    print(">>> start update")
    print(p.id)

    if request.method == 'POST' and request.POST["_method"] == "EDIT":
        print(">>> edit object id={0}".format(pk))
        from app_search.helpers.app_helper import AppHelper
        data = request.POST.copy()
        uform = UserForm(data, instance=u)
        pform = UserProfileForm(data, instance=p)
        if uform.is_valid() and pform.is_valid():
            u = uform.save()
            p = pform.save(commit = False)
            p.user = u
            p.save()
            if user and p:
                message.flash(request, "更新に成功しました", "success")
                # TODO: passwordの通知方法
                return redirect('user', pk = u.id)
            else:
                message.flash(request, "更新に失敗しました", "danger")

        else:
            print(">>> invalid")
            print(uform.errors)
            print(pform.errors)
            message.flash_with_errors(request, "入力エラーです。", uform.errors, pform.errors)


            c = {}
            c.update(csrf(request))
            page = {}
            page.update(message.get_flash_message(request))
            page.update({'id': u.id})
            page.update({'form': UserForm(instance=u)})
            page.update({'profile_form': UserProfileForm(instance=p)})
            c["page"] = page
            return render_to_response('users/edit.jinja', c)

    if request.method == 'POST' and request.POST["_method"] == "DELETE":
        print("delete object id={0}".format(pk))
        u.delete()
        message.flash(request, "削除に成功しました", "success")
        return redirect('users')

    #
    page = {}
    page.update(message.get_flash_message(request))

    c = {}
    c.update(csrf(request))
    c.update({"u": u})
    c.update({"p": p})
    c.update({"page": page})

    if format == "json":
        return HttpResponse(json.dumps(u.data, ensure_ascii=False, indent=2), content_type='application/json; encoding=utf-8')
    else:
        return render_to_response('users/show.jinja', c)