Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
Make change button work in client list
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniak274 committed Dec 7, 2019
1 parent 3a06769 commit 730b547
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
3 changes: 0 additions & 3 deletions ebiznes/apps/service/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class Meta:
fields = ('pk', 'created', 'service', 'user', 'modified',
'status', 'phone_number', 'address', 'service_name', 'status_display',
'total_price', 'user_id')
extra_kwargs = {
'service': {'write_only': True},
}

def get_status_display(self, obj):
return obj.get_status_display()
Expand Down
1 change: 1 addition & 0 deletions ebiznes/apps/service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
path('price-list/', views.CreatePriceListRecord.as_view(), name='price-list'),
path('price-list/remove/<int:pk>/', views.RemovePriceListRecord.as_view(), name='remove-price-list'),
path('price-list/update/<int:pk>/', views.UpdatePriceListRecord.as_view(), name='update-price-list'),
path('rents/<int:pk>/', views.UpdateRentView.as_view(), name='update-rent'),
] + router.urls
12 changes: 12 additions & 0 deletions ebiznes/apps/service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ def check_object_permissions(self, request, obj):

if not obj.service.owner == request.user:
raise PermissionDenied()


class UpdateRentView(UpdateAPIView):
permission_classes = [IsAuthenticated]
serializer_class = RentSerializer
queryset = Rent.objects.all()

def check_objectt_permissions(self, request, obj):
super().check_object_permissions(request, obj)

if not obj.service.owner == request.user:
raise PermissionDenied()
46 changes: 41 additions & 5 deletions ebiznes/assets/components/ClientList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<b-button
type="is-primary"
expanded
@click="change(props.row.pk)"
@click="change(props.row)"
>Zmień</b-button>
</div>
</div>
Expand All @@ -93,8 +93,6 @@ export default {
rents: [],
next: null,
pervious: null,
current_status: '',
current_price: '',
options: [
{
'value': 'WAITING_FOR_APPROVAL',
Expand All @@ -121,8 +119,46 @@ export default {
},
methods: {
change: function(pk) {
change: function(row) {
const {
pk,
address,
phone_number,
service,
user,
status,
total_price,
} = row;
const payload = {
address,
phone_number,
service,
user_id: user.pk,
status,
total_price,
};
axios.put(
`/api/services/rents/${pk}/`,
payload,
this.axiosConfig,
).then(response => {
this.$buefy.snackbar.open({
duration: 3000,
message: 'Zmiany zostaly zapisane',
type: 'is-success',
position: 'is-top',
});
}).catch(error => {
const data = Object.values(error.response.data)
.reduce((acc, item) => {
acc += item.join(' ');
return acc;
}, '')
this.$toastr.e(data)
})
}
},
Expand Down

0 comments on commit 730b547

Please sign in to comment.