def list(request): """ The current set of locations. :param request: :return: """ all_locations = Location.objects.all() # build pagination location_pager = Paginator(all_locations, 5) page = request.GET.get("page") try: locations = location_pager.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. locations = location_pager.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. locations = location_pager.page(location_pager.num_pages) return render(request, "locations/list.html", context=fill_context({"locations": locations}))
def travel(request, ship_id): """ Travel options from a location. :param request: :param ship_id: :return: """ ship = get_object_or_404(Ship, pk=ship_id) location = ship.location # only owners can get the details on a ship if request.user.profile == ship.owner: if location.shipyards.count() == 0: location.add_shipyard() return render(request, "ships/travel.html", context=fill_context({ "ship": ship, "location": location })) else: return redirect(reverse("ships"))
def goods(request, ship_id, location_id): """ List the goods available to a ship at a location. :param request: :param ship_id: :param location_id: :return: """ ship = get_object_or_404(Ship, pk=ship_id) location = get_object_or_404(Location, pk=location_id) # are we actually at this location? if ship.location != location: return redirect(reverse("ship", args=(ship_id, ))) # does the user actually own this ship? if request.user.profile != ship.owner: return redirect(reverse("ships")) return render(request, "marketplace/goods.html", context=fill_context({ "ship": ship, "location": location }))
def profile(request): """ User profile. :param request: :return: """ return render(request, "accounts/profile.html", context=fill_context({}))
def list(request): """ The current set of ships. :param request: :return: """ all_ships = Ship.objects.order_by("value").all() return render(request, "ships/list.html", context=fill_context({"ships": all_ships}))
def index(request): """ :param request: :return: """ # let's get a count of our different location types location_counts = Location.objects.values("location_type").annotate( count=Count('id')) ctx = {"location_counts": location_counts} return render(request, "index.html", context=fill_context(ctx))
def detail(request, location_id): """ Detail of a location. :param request: :param location_id: :return: """ location = get_object_or_404(Location, pk=location_id) return render(request, "locations/detail.html", context=fill_context({"location": location}))
def detail(request, ship_id): """ Detail of a ships. :param request: :param planet_id: :return: """ ship = get_object_or_404(Ship, pk=ship_id) location = ship.location # only owners can get the details on a ship if request.user.profile == ship.owner: return render(request, "ships/detail.html", context=fill_context({ "ship": ship, "location": location })) else: return redirect(reverse("ships"))
def yard(request, ship_id, shipyard_id): """ List the contents of the shipyard :param request: :param ship_id: :param planet_id: :return: """ ship = get_object_or_404(Ship, pk=ship_id) shipyard = get_object_or_404(ShipYard, pk=shipyard_id) location = shipyard.location # are we actually at this planet? if ship.location != location: return redirect(reverse("ship", args=(ship_id,))) # does the user actually own this ship? if request.user.profile != ship.owner: return redirect(reverse("ships")) print "There are %d ships at the yard" % (shipyard.ships.count(),) return render(request, "shipyards/yard.html", context=fill_context({"ship": ship, "location": location, "shipyard": shipyard, "upgrade_blurb": ShipUpgrade.objects.upgrade_quality_blurb()}))