Запись в БД из Обратной связи
This commit is contained in:
1 parent
beb6744894
commit
d4099e264d
5 files changed
+111
-128
No files matched your search
BIN
Binary file not shown.
+1
-1
@@ -16,7 +16,7 @@ class BaseCriteria(models.Model):
|
|||||||
class UserComment(models.Model):
|
class UserComment(models.Model):
|
||||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, editable=False, on_delete=models.PROTECT)
|
||||||
time_create = models.DateTimeField(auto_now_add = True)
|
time_create = models.DateTimeField(auto_now_add = True)
|
||||||
comment = models.TextField(null=True)
|
comment = models.TextField(null=True, blank = False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Комментарий пользователя"
|
verbose_name = "Комментарий пользователя"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class BaseCriteriaSerializer(serializers.ModelSerializer):
|
|||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
class UserCommentSerializer(serializers.ModelSerializer):
|
class UserCommentSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserComment
|
model = UserComment
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
+4
-4
@@ -5,7 +5,7 @@ from django.forms.models import model_to_dict
|
|||||||
from accounts.models import User
|
from accounts.models import User
|
||||||
|
|
||||||
from navigation.views import LinkAPIView
|
from navigation.views import LinkAPIView
|
||||||
|
import datetime
|
||||||
from .serializers import *
|
from .serializers import *
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
@@ -14,7 +14,8 @@ class FormFeedAPI(LinkAPIView):
|
|||||||
serializer_class1 = BaseCriteriaSerializer
|
serializer_class1 = BaseCriteriaSerializer
|
||||||
serializer_class2 = UserCommentSerializer
|
serializer_class2 = UserCommentSerializer
|
||||||
queryset1 = BaseCriteria.objects.all()
|
queryset1 = BaseCriteria.objects.all()
|
||||||
queryset2 = UserComment.objects.filter(user_id=request.user.id)
|
queryset2 = UserComment.objects.filter(user_id=request.user.id, time_create__contains=datetime.date.today())
|
||||||
|
print(queryset2)
|
||||||
baseCriteria = serializer_class1(queryset1, many=True)
|
baseCriteria = serializer_class1(queryset1, many=True)
|
||||||
userComment = serializer_class2(queryset2, many=True)
|
userComment = serializer_class2(queryset2, many=True)
|
||||||
return Response({'baseCriteria':baseCriteria.data, 'userComment':userComment.data})
|
return Response({'baseCriteria':baseCriteria.data, 'userComment':userComment.data})
|
||||||
@@ -22,10 +23,9 @@ class FormFeedAPI(LinkAPIView):
|
|||||||
class CommentAPI(ListCreateAPIView):
|
class CommentAPI(ListCreateAPIView):
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
comid = UserComment.objects.create(user_id = request.user.id, comment = request.data['usercomment'])
|
comid = UserComment.objects.create(user_id = request.user.id, comment = request.data['comment'])
|
||||||
for x in request.data['ratingstatus']:
|
for x in request.data['ratingstatus']:
|
||||||
RatingStatus.objects.create(crit_id=x['id'], rating = x['rating'], usercom_id= comid.id)
|
RatingStatus.objects.create(crit_id=x['id'], rating = x['rating'], usercom_id= comid.id)
|
||||||
|
|
||||||
return Response(print('Запись создана в таблицу feedback_usercomment'))
|
return Response(print('Запись создана в таблицу feedback_usercomment'))
|
||||||
|
|
||||||
|
|
||||||
+105
-123
@@ -3,15 +3,11 @@
|
|||||||
<v-card-title>
|
<v-card-title>
|
||||||
<span class="text-h5">Обратная связь</span>
|
<span class="text-h5">Обратная связь</span>
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
|
|
||||||
<v-card-text class="px-2 py-0">
|
<v-card-text class="px-2 py-0">
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col class="flex-grow-0 py-0 text-no-wrap align-self-center text-button">Оцените сайт
|
<v-col class="flex-grow-0 py-0 text-no-wrap align-self-center text-button">
|
||||||
<!-- <my-helper
|
Оцените сайт
|
||||||
:pretext = "result.data"
|
|
||||||
/> -->
|
|
||||||
|
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-divider/>
|
<v-divider/>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -19,83 +15,69 @@
|
|||||||
v-for="(x, key) in tab_baseCriteria"
|
v-for="(x, key) in tab_baseCriteria"
|
||||||
:key = key
|
:key = key
|
||||||
>
|
>
|
||||||
<v-col class="flex-grow-0 pb-0">
|
<v-col class="flex-grow-0 pb-0">
|
||||||
<v-icon
|
<v-icon
|
||||||
|
size="large"
|
||||||
size="large"
|
:color="x.color"
|
||||||
:color="x.color"
|
:icon="x.ico"
|
||||||
:icon="x.ico"
|
/>
|
||||||
|
</v-col>
|
||||||
/>
|
|
||||||
</v-col>
|
|
||||||
<v-col class="pb-0" lg=3>
|
<v-col class="pb-0" lg=3>
|
||||||
|
|
||||||
{{x.name}}
|
{{x.name}}
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col class="py-0">
|
<v-col class="py-0">
|
||||||
<v-rating
|
<v-rating
|
||||||
v-model="x.rating"
|
v-model="x.rating"
|
||||||
hover
|
hover
|
||||||
half-increments
|
half-increments
|
||||||
size="small"
|
size="small"
|
||||||
color="yellow-darken-3"
|
color="yellow-darken-3"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-divider/>
|
<v-divider/>
|
||||||
</v-row >
|
</v-row >
|
||||||
<!-- <v-row>
|
<v-row class="mt-6">
|
||||||
<v-divider/>
|
<v-col class="pa-0 px-3">
|
||||||
<v-col class="px-3 ">
|
<v-textarea
|
||||||
{{myLabel()}}
|
label="Ваши комментарии сделают портал лучше"
|
||||||
</v-col>
|
hide-details
|
||||||
<v-divider/>
|
variant="outlined"
|
||||||
</v-row> -->
|
rows="5"
|
||||||
|
row-height="15"
|
||||||
<v-row class="mt-6">
|
v-model="comment"
|
||||||
<v-col class="pa-0 px-3">
|
/>
|
||||||
<v-textarea
|
</v-col>
|
||||||
label="Ваши комментарии сделают портал лучше"
|
</v-row>
|
||||||
hide-details
|
</v-container>
|
||||||
variant="outlined"
|
</v-card-text>
|
||||||
rows="5"
|
<v-card-actions class="pt-0">
|
||||||
row-height="15"
|
<small v-if="average < 5 || comment.length > 0" class="pl-5">
|
||||||
v-model="comment"
|
Вы оценили сайт на <span class="font-weight-black">{{average}}</span> {{myLabel()}}
|
||||||
/>
|
</small>
|
||||||
</v-col>
|
<v-spacer/>
|
||||||
</v-row>
|
<v-btn
|
||||||
</v-container>
|
|
||||||
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions class="pt-0">
|
|
||||||
<div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<small v-if="average < 5 || comment.length > 0" class="pl-5">
|
|
||||||
Вы оценили сайт на <span class="font-weight-black">{{average}}</span> {{myLabel()}} </small>
|
|
||||||
<v-spacer/>
|
|
||||||
<v-btn
|
|
||||||
color="blue-darken-1"
|
|
||||||
variant="text"
|
|
||||||
@click="menusCloses"
|
|
||||||
>
|
|
||||||
Закрыть
|
|
||||||
|
|
||||||
|
|
||||||
</v-btn>
|
|
||||||
<v-btn
|
|
||||||
color="blue-darken-1"
|
|
||||||
variant="text"
|
|
||||||
@click="feedAll"
|
|
||||||
|
|
||||||
>
|
|
||||||
Отправить
|
|
||||||
</v-btn>
|
|
||||||
|
|
||||||
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
|
|
||||||
|
|
||||||
|
color="blue-darken-1"
|
||||||
|
variant="text"
|
||||||
|
text="Закрыть"
|
||||||
|
@click="menusCloses"
|
||||||
|
/>
|
||||||
|
<v-btn
|
||||||
|
v-if="tab_userComment.length=0"
|
||||||
|
color="blue-darken-1"
|
||||||
|
variant="text"
|
||||||
|
text="Отправить"
|
||||||
|
@click="feedAll"
|
||||||
|
/>
|
||||||
|
<v-btn
|
||||||
|
v-else
|
||||||
|
color="blue-darken-1"
|
||||||
|
variant="text"
|
||||||
|
text="Обновить"
|
||||||
|
@click="feedAll"
|
||||||
|
/>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -115,57 +97,57 @@ export default {
|
|||||||
const tab_baseCriteria = ref([])
|
const tab_baseCriteria = ref([])
|
||||||
const tab_userComment = ref([])
|
const tab_userComment = ref([])
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
axiosApiInstance.get('api/feedback/formfeed/')
|
axiosApiInstance.get('api/feedback/formfeed/')
|
||||||
.then(data => {
|
.then(data => {
|
||||||
tab_baseCriteria.value = data.data.baseCriteria
|
tab_baseCriteria.value = data.data.baseCriteria
|
||||||
tab_userComment.value = data.data.userComment
|
tab_userComment.value = data.data.userComment
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
function feedAll() {
|
|
||||||
const feedObj = {}
|
|
||||||
feedObj.ratingstatus = ratingStatus.value.decFeed
|
|
||||||
feedObj.usercomment = comment.value
|
|
||||||
// axiosApiInstance.post('api/feedback/comment/', feedObj)
|
|
||||||
comment.value=""
|
|
||||||
tab_baseCriteria.value.map(e=>e.rating=5)
|
|
||||||
}
|
|
||||||
|
|
||||||
const ratingStatus = computed(() => {
|
|
||||||
const decFeed = []
|
|
||||||
tab_baseCriteria.value.map(e =>
|
|
||||||
{
|
|
||||||
const { id, rating } = {...e}
|
|
||||||
decFeed.push({id:id, rating:rating})
|
|
||||||
});
|
|
||||||
return { decFeed }
|
|
||||||
});
|
|
||||||
|
|
||||||
const average = computed(()=> {
|
|
||||||
const sum = tab_baseCriteria.value.reduce((total, obj)=> total + obj.rating, 0)
|
|
||||||
const sumlen = sum/tab_baseCriteria.value.length
|
|
||||||
const ukr = Number.isInteger(sumlen)?sumlen:sumlen.toFixed(1)
|
|
||||||
return ukr
|
|
||||||
})
|
|
||||||
|
|
||||||
function myLabel() {
|
|
||||||
let labels = ''
|
|
||||||
if (average.value > 0 && average.value <= 3)
|
|
||||||
labels = 'УПС-С! Мы обязательно все исправим'
|
|
||||||
else if (average.value > 2 && average.value <= 4)
|
|
||||||
labels = 'Спасибо за обратную связь, мы обратим на это внимание'
|
|
||||||
else if (average.value > 4 && average.value < 5)
|
|
||||||
labels = 'Класс, будем стараться до 5'
|
|
||||||
else
|
|
||||||
labels = "Спасибо за отзыв и высокую оценку ^__^"
|
|
||||||
return labels
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
function menusCloses() {
|
function feedAll() {
|
||||||
context.emit('menusClose')
|
const feedObj = {}
|
||||||
}
|
// feedObj.ratingstatus = ratingStatus.value.decFeed
|
||||||
|
feedObj.comment = comment.value
|
||||||
|
axiosApiInstance.post('api/feedback/comment/', feedObj)
|
||||||
|
comment.value=""
|
||||||
|
tab_baseCriteria.value.map(e=>e.rating=5)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ratingStatus = computed(() => {
|
||||||
|
const decFeed = []
|
||||||
|
tab_baseCriteria.value.map(e =>
|
||||||
|
{
|
||||||
|
const { id, rating } = {...e}
|
||||||
|
decFeed.push({id:id, rating:rating})
|
||||||
|
});
|
||||||
|
return { decFeed }
|
||||||
|
});
|
||||||
|
|
||||||
|
const average = computed(()=> {
|
||||||
|
const sum = tab_baseCriteria.value.reduce((total, obj)=> total + obj.rating, 0)
|
||||||
|
const sumlen = sum/tab_baseCriteria.value.length
|
||||||
|
const ukr = Number.isInteger(sumlen)?sumlen:sumlen.toFixed(1)
|
||||||
|
return ukr
|
||||||
|
})
|
||||||
|
|
||||||
|
function myLabel() {
|
||||||
|
let labels = ''
|
||||||
|
if (average.value > 0 && average.value <= 3)
|
||||||
|
labels = 'УПС-С! Мы обязательно все исправим'
|
||||||
|
else if (average.value > 2 && average.value <= 4)
|
||||||
|
labels = 'Спасибо за обратную связь, мы обратим на это внимание'
|
||||||
|
else if (average.value > 4 && average.value < 5)
|
||||||
|
labels = 'Класс, будем стараться до 5'
|
||||||
|
else
|
||||||
|
labels = "Спасибо за отзыв и высокую оценку ^__^"
|
||||||
|
return labels
|
||||||
|
}
|
||||||
|
|
||||||
|
function menusCloses() {
|
||||||
|
context.emit('menusClose')
|
||||||
|
}
|
||||||
|
|
||||||
return {tab_baseCriteria, tab_userComment, comment, average, feedAll, menusCloses, myLabel}
|
return {tab_baseCriteria, tab_userComment, comment, average, feedAll, menusCloses, myLabel}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user