def releaseBooking(request, pk): query_set = Booking.objects.filter(pk=pk) if len(query_set) != 1: return HttpResponseBadRequest() booking = query_set[0] today = datetime.date.today() # Delete if booking.fromDate > today: text = 'user {} deletes booking. asset {} from {} to {} for "{}"'.format( request.user, booking.asset.name, booking.fromDate, booking.toDate, booking.purpose) booking.delete() writelog(text) # Set toDate to today elif booking.toDate > today: if booking.shippingDate is not None: if booking.shippingDate > today: booking.shippingDate = today if booking.returnDate is not None: if booking.returnDate > today: booking.returnDate = today booking.toDate = today text = 'user {} releases booking. asset {} from {} to {} for "{}"'.format( request.user, booking.asset.name, booking.fromDate, booking.toDate, booking.purpose) booking.save() writelog(text) return HttpResponseRedirect(reverse_lazy('home'))
def form_valid(self, form): ins = form.instance text = 'user {} updates booking. asset {} from {} to {} for "{}"'.format( self.request.user, ins.asset.name, ins.fromDate, ins.toDate, ins.purpose) writelog(text) return super(BookingUpdateView, self).form_valid(form)
def form_invalid(self, form): username = form.data['username'] query = User.objects.filter(username=username) if len(query) == 0: text = 'Login failed. User "{}" does not exist.'.format(username) writelog(text) messages.error(self.request, text) else: user = query[0] if user.is_active: text = 'Login failed with user "{}". Password might be wrong.'.format( username) writelog(text) messages.error(self.request, text) else: text = 'User "{}" is inactive. Please contact admin to make active.'.format( username) writelog(text) messages.error(self.request, text) return super(LoginView, self).form_invalid(form)
def dispatch(self, request, *args, **kwargs): writelog('user {} logout'.format(self.request.user)) return super(LogoutView, self).dispatch(request, *args, **kwargs)
def form_valid(self, form): writelog('user {} login'.format(form.get_user())) return super(LoginView, self).form_valid(form)
def dispatch(self, request, *args, **kwargs): writelog('user {} updates his/her password'.format(self.request.user)) return super(PasswordChangeDoneView, self).dispatch(request, *args, **kwargs)
def form_valid(self, form): writelog('user {} updates his/her profile'.format(self.request.user)) return super(UserSelfUpdateView, self).form_valid(form)
def delete(self, request, *args, **kwargs): asset = Asset.objects.get(pk=self.kwargs['pk']) text = 'user {} deletes asset {}. modelNumber:{}, serialNumber:{}'.format( self.request.user, asset.name, asset.modelNumber, asset.serialNumber) writelog(text) return super(AssetDeleteView, self).delete(request, *args, **kwargs)
def form_valid(self, form): ins = form.instance text = 'user {} updates asset {}. modelNumber:{}, serialNumber:{}'.format( self.request.user, ins.name, ins.modelNumber, ins.serialNumber) writelog(text) return super(AssetUpdateView, self).form_valid(form)