示例#1
0
def read_all(request):
    try:
        notifications = Notification.objects.all_unread(request.user)
        for notification in notifications:
            if notification.recipient == request.user:
                notification.read = True
                notification.save()
            else:
                raise Http404
        return redirect_to(reverse("notifications_all"))
    except:
        return redirect_to(reverse("notifications_all"))
示例#2
0
文件: views.py 项目: ikedumancas/DOIT
def read_all(request):
	try:
		notifications = Notification.objects.all_unread(request.user)
		for notification in notifications:
			if notification.recipient == request.user:
				notification.read=True
				notification.save()
			else:
				raise Http404
		return redirect_to(reverse("notifications_all"))
	except:
		return redirect_to(reverse("notifications_all"))
示例#3
0
文件: views.py 项目: ikedumancas/DOIT
def read(request,id):
	try:
		next_url = request.GET.get('next', None)
		notification = Notification.objects.get(id=id)
		if notification.recipient == request.user:
			notification.read=True
			notification.save()
			if next_url is not None:
				return redirect_to(next_url)
			else:
				return redirect_to(reverse("notifications_all"))
		else:
			raise Http404
	except:
		return redirect_to(reverse("notifications_all"))
示例#4
0
def read(request, id):
    try:
        next_url = request.GET.get('next', None)
        notification = Notification.objects.get(id=id)
        if notification.recipient == request.user:
            notification.read = True
            notification.save()
            if next_url is not None:
                return redirect_to(next_url)
            else:
                return redirect_to(reverse("notifications_all"))
        else:
            raise Http404
    except:
        return redirect_to(reverse("notifications_all"))
示例#5
0
def comment_create_view(request):
    if request.method == 'POST':
        parent_id = request.POST.get('parent_id')
        video_id = request.POST.get('video_id')
        origin_path = request.POST.get('origin_path')
        redirect_url = origin_path
        parent_comment = None
        video = None
        comment_form = CommentForm(request.POST)

        if comment_form.is_valid():
            if video_id:
                try:
                    video = Video.objects.get(id=video_id)
                except:
                    messages.error(
                        request,
                        'There was an error with your comment for this video.')
            if parent_id:
                try:
                    parent_comment = Comment.objects.get(id=parent_id)
                    video = parent_comment.video
                    origin_path = parent_comment.origin
                except:
                    messages.error(
                        request,
                        'There was an error with your reply for this comment.')
            comment_text = comment_form.cleaned_data['comment']
            new_comment = Comment.objects.create_comment(
                user=request.user,
                text=comment_text,
                path=origin_path,
                video=video,
                parent=parent_comment,
            )
            if new_comment.is_child:
                affected_users = parent_comment.get_affected_users()
                notify.send(
                    request.user,
                    action=new_comment,
                    verb='replied to',
                    target=parent_comment,
                    affected_users=affected_users,
                    recipient=parent_comment.user,
                )
                redirect_url = parent_comment.get_absolute_url()
            else:
                notify.send(request.user,
                            action=new_comment,
                            verb='commented on',
                            target=video,
                            recipient=MyUser.objects.get(username="******"))
                redirect_url = new_comment.get_absolute_url()

            messages.success(request, 'Your comment has been added.')
            # messages.success(request, 'Your comment has been added.', extra_tags='safe') # NOTE: add extra_tags='safe' if you add html to message
        else:
            messages.error(request, 'There was an error with your comment.')
        return redirect_to(redirect_url)
    raise Http404
示例#6
0
def comment_thread(request, id):
    head_title = 'View Comment Thread'
    comment_form = CommentForm(request.POST or None)
    try:
        if comment_form.is_valid():
            parent_id = request.POST.get('parent_id')
            parent_comment = Comment.objects.get(id=parent_id)
            comment_text = comment_form.cleaned_data['comment']
            new_comment = Comment.objects.create_comment(
                user=request.user,
                text=comment_text,
                path=parent_comment.origin,
                video=parent_comment.video,
                parent=parent_comment)
            return redirect_to(parent_comment.get_absolute_url())
        comment = Comment.objects.get(id=id)
        context = {
            'head_title': head_title,
            'comment': comment,
            'comment_form': comment_form,
        }
        template = "comments/comment_thread.html"
        return render(request, template, context)
    except:
        raise Http404
示例#7
0
def video_detail(request, cat_slug, vid_slug):
    cat = get_object_or_404(Category, slug=cat_slug)
    obj = get_object_or_404(Video, slug=vid_slug, category=cat)
    page_view.send(request.user,
                   page_path=request.get_full_path(),
                   primary=obj,
                   secondary=cat)
    head_title = obj.title
    context = {
        "head_title": head_title,
        "obj": obj,
    }
    template = "videos/video_detail.html"
    try:
        is_member = request.user.is_member
    except:
        is_member = False

    if obj.has_preview or is_member:
        if request.user.is_authenticated():
            comments = obj.comment_set.all()
            comment_form = CommentForm()
            context.update({
                "comments": comments,
                "comment_form": comment_form,
            })
    else:
        next_url = cat.get_absolute_url()
        messages.warning(
            request,
            'You have to be a member to access this content. <a href="%s">Upgrade your account here</a>'
            % (reverse('account_upgrade')))
        return redirect_to(next_url)
        # return HttpResponseRedirect("%s?next=%s"%(reverse('account_upgrade'), next_url)) # activate this if you want the user to go to upgrade
    return render(request, template, context)
def comment_thread(request,id):
	head_title   = 'View Comment Thread'
	comment_form = CommentForm(request.POST or None)
	try:
		if comment_form.is_valid():
			parent_id      = request.POST.get('parent_id')
			parent_comment = Comment.objects.get(id=parent_id)
			comment_text   = comment_form.cleaned_data['comment']
			new_comment    = Comment.objects.create_comment(
				user   =request.user, 
				text   =comment_text, 
				path   = parent_comment.origin, 
				video  = parent_comment.video,
				parent = parent_comment
			)
			return redirect_to(parent_comment.get_absolute_url())
		comment = Comment.objects.get(id=id)
		context = {
			'head_title':head_title,
			'comment':comment,
			'comment_form':comment_form,
		}
		template = "comments/comment_thread.html"
		return render(request, template, context)	
	except:
		raise Http404
def video_detail(request, cat_slug,vid_slug):
	cat = get_object_or_404(Category, slug=cat_slug)
	obj = get_object_or_404(Video, slug=vid_slug, category=cat)
	page_view.send(request.user,
		page_path=request.get_full_path(),
		primary=obj,
		secondary=cat)
	head_title = obj.title
	context = {
		"head_title":head_title,
		"obj":obj,
	}
	template = "videos/video_detail.html"
	try:
		is_member = request.user.is_member
	except:
		is_member = False

	if obj.has_preview or is_member:
		if request.user.is_authenticated():
			comments = obj.comment_set.all()
			comment_form = CommentForm()
			context.update({
				"comments":comments,
				"comment_form":comment_form,
			})
	else:
		next_url = cat.get_absolute_url()
		messages.warning(request, 'You have to be a member to access this content. <a href="%s">Upgrade your account here</a>' %(reverse('account_upgrade'))) 
		return redirect_to(next_url)
		# return HttpResponseRedirect("%s?next=%s"%(reverse('account_upgrade'), next_url)) # activate this if you want the user to go to upgrade
	return render(request, template, context)
def comment_create_view(request):
	if request.method == 'POST':
		parent_id      = request.POST.get('parent_id')
		video_id       = request.POST.get('video_id')
		origin_path    = request.POST.get('origin_path')
		redirect_url   = origin_path
		parent_comment = None
		video          = None
		comment_form   = CommentForm(request.POST)
		
		if comment_form.is_valid():
			if video_id:
				try:
					video = Video.objects.get(id=video_id)
				except:
					messages.error(request, 'There was an error with your comment for this video.')
			if parent_id:
				try:
					parent_comment = Comment.objects.get(id=parent_id)
					video          = parent_comment.video
					origin_path    = parent_comment.origin
				except:
					messages.error(request, 'There was an error with your reply for this comment.')
			comment_text = comment_form.cleaned_data['comment']
			new_comment  = Comment.objects.create_comment(
				user   = request.user, 
				text   = comment_text, 
				path   = origin_path, 
				video  = video,
				parent = parent_comment,
			)
			if new_comment.is_child:
				affected_users = parent_comment.get_affected_users()
				notify.send(
					request.user,
					action=new_comment,
					verb='replied to',
					target=parent_comment,
					affected_users = affected_users,
					recipient=parent_comment.user,)
				redirect_url = parent_comment.get_absolute_url()
			else:
				notify.send(
					request.user,
					action=new_comment,
					verb='commented on',
					target=video,
					recipient=MyUser.objects.get(username="******"))
				redirect_url = new_comment.get_absolute_url()
				
			messages.success(request, 'Your comment has been added.')
			# messages.success(request, 'Your comment has been added.', extra_tags='safe') # NOTE: add extra_tags='safe' if you add html to message
		else:
			messages.error(request, 'There was an error with your comment.')
		return redirect_to(redirect_url)
	raise Http404
示例#11
0
def auth_login(request):
    form = LoginForm(request.POST or None)
    next_url = request.GET.get('next')
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        user = authenticate(username=username, password=password)
        if user:
            login(request, user)
            if next_url:
                return redirect_to(next_url)
            return redirect('home')
        else:
            messages.error(request, 'Username/Password incorrect.')
    context = {'form': form}
    template = "account/login.html"
    return render(request, template, context)
示例#12
0
文件: views.py 项目: ikedumancas/DOIT
def auth_login(request):
	form = LoginForm(request.POST or None)
	next_url = request.GET.get('next')
	if form.is_valid():
		username = form.cleaned_data['username']
		password = form.cleaned_data['password']
		user = authenticate(username=username,password=password)
		if user:
			login(request,user)
			if next_url:
				return redirect_to(next_url)	
			return redirect('home')
		else:
			messages.error(request,'Username/Password incorrect.')
	context = {
		'form':form
	}
	template = "account/login.html"
	return render(request, template, context)
def auth_login(request):
    head_title = "Login"
    form = LoginForm(request.POST or None)
    next_url = request.GET.get('next')
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        user = authenticate(username=username, password=password)
        if user:
            login(request, user)
            if next_url:
                return redirect_to(next_url)
            return redirect('home')
        else:
            pass

    context = {
        "head_title": head_title,
        "form": form,
    }
    template = "login.html"
    return render(request, template, context)
def auth_logout(request):
    logout(request)
    return redirect_to('/')