def all_reported_comments(request): if not auth.is_super(request): return redirect('login') all_reports = Report.objects.exclude(comment_id=None) reports = [all_reports.filter(comment_id=item['comment_id']).last() for item in Report.objects.values('comment_id').distinct()] return render(request, 'projects/admin/reported_comments.html', {'reports': reports} )
def admin_reported_projects(request): if not auth.is_super(request): return redirect('login') user_id=request.session['user_id'] projects=[] distinct = Report.objects.values( 'project_id' ).annotate( name_count=Count('project_id') ) # print(distinct) not_commented=distinct.filter(comment_id__isnull = True) # print(not_commented) if Report.objects.filter(comment_id__isnull = True) : projects = Project.objects.filter(id__in=[item['project_id'] for item in not_commented ]) # print(projects) # reported_projects = Report.objects.distinct() # for reported_project in reported_projects: # if reported_project.comment_id == None : # projects += Project.objects.filter(id=reported_project.project_id) context = {'projects':projects} return render(request, 'projects/admin/reported_projects.html', context )
def admin_projects(request): if not auth.is_super(request): return redirect('login') projects = Project.objects.all() return render(request, 'projects/admin/all.html', {'projects':projects})
def index(request): if not auth.is_super(request): return redirect('login') categories = Category.objects.all() if request.method == "POST": if (request.POST['name'] == ''): msg = 'You must insert category name!' alert = 'danger' else: category = Category(name=request.POST['name']) try: category.save() msg = 'New category added successfully' alert = 'success' except IntegrityError as e: msg = 'Category already added!' alert = 'danger' return render(request, 'all.html', { "categories": categories, "msg": msg, "alert": alert }) else: return render(request, 'all.html', {"categories": categories})
def delete_comment(request, id): if not auth.is_super(request): return redirect('login') report = Report.objects.get(pk=id) comment = Comment.objects.get(pk=report.comment_id) comment.delete() report.delete() return redirect('/admin/projects/comments/reported/')
def project_featured(request, id): if not auth.is_super(request): return redirect('login') project = Project.objects.get(pk=id) if(project.featured == 1): project.featured = 0 else: project.featured = 1 project.save() return JsonResponse({'status':200})
def admin_delete_reported_projects(request, id): if not auth.is_super(request): return redirect('login') project = Project.objects.get(pk=id) # if (project_donation): # project_donation.delete() # project.delete() project_donations,created=Donation.objects.get_or_create(project=project,amount=0) print(project_donations) project_donation=Donation.objects.filter(project=id) if len(project_donation) is 1 and created==True: project_donation.delete() project.delete() elif len(project_donation) is 1 and created==False: project_donation.update(project=None) project.delete() elif len(project_donation)>1 : project_donation.update(project=None) project.delete() return redirect('/admin/projects/reported_project')