|
| 1 | + |
| 2 | +# Create your views here. |
| 3 | +from django.contrib.auth.decorators import login_required |
| 4 | +from django.contrib.auth.mixins import LoginRequiredMixin |
| 5 | +from django.shortcuts import redirect |
| 6 | +from django.urls import reverse |
| 7 | +from django.views.generic import ListView, CreateView, UpdateView |
| 8 | + |
| 9 | +from aplicatie1.models import Locations |
| 10 | + |
| 11 | + |
| 12 | +class LocationsView(LoginRequiredMixin, ListView): |
| 13 | + model = Locations |
| 14 | + template_name = 'aplicatie1/locations_index.html' |
| 15 | + paginate_by = 5 |
| 16 | + |
| 17 | + |
| 18 | +class CreateLocationView(LoginRequiredMixin, CreateView): |
| 19 | + model = Locations |
| 20 | + fields = ['city', 'country'] |
| 21 | + template_name = 'aplicatie1/locations_form.html' |
| 22 | + |
| 23 | + def get_success_url(self): |
| 24 | + return reverse('locations:lista_locatii') |
| 25 | + |
| 26 | + |
| 27 | +class UpdateLocationView(LoginRequiredMixin, UpdateView): |
| 28 | + model = Locations |
| 29 | + fields = ['city', 'country'] |
| 30 | + template_name = 'aplicatie1/locations_form.html' |
| 31 | + |
| 32 | + def get_success_url(self): |
| 33 | + return reverse('locations:lista_locatii') |
| 34 | + |
| 35 | + |
| 36 | +@login_required |
| 37 | +def delete_location(request, pk): |
| 38 | + Locations.objects.filter(id=pk).update(active=0) |
| 39 | + return redirect('locations:lista_locatii') |
| 40 | + |
| 41 | + |
| 42 | +@login_required |
| 43 | +def activate_location(request, pk): |
| 44 | + Locations.objects.filter(id=pk).update(active=1) |
| 45 | + return redirect('locations:lista_locatii') |
0 commit comments