def home(request):
    new_claims = Service.getAllClaim()
    featured_claim = new_claims[0]
    hot_claims = Service.getAllClaim()
    help_titles = Service.getHelpTitleAsDict('home')
    help_descriptions = Service.getHelpDescriptionAsDict('home')
    return render(request, 'market/home.html', locals())
def claim_create(request):
    if request.method == 'POST':
        form = ClaimForm(request.POST)
        if form.is_valid():
            claim = form.save(commit=False)
            Service.createClaim(claim)
            return redirect('home')
    else:
        form = ClaimForm()
    return render(request, 'market/claim_create.html', locals())
def order_create(request, claim_id):
    claim = Service.getClaimById(claim_id)
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            Service.createOrder(order, claim, request.user.trader)
            return redirect('home')
    else:
        form = OrderForm()
    return render(request, 'market/order_create.html', locals())
def signup(request):
    if request.method == 'POST':
        traderform = TraderForm(request.POST)
        userform = UserForm(request.POST)
        if traderform.is_valid() and userform.is_valid():
            trader = traderform.save(commit=False)
            user = userform.save(commit=False)
            Service.createTrader(trader, user)
            return render(request, 'market/home.html')
    else:
        traderform = TraderForm()
        userform = UserForm()
    return render(request, 'market/signup.html', locals())
 def put(self, request, pk, format=None):
     Order = Service.getOrderById(pk)
     serializer = OrderSerializer(Order, data=request.DATA)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def claims(request):
    claims = Service.getAllClaim()
    return render(request, 'market/claims.html', locals())
def claim_info(request, id):
    claim = Service.getClaimById(id)
    return render(request, 'market/claim_info.html', locals())
def portfolio(request):
    holdings = Service.getAllHolding(request.user.trader)
    help_titles = Service.getHelpTitleAsDict('home')
    help_descriptions = Service.getHelpDescriptionAsDict('home')
    waiting_orders = Service.getAllOrder(request.user.trader)
    return render(request, 'market/portfolio.html', locals())
def leaderboard(request):
    trader_leaderboard = Service.getLeaderboard()
    return render(request, 'market/leaderboard.html', locals())
def dashboard_user(request):
    performance_data = Service.getDataChartPerformance(request.user.trader)
    return render(request, 'market/dashboard_user.html', locals())
 def delete(self, request, pk, format=None):
     Order = Service.getOrderById(pk)
     Service.deleteOrder(Order)
     return Response(status=status.HTTP_204_NO_CONTENT)
 def get(self, request, pk, format=None):
     Order = Service.getOrderById(pk)
     serializer = OrderSerializer(Order)
     return Response(serializer.data)
 def get(self, request, format=None):
     Orders = Service.getAllOrder()
     serializer = OrderSerializer(Orders, many=True)
     return Response(serializer.data)
 def delete(self, request, pk, format=None):
     claim = Service.getClaimById(pk)
     Service.deleteClaim(claim)
     return Response(status=status.HTTP_204_NO_CONTENT)
 def get(self, request, pk, format=None):
     Claim = Service.getClaimById(pk)
     serializer = ClaimSerializer(Claim)
     return Response(serializer.data)
 def get(self, request, format=None):
     claims = Service.getAllClaim()
     serializer = ClaimSerializer(claims, many=True)
     return Response(serializer.data)