from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from news.models import Article, Event
from door.models import DoorStatus
from datetime import datetime
from itertools import chain


def index(request):
    number_of_news = 3

    # Sorts the news to show the events nearest in future and then fill in with the newest articles
    event_list = Event.objects.filter(time_end__gte=datetime.now())[0:number_of_news:-1]
    article_list = Article.objects.order_by('-pub_date')[0:number_of_news - len(event_list)]
    news_list = list(chain(event_list, article_list))

    try:
        door_status = DoorStatus.objects.get(name='hackerspace').status
    except DoorStatus.DoesNotExist:
        door_status = True
    context = {
        'news_list': news_list,
        'door_status': door_status,
    }

    return render(request, 'index.html', context)


def opptak(request):
    return HttpResponseRedirect(reverse('application_form'))


def test404(request):
    return render(request, '404.html')

from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from news.models import Article, Event
from door.models import DoorStatus
from datetime import datetime
from itertools import chain


def index(request):
    number_of_news = 3

    # Sorts the news to show the events nearest in future and then fill in with the newest articles
    event_list = Event.objects.filter(time_end__gte=datetime.now())[0:number_of_news:-1]
    article_list = Article.objects.order_by('-pub_date')[0:number_of_news - len(event_list)]
    news_list = list(chain(event_list, article_list))

    try:
        door_status = DoorStatus.objects.get(name='hackerspace').status
    except DoorStatus.DoesNotExist:
        door_status = True
    context = {
        'news_list': news_list,
        'door_status': door_status,
    }

    return render(request, 'index.html', context)


def opptak(request):
    return HttpResponseRedirect(reverse('article', args=[6]))


def test404(request):
    return render(request, '404.html')

Change redirect to application redirect
Change redirect to application redirect

  from django.shortcuts import render
  from django.http import HttpResponseRedirect
  from django.core.urlresolvers import reverse
  from news.models import Article, Event
  from door.models import DoorStatus
  from datetime import datetime
  from itertools import chain
  
  
  def index(request):
      number_of_news = 3
  
      # Sorts the news to show the events nearest in future and then fill in with the newest articles
      event_list = Event.objects.filter(time_end__gte=datetime.now())[0:number_of_news:-1]
      article_list = Article.objects.order_by('-pub_date')[0:number_of_news - len(event_list)]
      news_list = list(chain(event_list, article_list))
  
      try:
          door_status = DoorStatus.objects.get(name='hackerspace').status
      except DoorStatus.DoesNotExist:
          door_status = True
      context = {
          'news_list': news_list,
          'door_status': door_status,
      }
  
      return render(request, 'index.html', context)
  
  
  def opptak(request):
-     return HttpResponseRedirect(reverse('application_form'))
+     return HttpResponseRedirect(reverse('article', args=[6]))
  
  
  def test404(request):
      return render(request, '404.html')
  
Change redirect to application redirect
## Code Before:
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from news.models import Article, Event
from door.models import DoorStatus
from datetime import datetime
from itertools import chain


def index(request):
    number_of_news = 3

    # Sorts the news to show the events nearest in future and then fill in with the newest articles
    event_list = Event.objects.filter(time_end__gte=datetime.now())[0:number_of_news:-1]
    article_list = Article.objects.order_by('-pub_date')[0:number_of_news - len(event_list)]
    news_list = list(chain(event_list, article_list))

    try:
        door_status = DoorStatus.objects.get(name='hackerspace').status
    except DoorStatus.DoesNotExist:
        door_status = True
    context = {
        'news_list': news_list,
        'door_status': door_status,
    }

    return render(request, 'index.html', context)


def opptak(request):
    return HttpResponseRedirect(reverse('application_form'))


def test404(request):
    return render(request, '404.html')

## Instruction:
Change redirect to application redirect
## Code After:
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from news.models import Article, Event
from door.models import DoorStatus
from datetime import datetime
from itertools import chain


def index(request):
    number_of_news = 3

    # Sorts the news to show the events nearest in future and then fill in with the newest articles
    event_list = Event.objects.filter(time_end__gte=datetime.now())[0:number_of_news:-1]
    article_list = Article.objects.order_by('-pub_date')[0:number_of_news - len(event_list)]
    news_list = list(chain(event_list, article_list))

    try:
        door_status = DoorStatus.objects.get(name='hackerspace').status
    except DoorStatus.DoesNotExist:
        door_status = True
    context = {
        'news_list': news_list,
        'door_status': door_status,
    }

    return render(request, 'index.html', context)


def opptak(request):
    return HttpResponseRedirect(reverse('article', args=[6]))


def test404(request):
    return render(request, '404.html')
