def video_url_remove(request): output = {} id = request.POST.get('id') status = 200 if id: try: obj = VideoUrl.objects.get(id=id) tv = obj.video.get_team_video() if tv and not permissions.can_user_edit_video_urls(obj.video, request.user): output['error'] = ugettext('You have not permission delete this URL') status = 403 else: if obj.primary: output['error'] = ugettext('You can\'t remove primary URL') status = 403 else: # create activity record act = Action(video=obj.video, action_type=Action.DELETE_URL) act.new_video_title = obj.url act.created = datetime.datetime.now() act.user = request.user act.save() # delete obj.delete() except VideoUrl.DoesNotExist: output['error'] = ugettext('Object does not exist') status = 404 return HttpResponse(json.dumps(output), status=status)
def clean(self): data = super(CreateVideoUrlForm, self).clean() video = data.get('video') if video and not can_user_edit_video_urls(video, self.user): raise forms.ValidationError(_('You have not permission add video URL for this video')) return self.cleaned_data
def video_url_make_primary(request): output = {} id = request.POST.get('id') status = 200 if id: try: obj = VideoUrl.objects.get(id=id) tv = obj.video.get_team_video() if tv and not permissions.can_user_edit_video_urls(obj.video, request.user): output['error'] = ugettext('You have not permission change this URL') status = 403 else: obj.make_primary(user=request.user) except VideoUrl.DoesNotExist: output['error'] = ugettext('Object does not exist') status = 404 return HttpResponse(json.dumps(output), status=status)