<commit_before>from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.mixins import UserPassesTestMixin

from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView

from django import forms
from .forms import CommentForm, CommentReviewForm

from .models import Article, Comment, Category, ContentManagerCategory, Like

from django.contrib.auth.decorators import login_required

from django.http import HttpResponseRedirect

from django.contrib.admin.views.decorators import staff_member_required

class ArticleListView(ListView):
	model = Article
	def get_context_data(self, **kwargs):
		context = super(ArticleListView, self).get_context_data(**kwargs)
		context['categories'] =  Category.objects.all()
		return context

class ArticleDetailView(DetailView):
	model = Article

	def get_context_data(self, **kwargs):
		context = super(ArticleDetailView, self).get_context_data(**kwargs)
		context['form'] = CommentForm()
		context['comments'] = Comment.objects.filter(news_article=self.object)
		context['likes'] = len(Like.objects.filter(article=self.object))
		context['liked'] = 'True' if len(Like.objects.filter(article=self.object, author=self.request.user)) != 0 else 'False'
		return context

class ArticleCreateView(UserPassesTestMixin, CreateView):<commit_msg>fixed error: page article_detail.html falls if user is not authenticated<commit_after>from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.mixins import UserPassesTestMixin

from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView

from django import forms
from .forms import CommentForm, CommentReviewForm

from .models import Article, Comment, Category, ContentManagerCategory, Like

from django.contrib.auth.decorators import login_required

from django.http import HttpResponseRedirect

from django.contrib.admin.views.decorators import staff_member_required

class ArticleListView(ListView):
	model = Article
	def get_context_data(self, **kwargs):
		context = super(ArticleListView, self).get_context_data(**kwargs)
		context['categories'] =  Category.objects.all()
		return context

class ArticleDetailView(DetailView):
	model = Article

	def get_context_data(self, **kwargs):
		context = super(ArticleDetailView, self).get_context_data(**kwargs)
		context['form'] = CommentForm()
		context['comments'] = Comment.objects.filter(news_article=self.object)
		context['likes'] = len(Like.objects.filter(article=self.object))
		if self.request.user.is_authenticated():
			if len(Like.objects.filter(article=self.object, author=self.request.user)) != 0:
				context['liked'] = 'True'
			else: 
				context['liked'] = 'False'
		else: 
			context['liked'] = 'False'
		return context

class ArticleCreateView(UserPassesTestMixin, CreateView):
{'fraction_non_alphanumeric': 0.10111599594183295, 'fraction_numerical': 0.002705444707473791, 'mean_word_length': 6.565217391304348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2429509', 'n_tokens_mistral': 888, 'n_tokens_neox': 826, 'n_words': 202}