Skip to content

Commit 38f4497

Browse files
author
Andres Vargas
committed
Organizacion deleted
1 parent 7952aa7 commit 38f4497

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

demo/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Contact(EntityMix):
3434

3535
class Meta:
3636
ordering = ("first_name", "last_name")
37+
3738
@property
3839
def name(self):
3940
return f"{self.first_name} {self.last_name}"

demo/static/src/Pages/Organizations.Edit.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<span class="text-indigo-400 font-medium">/</span>
66
{{ form.name }}
77
</h1>
8-
<trashed-message v-if="organization.deleted_at" class="mb-6" @restore="restore">
8+
<trashed-message v-if="organization.deleted" class="mb-6" @restore="restore">
99
This organization has been deleted.
1010
</trashed-message>
1111
<div class="bg-white rounded shadow overflow-hidden max-w-3xl">
@@ -111,17 +111,17 @@ export default {
111111
methods: {
112112
submit() {
113113
this.sending = true
114-
this.$inertia.put(this.route('demo:organizations.edit', this.organization.id), this.form)
114+
this.$inertia.post(this.route('demo:organizations.edit', this.organization.id), this.form)
115115
.then(() => this.sending = false)
116116
},
117117
destroy() {
118118
if (confirm('Are you sure you want to delete this organization?')) {
119-
this.$inertia.delete(this.route('organizations.destroy', this.organization.id))
119+
this.$inertia.delete(this.route('demo:organizations.edit', this.organization.id))
120120
}
121121
},
122122
restore() {
123123
if (confirm('Are you sure you want to restore this organization?')) {
124-
this.$inertia.put(this.route('organizations.restore', this.organization.id))
124+
this.$inertia.put(this.route('demo:organizations.edit', this.organization.id))
125125
}
126126
},
127127
},

demo/static/src/Pages/Organizations.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<td class="border-t">
2727
<inertia-link class="px-6 py-4 flex items-center focus:text-indigo-500" :href="route('demo:organizations.edit', organization.id)">
2828
{{ organization.name }}
29-
<icon v-if="organization.deleted_at" name="trash" class="flex-shrink-0 w-3 h-3 fill-gray-400 ml-2" />
29+
<icon v-if="organization.deleted" name="trash" class="flex-shrink-0 w-3 h-3 fill-gray-400 ml-2" />
3030
</inertia-link>
3131
</td>
3232
<td class="border-t">
@@ -88,7 +88,7 @@ export default {
8888
handler: throttle(function() {
8989
let query = pickBy(this.form)
9090
let url = this.route('demo:organizations') + "?";
91-
url += Object.keys(query).length ? "&search=" + query.search : "&remember=true"
91+
url += Object.keys(query).length ? "&search=" + query.search + "&trashed="+ query.trashed : "&remember=true"
9292
console.log("url", url);
9393
this.$inertia.replace(url)
9494

demo/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from inertia.share import share
22
from django.core.paginator import Paginator, EmptyPage
33
from django.urls import reverse
4-
4+
from django.db import models
55

66
def _filter(request, objects, filter_param):
77
trashed = request.GET.get("trashed","")
88
if trashed == "with":
9+
objects = objects.filter(models.Q(deleted=True)|models.Q(deleted=False))
10+
elif trashed == "only":
911
objects = objects.filter(deleted=True)
1012
search = request.GET.get("search", "")
11-
if search != "" and search !="undefined":
13+
if search =="undefined":
14+
search = ""
15+
if search != "":
1216
d = {filter_param: search}
1317
objects = objects.filter(**d)
1418
return objects

demo/views.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,39 @@
1515
def organization_edit(request, id):
1616
organization = Organization.objects.get(id=id)
1717
schema = OrganizationSchema()
18+
19+
if request.method == "POST":
20+
try:
21+
schema.loads(request.body)
22+
except ValidationError as err:
23+
share_flash(request, error="Exists errors on form")
24+
share_flash(request, errors= err.messages)
25+
else:
26+
Organization.objects.filter(id=id).update(**data)
27+
share_flash(request, success="Updated Organization")
28+
return redirect(reverse("demo:organizations"))
29+
if request.method == "DELETE":
30+
organization.deleted = True
31+
organization.save()
32+
share_flash(request, success="Organization Deleted")
33+
return redirect(reverse("demo:organizations"))
34+
if request.method == "PUT":
35+
organization.deleted = False
36+
organization.save()
37+
share_flash(request, success="Organization Undeleted")
38+
return redirect(reverse("demo:organizations"))
39+
40+
org = schema.dump(organization)
1841
props = {
19-
'organization': schema.dump(organization)
42+
'organization': org
2043
}
2144
return render_inertia(request, "Organizations.Edit", props)
2245

2346

2447
def organizations(request):
2548
org_sche = OrganizationSchema(many=True)
2649
objects = Organization.objects.all()
27-
_filter(request, objects, "name__icontains")
50+
objects = _filter(request, objects, "name__icontains")
2851
args = ("id","name", 'region','city','phone')
2952
objs, links = _get_objs(request, objects, args,"demo:organizations")
3053
trashed = request.GET.get("trashed","")
@@ -84,8 +107,6 @@ def contact_edit(request, id):
84107
share_flash(request, success="Contact Deleted")
85108
return redirect(reverse("demo:contacts"))
86109

87-
88-
89110
props = {
90111
'contact': c.dump(contact),
91112
'organizations': org_schema.dump(orgs)

0 commit comments

Comments
 (0)