Пример #1
0
def search(request):
    if request.method == 'POST':
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        result_list = BarterUser.getUserByNames(first_name, last_name)
        if (len(result_list) == 0):
            result_list = BarterUser.getUserByLastName(last_name)

        return render(request, 'searchResult.html',
                      {'result_list': result_list})
    else:
        return HttpResponseRedirect('/')
Пример #2
0
def make_transaction(request, want_id, for_id):
    me = BarterUser.getUserFromRequest(request)
    source_ann = Announcement.getAnnouncementById(for_id)
    target_ann = Announcement.getAnnouncementById(want_id)
    target_user = target_ann.user

    Transaction.createTransaction(
        me,
        target_user,
        Transaction.PENDING,
        source_ann,
        target_ann,
    )

    offer_subject = "Exchange Offer"
    body = "Not yet developed..."    

    Message.sendMessage(
        Message.OFFER,
        me,
        target_user,
        offer_subject,
        body,
    )
    return HttpResponseRedirect('/transactions/')
Пример #3
0
def offer_exchange(request, want_id):
    me = BarterUser.getUserFromRequest(request).id
    anns = Announcement.getUsersAnnouncements(me)
    
    return render(request, 'transactions/my_offers.html', {
        'announcements': anns,
        'want_id': want_id,
    })
Пример #4
0
def index(request):
    form = MessageForm()
    me = BarterUser.getUserFromRequest(request).id
    inbox = Message.getMessagesTo(me)
    outbox = Message.getMessagesFrom(me)
    return render(request, 'messages/index.html', {
        'form': form,
        'inbox': inbox,
        'outbox': outbox,
    })
Пример #5
0
def index(request):
    form = MessageForm()
    me = BarterUser.getUserFromRequest(request).id
    inbox = Message.getMessagesTo(me)
    outbox = Message.getMessagesFrom(me)
    return render(request, 'messages/index.html', {
        'form': form,
        'inbox': inbox,
        'outbox': outbox,
    })
Пример #6
0
def send(request):
    if request.method == 'POST':
        form = MessageForm(request.POST)
        if form.is_valid():
            recipient = form.cleaned_data['recipient']
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body']
            Message.sendMessage(Message.ORDINARY,
                                BarterUser.getUserFromRequest(request),
                                recipient, subject, body)
    return HttpResponseRedirect('/messages/')
Пример #7
0
def send(request):
    if request.method == 'POST':
        form = MessageForm(request.POST)
        if form.is_valid():
            recipient = form.cleaned_data['recipient']
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body']
            Message.sendMessage(
                Message.ORDINARY,
                BarterUser.getUserFromRequest(request),
                recipient,
                subject,
                body)
    return HttpResponseRedirect('/messages/')
Пример #8
0
def index(request):
    me = BarterUser.getUserFromRequest(request)
    finished_from_me = Transaction.getFinishedTransactionsFrom(me)
    finished_to_me = Transaction.getFinishedTransactionsTo(me)
    all_transactions = Transaction.getAllTransactionsFromAndTo(me)   
 
    pending_from_me = Transaction.getPendingTransactionsFrom(me)
    pending_to_me = Transaction.getPendingTransactionsTo(me)

    return render(request, 'transactions/index.html', {
        'finished_from_me': finished_from_me,
        'finished_to_me': finished_to_me,
        #'all_transactions': all_transactions,
        'pending_from_me': pending_from_me,
        'pending_to_me': pending_to_me,
    })
Пример #9
0
def add_announcement(request):
    print(request.POST.get("image", "ne ma :("))
    _user = BarterUser.getUserFromRequest(request)
    _title = request.POST.get('title')
    _content = request.POST.get('content')
    tagsStrList = request.POST.getlist('tag_list')
    tagsList = Tag.addTagsList(tagsStrList)
    newAnn = Announcement.createAnnouncement(_user, _title, _content, tagsList)
    if newAnn is not None:
        if request.FILES.get("image", ""):
            newImage = BarterImage.imageFromUpload(request.FILES["image"])
            print("upload successful")
            newAnn.setImage(newImage)
        # Should be "Announcement creation succcessful" or whatever
        return HttpResponseRedirect('/')
    else:
        # Should be "Announcement creation failed"
        return HttpResponseRedirect('/')
Пример #10
0
def add_announcement(request):
    print(request.POST.get("image", "ne ma :("))
    _user = BarterUser.getUserFromRequest(request)
    _title = request.POST.get('title')
    _content = request.POST.get('content')
    tagsStrList = request.POST.getlist('tag_list')
    tagsList = Tag.addTagsList(tagsStrList)
    newAnn = Announcement.createAnnouncement(_user, _title, _content, tagsList)
    if newAnn is not None:
        if request.FILES.get("image", ""):
            newImage = BarterImage.imageFromUpload(request.FILES["image"])
            print("upload successful")
            newAnn.setImage(newImage)
        # Should be "Announcement creation succcessful" or whatever
        return HttpResponseRedirect('/')
    else:
        # Should be "Announcement creation failed"
        return HttpResponseRedirect('/')
Пример #11
0
def reject(request, tid):
    t = Transaction.getTransactionById(tid)
    t.status = Transaction.REJECTED
    t.response_date = datetime.today()
    t.save()

    me = BarterUser.getUserFromRequest(request)
    target_user = t.source_ann.user

    subject = "Offer rejected"
    body = "Not yet deve;p[ed"
    Message.sendMessage(
        Message.OFFER,
        me,
        target_user,
        subject,
        body,
    )
    return HttpResponseRedirect('/transactions/')
Пример #12
0
 def setUp(self):
     self.testUser = BarterUser.createUser("testUser", "x", "x",
                                           "*****@*****.**", "x", "x", False)