import os

from django.shortcuts import render, get_object_or_404

from .models import Problem

def index(request):
    problems = Problem.objects.filter(status='published')
    context = {
        'problems': problems,
        "project_description": os.getenv("PROJECT_DESCRIPTION", ""),
        "project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
    }
    return render(request, "core/index.html", context)

def problem_detail(request, pk):
    problem = get_object_or_404(Problem, pk=pk)
    context = {
        'problem': problem,
        "project_description": os.getenv("PROJECT_DESCRIPTION", ""),
        "project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
    }
    return render(request, "core/article_detail.html", context)
