def get(self, request, tool_id): curr_asset = get_object_or_404(Asset, pk=tool_id) form = MakeShareForm(user=request.user, asset=curr_asset) context = RequestContext(request, { 'isMember': is_member(user=request.user, location=curr_asset.location), 'form': form, 'tool_id': tool_id }) return render(request, self.template_name, context)
def post(self, request, shed_id): shedLocation = get_object_or_404(Location, pk=shed_id) if request.POST['requestMembership'] == '1': if is_member(user=request.user, location=shedLocation): messages.add_message(request, messages.WARNING, 'You already are a member of this shed', extra_tags='alert-success') return redirect('sharetools:shed', shed_id) else: messages.add_message(request, messages.SUCCESS, 'Your request has been sent', extra_tags='alert-success') set_user_role(user=request.user, role=Membership.REQUEST, location=shedLocation) return redirect('sharetools:shed', shed_id) else: return redirect('sharetools:shed', shed_id)
def get(self, request, tool_id): asset = get_object_or_404(Asset, pk=tool_id) sharedset = ShareContract.objects.filter(asset=tool_id, status=ShareContract.ACCEPTED) shared = None if (sharedset): shared = sharedset[0] context = RequestContext(request, { 'isMember': is_member(user=request.user, location=asset.location), 'user': request.user, 'asset': asset, 'shared': shared }) return render(request, self.template_name, context)
def post(self, request, tool_id): # Get the tool or 404 curr_asset = get_object_or_404(Asset, pk=tool_id) # Test if user has required permissions # Only members of the shed of the tool may borrow it if not is_member(user=request.user, location=curr_asset.location): messages.add_message(request, messages.WARNING, 'You do not have permission to borrow this tool.', extra_tags='alert-warning') return redirect('sharetools:shares') form = MakeShareForm(request.POST, user=request.user, asset=curr_asset) if form.is_valid(): messages.add_message(request, messages.SUCCESS, 'Share Contract Created Successfully.', extra_tags='alert-success') form.save() return redirect('sharetools:shares') messages.add_message(request, messages.SUCCESS, 'Please enter a valid date.', extra_tags='alert-warning') return redirect('sharetools:makeShareContract', tool_id)
def get(self, request, shed_id): shedLocation = get_object_or_404(Location, pk=shed_id) role = get_user_role(location=shedLocation, user=request.user) assets = Asset.objects.filter(location=shedLocation).order_by('type') user_assets = Asset.objects.filter(owner=request.user, isAvailable=True) try: membership = Membership.objects.get(location=shedLocation, user=request.user) except Membership.DoesNotExist: membership = None context = RequestContext(request, { 'assets': assets, 'location': shedLocation, 'isMember': is_member(user=request.user, location=shedLocation), 'isMod': is_mod(user=request.user, location=shedLocation), 'membership': membership, 'userAssets':user_assets }) return render(request, self.template_name, context_instance=context)