LIL-582, contest works autoload on scroll, check that user uploaded work and etc

remotes/origin/hotfix/LIL-661
gzbender 8 years ago
parent e2671221cb
commit 4c97c791d8
  1. 2
      api/v1/serializers/contest.py
  2. 5
      api/v1/views.py
  3. 5
      apps/content/templates/content/contest.html
  4. 33
      web/src/components/ContestWorks.vue

@ -64,7 +64,5 @@ class ContestWorkCreateSerializer(serializers.ModelSerializer):
model = ContestWork
fields = '__all__'
# TODO check ContestWork.objects.filter(user=self.request.user).exists()
def to_representation(self, instance):
return ContestWorkSerializer(instance=instance, context=self.context).to_representation(instance)

@ -469,3 +469,8 @@ class ContestWorkViewSet(ExtendedModelViewSet):
'retrieve': ContestWorkSerializer,
}
filter_fields = ('contest',)
def create(self, request, *args, **kwargs):
if ContestWork.objects.filter(user=request.user).exists():
return Response(status=status.HTTP_400_BAD_REQUEST)
return super().create(request, *args, **kwargs)

@ -33,11 +33,8 @@
</a>
<div class="text">
</div>
<contest-works contest-id="{{ contest.id }}"></contest-works>
<contest-works contest-id="{{ contest.id }}" autoload="true"></contest-works>
</div>
</div>
</div>
{% endblock content %}
{% block foot %}
{% endblock foot %}

@ -6,24 +6,51 @@
<script>
import {api} from "../js/modules/api";
import $ from 'jquery';
import ContestWork from "./blocks/ContestWork.vue";
export default {
name: "contest-works",
props: ['contestId'],
props: ['contestId', 'autoload'],
data(){
return {
page: 1,
lastPage: null,
loading: false,
contestWorks: [],
};
},
mounted() {
this.load();
if(this.autoload) {
$(window).scroll(() => {
const pos = $(this.$el).offset().top + this.$el.clientHeight - 100;
if($(window).scrollTop() + $(window).height() >= pos
&& !this.loading && !this.lastPage) {
this.page += 1;
this.load();
}
});
}
},
methods: {
load() {
api.get(`/api/v1/contest-works/?contest=${this.contestId}`)
this.loading = true;
api.get(`/api/v1/contest-works/?contest=${this.contestId}&page=${this.page}`)
.then((response) => {
this.contestWorks = response.data.results;
this.loading = false;
if(this.page > 1){
this.contestWorks.concat(response.data.results);
}
else{
this.contestWorks = response.data.results;
}
})
.catch((response) => {
this.loading = false;
if(response.response.status == 404){
this.lastPage = this.page;
}
});
}
},

Loading…
Cancel
Save