def push_tag(request, object_id): # Link used for User follow tag try: tag = Tag.objects.get(id=object_id) ctype = ContentType.objects.get_for_model(Tag) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, tag) action.send(request.user, verb=_("unfollow the tag"), target=tag) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_("now follow"), target=tag) else: follow(request.user, tag) status = True action.send( request.user, verb=_("follow the tag"), action_type=ACTION_FOLLOWED, target=tag, request=request ) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=tag.pk).count: notice.send(request.user, user=u, verb=_("also now follow"), target=tag) else: notice.send(request.user, user=u, verb=_("now follow"), target=tag) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {"success": True, "count": result, "id": tag.pk, "status": status} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def push_user(request, object_id): # Link used for User press button in user panel try: user = get_user_model().objects.get(id=object_id) if request.user == user: raise AccessError ctype = ContentType.objects.get_for_model(get_user_model()) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, user) action.send(request.user, verb=_("unfollow the user"), target=user) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_("now unfollow"), target=user) else: follow(request.user, user) status = True action.send(request.user, verb=_("follow the user"), target=user) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=user.pk).count: notice.send(request.user, user=u, verb=_("also now follow"), target=user) else: notice.send(request.user, user=u, verb=_("now follow"), target=user) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {"success": True, "count": result, "id": user.pk, "status": status} except AccessError: payload = {"success": False} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def push_video(request, object_id): # Link used for User press Like on Video Detail Page try: video = get_object_or_404(Video, id=int(object_id)) ctype = ContentType.objects.get_for_model(Video) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): if unfollow(request.user, video): # action.send(request.user, verb=_('disliked the video'), target=video) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_("now disliked"), target=video) else: if follow(request.user, video): status = True action.send( request.user, verb=_("liked the video"), action_type=ACTION_LIKED, target=video, request=request ) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=video.pk).count: notice.send(request.user, user=u, verb=_("also now liked"), target=video) else: notice.send(request.user, user=u, verb=_("now liked"), target=video) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {"success": True, "count": result, "id": video.pk, "status": status} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def form_valid(self, form): link = form.cleaned_data.get('video_url') consumer = oembed.OEmbedConsumer(link) result = consumer.result() obj = Video() obj.embedcode = result['html'] obj.thumbnail = image_from_url(result['thumbnail_url']) if 'duration' in result: obj.duration = result['duration'] obj.user = self.request.user obj.project_name = form.cleaned_data.get('project_name') obj.project_url = form.cleaned_data.get('project_url') obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url')) obj.publish = True obj.description = form.cleaned_data.get('description') obj.video_url = link obj.save() obj.slug = gen_shortcut(obj.id) tags = form.cleaned_data.get('tags') alltags = Tag.objects.all().filter(name__in=tags) for tag in tags: obj.tags.add(alltags.get(name=tag)) obj.save() self.success_url = obj.get_absolute_url() action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj, request=self.request) return super(VideoAdd, self).form_valid(form)
def flat_comment_add(request, content_type, object_id): """ Its Ajax flat posted comments """ # noinspection PyBroadException try: if not request.user.is_authenticated: raise AccessError comment = FlatNnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id( int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST['comment'] if not len(comment.comment): raise AccessError kwargs = {'content_type': content_type, 'object_id': object_id} comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) html = render_to_string('comments/item_comment.html', {'comment': comment}) payload = dict(success=True, html=html) except AccessError as aerr: payload = dict(success=False, error=_('You are not allowed for add comment')) except: payload = dict(success=False) return ajax_answer_lazy(payload)
def flat_comment_add(request, content_type, object_id): """ Its Ajax flat posted comments """ # noinspection PyBroadException try: if not request.user.is_authenticated(): raise AccessError comment = FlatNnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id(int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST['comment'] if not len(comment.comment): raise AccessError kwargs = {'content_type': content_type, 'object_id': object_id} comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) html = render_to_string('comments/item_comment.html', {'comment': comment}) payload = {'success': True, 'html': html} except AccessError as aerr: payload = {'success': False, 'error': _('You are not allowed for add comment')} except: payload = {'success': False} return ajax_answer_lazy(payload)
def push_tag(request, object_id): # Link used for User follow tag # noinspection PyBroadException try: tag = Tag.objects.get(id=object_id) ctype = ContentType.objects.get_for_model(Tag) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, tag) action.send(request.user, verb=_('unfollow the tag'), target=tag) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now follow'), target=tag) else: follow(request.user, tag) status = True action.send(request.user, verb=_('follow the tag'), action_type=ACTION_FOLLOWED, target=tag, request=request) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=tag.pk).count: notice.send(request.user, user=u, verb=_('also now follow'), target=tag) else: notice.send(request.user, user=u, verb=_('now follow'), target=tag) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {'success': True, 'count': result, 'id': tag.pk, 'status': status} except: payload = {'success': False} return ajax_answer_lazy(payload)
def comment_add(request, content_type, object_id, parent_id=None): # noinspection PyBroadException try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id(int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST.get('comment') or None depth = int(request.POST.get('depth')) if len(comment.comment) < 1: raise AccessError if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) newcomment = copy.deepcopy(comment) newcomment.depth = depth html = render_to_string('comments/comment_one.html', {'comment': newcomment, 'user': request.user}) payload = {'success': True, 'html': html, 'object_comments': comment.content_object.comments} except AccessError as aerr: payload = {'success': False, 'error': 'You are not allowed for add comment'} except: payload = {'success': False} return ajax_answer_lazy(payload)
def push_user(request, object_id): # Link used for User press button in user panel # noinspection PyBroadException try: user = get_user_model().objects.get(id=object_id) if request.user == user: raise AccessError ctype = ContentType.objects.get_for_model(get_user_model()) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, user) action.send(request.user, verb=_('unfollow the user'), target=user) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now unfollow'), target=user) else: follow(request.user, user) status = True action.send(request.user, verb=_('follow the user'), target=user) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=user.pk).count: notice.send(request.user, user=u, verb=_('also now follow'), target=user) else: notice.send(request.user, user=u, verb=_('now follow'), target=user) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {'success': True, 'count': result, 'id': user.pk, 'status': status} except AccessError as aerr: payload = {'success': False} except: payload = {'success': False} return ajax_answer_lazy(payload)
def push_user(request, object_id): # Link used for User press button in user panel try: user = settings.AUTH_USER_MODEL.objects.get(id=object_id) if request.user == user: raise AccessError ctype = ContentType.objects.get_for_model(settings.AUTH_USER_MODEL) status = False if Follow.objects.filter(user=request.user,content_type=ctype,object_id=object_id).count(): unfollow(request.user, user) action.send(request.user, verb=_('unfollow the user'), target=user) if request.user.get_profile().followers_count: for u in settings.AUTH_USER_MODEL.objects.filter(pk__in=request.user.get_profile().followers): notice.send(request.user, user=u, verb=_('now unfollow'), target=user) else: follow(request.user, user) status = True action.send(request.user, verb=_('follow the user'), target=user) if request.user.get_profile().followers_count: for u in settings.AUTH_USER_MODEL.objects.filter(pk__in=request.user.get_profile().followers): if u.follow_set.filter(content_type=ctype, object_id=user.pk).count: notice.send(request.user, user=u, verb=_('also now follow'), target=user) else: notice.send(request.user, user=u, verb=_('now follow'), target=user) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {'success': True, 'count': result, 'id': user.pk, 'status':status} except AccessError: payload = {'success': False} except : payload = {'success': False} return AjaxLazyAnswer(payload)
def push_video(request, object_id): # Link used for User press Like on Video Detail Page # noinspection PyBroadException try: video = get_object_or_404(Video, id=int(object_id)) ctype = ContentType.objects.get_for_model(Video) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): if unfollow(request.user, video): # action.send(request.user, verb=_('disliked the video'), target=video) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now disliked'), target=video) else: if follow(request.user, video): status = True action.send(request.user, verb=_('liked the video'), action_type=ACTION_LIKED, target=video, request=request) if request.user.followers_count: for u in get_user_model().objects.filter(pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=video.pk).count: notice.send(request.user, user=u, verb=_('also now liked'), target=video) else: notice.send(request.user, user=u, verb=_('now liked'), target=video) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = {'success': True, 'count': result, 'id': video.pk, 'status': status} except: payload = {'success': False} return ajax_answer_lazy(payload)
def flat_comment_add(request, content_type, object_id): """ Its Ajax flat posted comments """ try: if not request.user.is_authenticated(): raise AccessError comment = FlatNnmcomment() comment.user = request.user comment.content_type = get_object_or_404(ContentType, id=int(content_type)) comment.object_id = int(object_id) comment.ip = request.META["REMOTE_ADDR"] comment.user_agent = request.META["HTTP_USER_AGENT"] comment.comment = request.POST["comment"] if not len(comment.comment): raise AccessError kwargs = {"content_type": content_type, "object_id": object_id} comment.save() action.send( request.user, verb=_("commented"), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request, ) html = render_to_string("comments/item_comment.html", {"comment": comment}) payload = {"success": True, "html": html} except AccessError: payload = {"success": False, "error": _("You are not allowed for add comment")} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def comment_add(request, content_type, object_id, parent_id=None): try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = get_object_or_404(ContentType, id=int(content_type)) comment.object_id = int(object_id) comment.ip = request.META["REMOTE_ADDR"] comment.user_agent = request.META["HTTP_USER_AGENT"] comment.comment = request.REQUEST["comment"] or None depth = int(request.REQUEST["depth"]) if len(comment.comment) < 1: raise AccessError if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send( request.user, verb=_("commented"), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request, ) newcomment = copy.deepcopy(comment) newcomment.depth = depth html = render_to_string("comments/comment_one.html", {"comment": newcomment, "user": request.user}) payload = {"success": True, "html": html, "object_comments": comment.content_object.comments} except AccessError: payload = {"success": False, "error": "You are not allowed for add comment"} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def comment_add_oldver(request, content_type, object_id, parent_id=None): """ Its Ajax posted comments """ # noinspection PyBroadException try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id( int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST['comment'] if not len(comment.comment): raise AccessError kwargs = {'content_type': content_type, 'object_id': object_id} if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) avatar_id = False kwargs['parent_id'] = comment.pk reply_link = reverse("jcomment_parent_add", kwargs=kwargs) comment_text = linebreaksbr(comment.comment) comment_date = comment.created_date.strftime( setting('COMMENT_DATE_FORMAT', '%d %b %Y %H:%M %p')) # noinspection PyBroadException try: avatar_id = comment.user.avatar.pk except: pass # noinspection PyUnresolvedReferences payload = { 'success': True, 'id': comment.pk, 'username': comment.user.get_name, 'username_url': comment.get_absolute_url(), 'comment': comment_text, 'avatar_id': avatar_id, 'comment_date': comment_date, 'reply_link': reply_link, 'object_comments': comment.content_object.comments } except AccessError as aerr: payload = { 'success': False, 'error': _('You are not allowed for add comment') } except: payload = {'success': False} return ajax_answer_lazy(payload)
def comment_add_oldver(request, content_type, object_id, parent_id=None): """ Its Ajax posted comments """ try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = get_object_or_404(ContentType, id=int(content_type)) comment.object_id = int(object_id) comment.ip = request.META["REMOTE_ADDR"] comment.user_agent = request.META["HTTP_USER_AGENT"] comment.comment = request.POST["comment"] if not len(comment.comment): raise AccessError kwargs = {"content_type": content_type, "object_id": object_id} if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send( request.user, verb=_("commented"), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request, ) avatar_id = False kwargs["parent_id"] = comment.pk reply_link = reverse("jcomment_parent_add", kwargs=kwargs) comment_text = linebreaksbr(comment.comment) comment_date = comment.created_date.strftime(settings.COMMENT_DATE_FORMAT) try: avatar_id = comment.user.avatar.pk except: pass payload = { "success": True, "id": comment.pk, "username": comment.user.get_name, "username_url": comment.get_absolute_url(), "comment": comment_text, "avatar_id": avatar_id, "comment_date": comment_date, "reply_link": reply_link, "object_comments": comment.content_object.comments, } except AccessError: payload = {"success": False, "error": _("You are not allowed for add comment")} except: payload = {"success": False} return AjaxLazyAnswer(payload)
def push_user(request, object_id): # Link used for User press button in user panel # noinspection PyBroadException try: user = get_user_model().objects.get(id=object_id) if request.user == user: raise AccessError ctype = ContentType.objects.get_for_model(get_user_model()) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, user) action.send(request.user, verb=_('unfollow the user'), target=user) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now unfollow'), target=user) else: follow(request.user, user) status = True action.send(request.user, verb=_('follow the user'), target=user) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=user.pk).count: notice.send(request.user, user=u, verb=_('also now follow'), target=user) else: notice.send(request.user, user=u, verb=_('now follow'), target=user) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = { 'success': True, 'count': result, 'id': user.pk, 'status': status } except AccessError as aerr: payload = {'success': False} except: payload = {'success': False} return ajax_answer_lazy(payload)
def push_tag(request, object_id): # Link used for User follow tag # noinspection PyBroadException try: tag = Tag.objects.get(id=object_id) ctype = ContentType.objects.get_for_model(Tag) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): unfollow(request.user, tag) action.send(request.user, verb=_('unfollow the tag'), target=tag) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now follow'), target=tag) else: follow(request.user, tag) status = True action.send(request.user, verb=_('follow the tag'), action_type=ACTION_FOLLOWED, target=tag, request=request) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=tag.pk).count: notice.send(request.user, user=u, verb=_('also now follow'), target=tag) else: notice.send(request.user, user=u, verb=_('now follow'), target=tag) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = { 'success': True, 'count': result, 'id': tag.pk, 'status': status } except: payload = {'success': False} return ajax_answer_lazy(payload)
def push_video(request, object_id): # Link used for User press Like on Video Detail Page # noinspection PyBroadException try: video = get_object_or_404(Video, id=int(object_id)) ctype = ContentType.objects.get_for_model(Video) status = False if Follow.objects.filter(user=request.user, content_type=ctype, object_id=object_id).count(): if unfollow(request.user, video): # action.send(request.user, verb=_('disliked the video'), target=video) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): notice.send(request.user, user=u, verb=_('now disliked'), target=video) else: if follow(request.user, video): status = True action.send(request.user, verb=_('liked the video'), action_type=ACTION_LIKED, target=video, request=request) if request.user.followers_count: for u in get_user_model().objects.filter( pk__in=request.user.followers): if u.follow_set.filter(content_type=ctype, object_id=video.pk).count: notice.send(request.user, user=u, verb=_('also now liked'), target=video) else: notice.send(request.user, user=u, verb=_('now liked'), target=video) result = Follow.objects.filter(content_type=ctype, object_id=object_id).count() payload = { 'success': True, 'count': result, 'id': video.pk, 'status': status } except: payload = {'success': False} return ajax_answer_lazy(payload)
def comment_add_oldver(request, content_type, object_id, parent_id=None): """ Its Ajax posted comments """ # noinspection PyBroadException try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id(int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST['comment'] if not len(comment.comment): raise AccessError kwargs = {'content_type': content_type, 'object_id': object_id} if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) avatar_id = False kwargs['parent_id'] = comment.pk reply_link = reverse("jcomment_parent_add", kwargs=kwargs) comment_text = linebreaksbr(comment.comment) comment_date = comment.created_date.strftime(setting('COMMENT_DATE_FORMAT', '%d %b %Y %H:%M %p')) # noinspection PyBroadException try: avatar_id = comment.user.avatar.pk except: pass # noinspection PyUnresolvedReferences payload = {'success': True, 'id': comment.pk, 'username': comment.user.get_name, 'username_url': comment.get_absolute_url(), 'comment': comment_text, 'avatar_id': avatar_id, 'comment_date': comment_date, 'reply_link': reply_link, 'object_comments': comment.content_object.comments} except AccessError as aerr: payload = {'success': False, 'error': _('You are not allowed for add comment')} except: payload = {'success': False} return ajax_answer_lazy(payload)
def comment_add(request, content_type, object_id, parent_id=None): # noinspection PyBroadException try: if not request.user.is_authenticated(): raise AccessError comment = Nnmcomment() comment.user = request.user comment.content_type = ContentType.objects.get_for_id( int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST.get('comment') or None depth = int(request.POST.get('depth')) if len(comment.comment) < 1: raise AccessError if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) newcomment = copy.deepcopy(comment) newcomment.depth = depth html = render_to_string('comments/comment_one.html', { 'comment': newcomment, 'user': request.user }) payload = { 'success': True, 'html': html, 'object_comments': comment.content_object.comments } except AccessError as aerr: payload = { 'success': False, 'error': 'You are not allowed for add comment' } except: payload = {'success': False} return ajax_answer_lazy(payload)
def comment_add(request, content_type, object_id, parent_id=None): """ Its Ajax posted comments """ try: if not request.user.is_authenticated(): raise AccessError comment = JComment() comment.user = request.user comment.content_type = get_object_or_404(ContentType, id=int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.REQUEST['comment'] if not len(comment.comment): raise AccessError kwargs={'content_type': content_type, 'object_id': object_id} if parent_id is not None: comment.parent_id = int(parent_id) comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description= comment.comment, target=comment.content_object, request=request) avatar_id = False kwargs['parent_id'] = comment.pk reply_link = reverse("jcomment_parent_add", kwargs=kwargs) comment_text = linebreaksbr(comment.comment) comment_date = comment.created_date.strftime(settings.COMMENT_DATE_FORMAT) try: avatar_id = comment.user.avatar.pk except : pass payload = {'success': True, 'id':comment.pk, 'username':comment.user.get_name, 'username_url':comment.get_absolute_url(), 'comment':comment_text, 'avatar_id':avatar_id, 'comment_date': comment_date, 'reply_link':reply_link, 'object_comments':comment.content_object.comments } except AccessError: payload = {'success': False, 'error':_('You are not allowed for add comment')} except : payload = {'success': False} return AjaxLazyAnswer(payload)
def flat_comment_add(request, content_type, object_id): """ Its Ajax flat posted comments """ try: if not request.user.is_authenticated(): raise AccessError comment = FlatNnmcomment() comment.user = request.user comment.content_type = get_object_or_404(ContentType, id=int(content_type)) comment.object_id = int(object_id) comment.ip = request.META['REMOTE_ADDR'] comment.user_agent = request.META['HTTP_USER_AGENT'] comment.comment = request.POST['comment'] if not len(comment.comment): raise AccessError kwargs = {'content_type': content_type, 'object_id': object_id} comment.save() action.send(request.user, verb=_('commented'), action_type=ACTION_COMMENTED, description=comment.comment, target=comment.content_object, request=request) html = render_to_string('comments/item_comment.html', {'comment': comment}) payload = {'success': True, 'html': html} except AccessError: payload = { 'success': False, 'error': _('You are not allowed for add comment') } except: payload = {'success': False} return AjaxLazyAnswer(payload)
def form_valid(self, form): link = form.cleaned_data.get('video_url') if not link[:7] == 'http://': link = 'http://%s' % link if link.find('youtu.be') != -1: link = link.replace('youtu.be/','www.youtube.com/watch?v=') consumer = oembed.OEmbedConsumer() # TODO: more code security here - big chance to get fatal error endpoint = get_oembed_end_point(link) # consumer.addEndpoint(endpoint) response = consumer.embed(link) result = response.getData() obj = Video() obj.embedcode = result['html'] obj.thumbnail = image_from_url(result['thumbnail_url']) if result.has_key('duration'): obj.duration = result['duration'] obj.user = self.request.user obj.project_name = form.cleaned_data.get('project_name') obj.project_url = form.cleaned_data.get('project_url') obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url')) obj.publish = True obj.description = form.cleaned_data.get('description') obj.video_url = link obj.save() obj.slug = gen_shortcut(obj.id) tags = form.cleaned_data.get('tags') alltags = Tag.objects.all().filter(name__in=tags) for tag in tags: obj.tags.add(alltags.get(name=tag)) obj.save() self.success_url = obj.get_absolute_url() action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj, request=self.request) return super(VideoAdd, self).form_valid(form)
def form_valid(self, form): link = form.cleaned_data.get('video_url') if not link[:7] == 'http://': link = 'http://%s' % link if link.find('youtu.be') != -1: link = link.replace('youtu.be/', 'www.youtube.com/watch?v=') consumer = oembed.OEmbedConsumer() # TODO: more code security here - big chance to get fatal error endpoint = get_oembed_end_point(link) # consumer.addEndpoint(endpoint) response = consumer.embed(link) result = response.getData() obj = Video() obj.embedcode = result['html'] obj.thumbnail = image_from_url(result['thumbnail_url']) if result.has_key('duration'): obj.duration = result['duration'] obj.user = self.request.user obj.project_name = form.cleaned_data.get('project_name') obj.project_url = form.cleaned_data.get('project_url') obj.video_provider = get_video_provider_from_link(form.cleaned_data.get('video_url')) obj.publish = True obj.description = form.cleaned_data.get('description') obj.video_url = link obj.save() obj.slug = gen_shortcut(obj.id) tags = form.cleaned_data.get('tags') alltags = Tag.objects.all().filter(name__in=tags) for tag in tags: obj.tags.add(alltags.get(name=tag)) obj.save() self.success_url = obj.get_absolute_url() action.send(self.request.user, verb=_('added the video'), action_type=ACTION_ADDED, target=obj, request=self.request) return super(VideoAdd, self).form_valid(form)