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('/')
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/')
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, })
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, })
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/')
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/')
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, })
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('/')
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/')
def setUp(self): self.testUser = BarterUser.createUser("testUser", "x", "x", "*****@*****.**", "x", "x", False)