<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.core.urlresolvers import reverse
from django.views.generic import CreateView, DetailView, ListView, RedirectView, UpdateView
from django.shortcuts import render

from braces.views import LoginRequiredMixin

from .models import ELO, ELOType, ReusabilityTree, ReusabilityTreeNode
from .forms import ELOForm, ELOForkForm, ELOUpdateForm

class ELOsCreateView(LoginRequiredMixin, CreateView):
    model = ELO
    form_class = ELOForm
    template_name = "elos/elos_create.html"
    #success_url = "/elos"

class ELOsDetailView(LoginRequiredMixin, DetailView):
    model = ELO
    query_pk_and_slug = True
    template_name = 'elos/elos_detail.html'

    def get_context_data(self, **kwargs):
        context = super(ELOsDetailView, self).get_context_data(**kwargs)
        elo = ELO.objects.get(id=self.kwargs['pk'])

        # Check Reusability Tree
        if not hasattr(elo, 'reusability_tree'):
            elo.reusability_tree_build()

        context['nodes'] = ReusabilityTreeNode.objects.filter(base_elo=elo)

        # Count Fork
        context['fork_count'] = ELO.objects.filter(parent_elo=self.kwargs['pk']).count()
        return context

class ELOsForkView(LoginRequiredMixin, CreateView):
    model = ELO
    form_class = ELOForkForm
    template_name = "elos/elos_fork.html"

    def get_form_kwargs(self):<commit_msg>更新 view ELOsDetailView, 強迫每次檢視時都重新產生最新版本的 RT<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.core.urlresolvers import reverse
from django.views.generic import CreateView, DetailView, ListView, RedirectView, UpdateView
from django.shortcuts import render

from braces.views import LoginRequiredMixin

from .models import ELO, ELOType, ReusabilityTree, ReusabilityTreeNode
from .forms import ELOForm, ELOForkForm, ELOUpdateForm

class ELOsCreateView(LoginRequiredMixin, CreateView):
    model = ELO
    form_class = ELOForm
    template_name = "elos/elos_create.html"
    #success_url = "/elos"

class ELOsDetailView(LoginRequiredMixin, DetailView):
    model = ELO
    query_pk_and_slug = True
    template_name = 'elos/elos_detail.html'

    def get_context_data(self, **kwargs):
        context = super(ELOsDetailView, self).get_context_data(**kwargs)
        elo = ELO.objects.get(id=self.kwargs['pk'])

        # Check Reusability Tree
        if not hasattr(elo, 'reusability_tree'):
            elo.reusability_tree_build()
        # Force to rebuild every time
        else:
            elo.reusability_tree_build()

        context['nodes'] = ReusabilityTreeNode.objects.filter(base_elo=elo)

        # Count Fork
        context['fork_count'] = ELO.objects.filter(parent_elo=self.kwargs['pk']).count()

        return context

class ELOsForkView(LoginRequiredMixin, CreateView):
    model = ELO
    form_class = ELOForkForm
    template_name = "elos/elos_fork.html"

    def get_form_kwargs(self):
{'fraction_non_alphanumeric': 0.09257409257409258, 'fraction_numerical': 0.000666000666000666, 'mean_word_length': 3.9983361064891847, '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': '1843980', 'n_tokens_mistral': 997, 'n_tokens_neox': 975, 'n_words': 202}