예제 #1
0
파일: views.py 프로젝트: boomeer/tripnsale
def EditProfileView(request):
    params = request.REQUEST
    user = GetCurrentUser(request)
    act = params.get("act", "")
    if user and act == "edit":
        try:
            oldPassw = params.get("oldPassword", "")
            passw = params.get("password", "")
            passw2 = params.get("password2", "")
            if oldPassw or passw or passw2:
                if not authenticate(username=user.username, password=oldPassw):
                    raise OldPassInvalidErr
                if passw != passw2:
                    raise PasswordsAreNotEqualErr
                if not (3 <= len(passw) <= 20):
                    raise BadPasswordLengthErr
                user.set_password(passw)

            if not params.get("firstName", "").strip():
                raise FirstnameMissingErr

            user.first_name = params["firstName"]

            if not params.get("lastName", "").strip():
                raise LastnameMissingErr
            user.last_name = params["lastName"]

            try:
                user.country = Country.objects.get(name=params.get("country", ""))
            except:
                raise InvalidCountryErr

            user.city = params.get("city", "")
            if not params.get("bday", "").strip():
                user.birthday = None
            else:
                try:
                    user.birthday = datetime.strptime(params["bday"], "%d.%m.%Y")
                except ValueError:
                    raise BdayInvalidErr
            user.about = params.get("about", "")

            user.emailNotify = params.get("emailNotify", False)

            if 'avatar' in request.FILES:
                StoreImage(request.FILES['avatar'], user.avatar)
                MakeThumbnail(user.avatar, user.avatarThumb)
            user.save()
            return redirect("/user/profile/")
        except EditErr as e:
            raise RedirectExc("/user/edit_profile/?err={}".format(e.status))
        except TsExc as e:
            raise RedirectExc("/user/edit_profile/?err={}".format(str(e)))
    return RenderToResponse("user/edit_profile.html", request, {
        "url": "/user/edit_profile/",
        "prUser": user,
        "countries": GetCountries(),
        "err": GetEditProfileMsg(params.get("err", ""))
    })
예제 #2
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyView(request, id):
    buy = BuyOffer.objects.get(id=id)
    if not buy.visible():
        raise Exception("not found")
    return RenderToResponse("offer/buy/view.html", request, {
        "buy": buy,
        "connected": BuyIsConnected(request, id),
    })
예제 #3
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleView(request, id):
    sale = SaleOffer.objects.get(id=id)
    if not sale.visible():
        raise Exception("not found")
    return RenderToResponse("offer/sale/view.html", request, {
        "sale": sale,
        "connected": SaleIsConnected(request, id),
    })
예제 #4
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleRecommendView(request, id):
    params = request.REQUEST
    sale = SaleOffer.objects.get(id=id)
    if sale.owner != GetCurrentUser(request):
        return redirect("/offer/sale/{}".format(id))

    filterparams = BuyFilterExtractParams(request, static=True, recommend=sale)
    filterparams["recSale"] = sale
    filterparams["firstTime"] = ParseBool(params.get("first_time", ""))
    return RenderToResponse("offer/sale/recommend.html", request, filterparams)
예제 #5
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyRecommendView(request, id):
    params = request.REQUEST
    buy = BuyOffer.objects.get(id=id)
    if buy.owner != GetCurrentUser(request):
        return redirect("/offer/buy/{}".format(id))

    filterparams = SaleFilterExtractParams(request, static=True, recommend=buy)
    filterparams["recBuy"] = buy
    filterparams["firstTime"] = ParseBool(params.get("first_time", ""))
    return RenderToResponse("offer/buy/recommend.html", request, filterparams)
예제 #6
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyPreview(request, id):
    params = request.REQUEST
    buy = BuyOffer.objects.get(id=id)
    if not buy.visible():
        raise Exception("not found")
    return RenderToResponse(
        "offer/buy/preview.html", request, {
            "buy": buy,
            "editBackref": params.get("editBackref", ""),
            "connected": BuyIsConnected(request, id),
        })
예제 #7
0
파일: views.py 프로젝트: boomeer/tripnsale
def ProfileView(request, userid=None):
    params = request.REQUEST
    user = User.objects.get(id=userid) if userid else GetCurrentUser(request)
    if not user and not userid:
        return redirect("/user/auth/")
    if not user.visible() and user != GetCurrentUser(request):
        return redirect("/")
    return RenderToResponse("user/profile.html", request, {
        "url": user.profileUrl() if user else "/user/profile/",
        "prUser": user,
        "firsttime": params.get("firsttime", ""),
    })
예제 #8
0
파일: views.py 프로젝트: boomeer/tripnsale
def SalePreview(request, id):
    params = request.REQUEST
    sale = SaleOffer.objects.get(id=id)
    if not sale.visible():
        raise Exception("not found")

    return RenderToResponse(
        "offer/sale/preview.html", request, {
            "sale": sale,
            "editBackref": params.get("editBackref", ""),
            "connected": SaleIsConnected(request, id),
        })
예제 #9
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyOfferAddView(request):
    params = request.REQUEST
    act = params.get("act", "")
    owner = GetCurrentUser(request)
    if act == "add":
        try:
            CheckPost(request)
            CheckAuth(request)

            fr, to, title, costFrom, costTo = ExtractBuyFields(params)

            gallery = Gallery.objects.get(token=params.get("gallery", ""))
            buy = BuyOffer(
                title=title,
                ititle=title.lower(),
                content=params.get("content", ""),
                costFrom=costFrom,
                costTo=costTo,
                guarant=params.get("guarant", False),
                fr=fr,
                frCity=params.get("frCity", ""),
                ifrCity=params.get("frCity", "").lower(),
                to=to,
                toCity=params.get("toCity", ""),
                itoCity=params.get("toCity", "").lower(),
                gallery=gallery,
                owner=owner,
                createTime=datetime.now(),
            )
            buy.save()
            VerifyPhotos(params.get("token", ""))
            # backref = params.get("backref", "/offer/buy/list#buy{}".format(buy.id))
            if SaleExtractRecommend(buy, owner, limit=1):
                backref = "/offer/buy/recommend/{}?first_time=true".format(
                    buy.id)
            else:
                backref = "/offer/buy/list#buy{}".format(buy.id)
            return redirect(backref)
        except BuyEditErr as e:
            raise RedirectExc("/offer/buy/add?err={}".format(e.status))
    else:
        gallery = CreateGallery()
        token = GetNewId()
        return RenderToResponse(
            "offer/buy/add.html", request, {
                "url": "/offer/buy/add/",
                "gallery": gallery,
                "token": token,
                "countries": GetCountries(),
                "err": GetBuyEditMsg(params.get("err", ""))
            })
예제 #10
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyEditView(request, id):
    params = request.REQUEST
    act = params.get("act", "")
    buy = BuyOffer.objects.get(id=id)
    user = GetCurrentUser(request)
    if buy.owner != user:
        return redirect("/")
    if act == "edit":
        try:
            CheckPost(request)
            fr, to, title, costFrom, costTo = ExtractBuyFields(params)
            buy.title = title
            buy.content = params.get("content", "")
            buy.costFrom = costFrom
            buy.costTo = costTo
            buy.fr = fr
            buy.frCity = params.get("frCity", "")
            buy.ifrCity = params.get("frCity", "").lower()
            buy.to = to
            buy.toCity = params.get("toCity", "")
            buy.itoCity = params.get("toCity", "").lower()
            buy.guarant = params.get("guarant", False)
            buy.save()
            VerifyPhotos(params.get("token", ""))

            backref = params.get("backref",
                                 "/offer/buy/list/#buy{}".format(buy.id))
            return redirect(backref)
        except BuyEditErr as e:
            raise RedirectExc("/offer/buy/edit/{}?err={}".format(
                buy.id, e.status))
    elif act == "makeHead":
        pic = Photo.objects.get(id=params.get("picId"))
        pic.gallery.head = pic
        pic.gallery.save()
        backref = params.get("backref", "/offer/buy/edit/{}".format(buy.id))
        return redirect(backref)
    elif act == "erasePic":
        pic = Photo.objects.get(id=params.get("picId"))
        buy.gallery.er(pic)
        backref = params.get("backref", "/offer/buy/edit/{}".format(buy.id))
        return redirect(backref)
    return RenderToResponse(
        "offer/buy/edit.html", request, {
            "url": "/offer/buy/edit/{}/".format(buy.id),
            "buy": buy,
            "err": GetBuyEditMsg(params.get("err", "")),
            "token": GetNewId(),
            "countries": GetCountries(),
        })
예제 #11
0
파일: views.py 프로젝트: boomeer/tripnsale
def UsersFilterView(request):
    params = request.REQUEST
    users = User.objects.all()
    users = [ user for user in users if user.visible() ]
    count = int(params.get("count", 30))
    page = int(params.get("page", 0))
    totalpages = (len(users) + count - 1) // count
    block = users[page*count:(page + 1)*count]
    return RenderToResponse("user/filter.html", request, {
        "url": "/user/all",
        "users": users,
        "block": block,
        "page": page,
        "totalpages": totalpages,
        "pagesid": "users"
    })
예제 #12
0
파일: views.py 프로젝트: boomeer/tripnsale
def UserMailView(request):
    user = GetCurrentUser(request)
    confs = Conference.objects.filter(users=user).all()
    confs = [conf for conf in confs if conf.msgs.all()]
    confs.sort(key=lambda conf: conf.msgs.latest("time").time, reverse=True)
    for conf in confs:
        u = conf.users.all()
        try:
            conf.peer = u[0] if u[1] == user else u[1]
        except:
            raise Exception(len(u))
        conf.msg = conf.msgs.latest("time")
    return RenderToResponse("user/mail.html", request, {
        "url": "/user/mail",
        "confs": confs,
    })
예제 #13
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleOfferAddView(request):
    params = request.REQUEST
    act = params.get("act", "")
    owner = GetCurrentUser(request)
    if act == "add":
        try:
            CheckPost(request)
            CheckAuth(request)

            fr, to, frTime, toTime, deposit = ExtractSaleFields(params)
            sale = SaleOffer(
                content=params.get("content", ""),
                fr=fr,
                frCity=params.get("frCity", ""),
                ifrCity=params.get("frCity", "").lower(),
                frTime=frTime,
                to=to,
                toCity=params.get("toCity", ""),
                itoCity=params.get("toCity", "").lower(),
                toTime=toTime,
                deposit=deposit,
                guarant=params.get("guarant", False),
                owner=owner,
                createTime=datetime.now(),
            )
            sale.save()
            # backref = params.get("backref", "/offer/sale/list#trip{}".format(sale.id))
            if BuyExtractRecommend(sale, owner, limit=1):
                backref = "/offer/sale/recommend/{}?first_time=true".format(
                    sale.id)
            else:
                backref = "/offer/sale/list#trip{}".format(sale.id)
            return redirect(backref)
        except SaleEditErr as e:
            raise RedirectExc("/offer/sale/add/?err={}".format(e.status))
    else:
        return RenderToResponse(
            "offer/sale/add.html", request, {
                "url": "/offer/sale/add/",
                "countries": GetCountries(),
                "err": GetSaleAddMsg(params.get("err", ""))
            })
예제 #14
0
파일: views.py 프로젝트: boomeer/tripnsale
def UserRecoverView(request):
    params = request.REQUEST
    msg = ""
    msgErr = ""
    if request.method == "POST":
        email = params.get("email", "")
        user = User.objects.filter(username=email).all()
        if not user:
            msgErr = "user_does_not_exist"
        else:
            msg = "recover_ok"
            user = user[0]
            newPassword = GetNewId()[0:8]
            user.set_password(newPassword)
            user.save()
            SendRecoverMail(user, newPassword)
    return RenderToResponse("user/recover.html", request, {
        "msg": GetUserRecoverMsg(msg),
        "msgErr": GetUserRecoverMsg(msgErr),
    })
예제 #15
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleEditView(request, id):
    params = request.REQUEST
    sale = SaleOffer.objects.get(id=id)
    act = params.get("act", "")
    if sale.owner != GetCurrentUser(request):
        return redirect("/offer/sale/{}".format(id))
    if act == "edit":
        try:
            CheckPost(request)
            fr, to, frTime, toTime, deposit = ExtractSaleFields(params)

            sale.content = params.get("content", "")
            sale.fr = fr
            sale.frCity = params.get("frCity", "")
            sale.ifrCity = params.get("frCity", "").lower()
            sale.frTime = frTime
            sale.to = to
            sale.toCity = params.get("toCity", "")
            sale.itoCity = params.get("toCity", "").lower()
            sale.toTime = toTime
            sale.deposit = deposit
            sale.guarant = params.get("guarant", False)
            sale.save()
            backref = params.get("backref",
                                 "/offer/sale/list/#trip{}".format(sale.id))
            return redirect(backref)
        except SaleEditErr as e:
            raise RedirectExc("/offer/sale/edit/{}?err={}".format(
                sale.id, e.status))
    else:
        return RenderToResponse(
            "offer/sale/edit.html", request, {
                "sale": sale,
                "countries": GetCountries(),
                "err": GetSaleAddMsg(params.get("err", "")),
            })
예제 #16
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyListView(request):
    namespace = BuyFilterExtractParams(request, True)
    namespace["url"] = "/offer/buy/list"
    return RenderToResponse("offer/buy/list.html", request, namespace)
예제 #17
0
파일: views.py 프로젝트: boomeer/tripnsale
def UsersView(request):
    return RenderToResponse("user/list.html", request, {
        "url": "/user/all",
    })
예제 #18
0
파일: views.py 프로젝트: boomeer/tripnsale
def BuyFilterView(request):
    return RenderToResponse("offer/buy/filter.html", request,
                            BuyFilterExtractParams(request))
예제 #19
0
def MainView(request):
    return RenderToResponse("main/main.html", request, {
        "url": "/",
    })
예제 #20
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleFilterView(request):
    return RenderToResponse("offer/sale/filter.html", request,
                            SaleFilterExtractParams(request))
예제 #21
0
파일: views.py 프로젝트: boomeer/tripnsale
def ImView(request):
    params = request.REQUEST
    act = params.get("act", "")
    if act == "send":
        user = GetCurrentUser(request)
        content = params.get("content", "").strip()
        if not content:
            return JsonResponse({"result": "ok"})
        conf = Conference.objects.get(id=params.get("conf", 0))
        msg = ConferenceMsg(
            conf=conf,
            fr=user,
            content=content,
            time=datetime.now(),
        )
        msg.save()
        return JsonResponse({"result": "ok"})
    elif act == "askGuarant":
        conf = Conference.objects.get(id=params.get("conf"))
        if conf.askGuarant or conf.plusGuarant:
            raise Exception("bad request")
        conf.askGuarant = True
        conf.save()
        msg = SystemMsg(
            conf=conf,
            content="Запрос к гаранту отправлен",
            time=datetime.now(),
        )
        msg.save()
        return JsonResponse({"result": "ok"})
    else:
        if "conf" not in params:
            user = GetCurrentUser(request)
            peer = User.objects.get(id=params.get("peer", 0))
            buyId = params.get("buy", 0)
            saleId = params.get("sale", 0)
            conf = GetOrCreateDialog(GetCurrentUser(request), peer)
            offer = None
            if buyId:
                offer = BuyOffer.objects.get(id=buyId)
            elif saleId:
                offer = SaleOffer.objects.get(id=saleId)
            if offer and CheckConnection(user, offer):
                SendOfferMail(user, offer, conf)
                if type(offer) == BuyOffer:
                    oc = OfferConnection(
                        user=user,
                        buy=offer,
                    )
                    msg = SystemMsg(
                        conf=conf,
                        content='Приглашение к обсуждению заказа &laquo;<a target="_blank" href="/offer/buy/list/#buy{id}">{name}</a>&raquo;'.format(id=offer.id, name=offer.title),
                        time=datetime.now(),
                    )
                else:
                    oc = OfferConnection(
                        user=user,
                        sale=offer,
                    )
                    cont = \
                        "Приглашение к обсуждению поездки &laquo;<a target=\"_blank\" " + \
                        "href=\"/offer/sale/list/#sale{id}\">" + \
                        "{fr}{frcity} &rarr; {to}{tocity} (c {frTime} по {toTime})</a>&raquo;"
                    cont = cont.format(
                        id=offer.id,
                        fr=offer.fr.title,
                        frcity=" ({})".format(offer.frCity) if offer.frCity else "",
                        to=offer.to.title,
                        tocity=" ({})".format(offer.toCity) if offer.toCity else "",
                        frTime=offer.frTime.strftime("%d.%m.%Y"),
                        toTime=offer.toTime.strftime("%d.%m.%Y")
                    )
                    msg = SystemMsg(
                        conf=conf,
                        content=cont,
                        time=datetime.now(),
                    )
                oc.save()
                msg.save()
            return redirect("/user/im?conf={}".format(conf.id))
        conf = Conference.objects.get(id=params.get("conf", 0))
        user = GetCurrentUser(request)
        if not conf.users.filter(id=user.id):
            return redirect("/user/mail/")
        return RenderToResponse("user/im.html", request, {
            "conf": conf,
        })
예제 #22
0
파일: views.py 프로젝트: boomeer/tripnsale
def AuthView(request):
    params = request.REQUEST
    act = params.get("act", "")
    if act == "login":
        CheckPost(request)
        djUser = authenticate(
            username=params.get("email", "").lower(),
            password=params.get("password", ""),
        )
        user = GetUserByDjUser(djUser)
        if user:
            if not user.activated:
                raise RedirectExc("/user/auth?msgLogin=user_is_not_activated")
            user.remoteAddr = request.META["REMOTE_ADDR"]
            user.save()
            login(request, djUser)
        else:
            raise RedirectExc("/user/auth/?msgLogin=wrong_login_or_password")
        backref = params.get("next", "/")
        if not backref:
            backref = "/"
        return redirect(backref)
    elif act == "reg":
        try:
            CheckPost(request)
            if not params.get("firstName", "").strip() or not params.get("lastName", "").strip():
                raise RequiredFieldsMissingErr

            if params["password"] != params["password2"]:
                raise PasswordsAreNotEqualErr
            if not re.compile("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+$").match(params["email"]):
                raise EmailIsInvalidErr
            if not (3 <= len(params["password"]) <= 20):
                raise BadPasswordLengthErr
            if not params.get("offert", 0):
                raise OfferNotAgreedErr
            country = Country.objects.get(name=params.get("country", 0))

            if User.objects.filter(username=params["email"]).count():
                raise DuplicateEmailErr

            user = User.objects.create_user(
                params.get("email", "").lower(),
                params.get("email", "").lower(),
                params.get("password", ""),
                first_name=params.get("firstName", ""),
                last_name=params.get("lastName", ""),
                country=country,
                city=params.get("city", ""),
                remoteAddr=request.META["REMOTE_ADDR"],
                regRemoteAddr=request.META["REMOTE_ADDR"],
                activateCode=GetNewId(),
                activated=not settings.ENABLE_ACTIVATION,
            )
            user.save()

            if settings.ENABLE_ACTIVATION:
                SendActivateMail(user)
                return RenderToResponse("user/auth_success.html", request, {
                            "email": params.get("email", ""),
                        })
            else:
                user = authenticate(
                    username=user.username,
                    password=params.get("password", ""),
                )
                login(request, user)
                backref = params.get("next", "/user/profile/?firsttime=1")
                return redirect(backref)
        except RegErr as e:
            raise RedirectExc("/user/auth/?msgReg={}".format(e.status))
    return RenderToResponse("user/auth.html", request, {
        "countries": GetCountries(),
        "msgLogin": GetRegMsg(params.get("msgLogin", "")),
        "msgReg": GetRegMsg(params.get("msgReg", "")),
        "next": params.get("next", ""),
    })
예제 #23
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleOfferView(request, id):
    sale = SaleOffer.objects.get(exact__id=int(id))
    return RenderToResponse("offer/sale/view.html", request, {"sale": sale})
예제 #24
0
def AsksView(request):
    confs = Conference.objects.filter(askGuarant=True).all()
    return RenderToResponse("guarant/asks.html", request, {
        "confs": confs,
    })
예제 #25
0
파일: views.py 프로젝트: boomeer/tripnsale
def SaleListView(request):
    filterparams = SaleFilterExtractParams(request, static=True)
    filterparams.update({"url": "/offer/sale/list"})
    return RenderToResponse("offer/sale/list.html", request, filterparams)