<commit_before># coding: utf-8

# Copyright (C) 2012  <NAME> <<EMAIL>>
#
# This file is part of manoseimas.lt project.
#
# manoseimas.lt is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# manoseimas.lt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with manoseimas.lt.  If not, see <http://www.gnu.org/licenses/>.

import itertools

from zope.component import adapts
from zope.component import provideAdapter

from django.utils.translation import ugettext_lazy as _

from sboard.factory import getNodeFactory
from sboard.nodes import CreateView
from sboard.nodes import DetailsView
from sboard.nodes import UpdateView
from sboard.utils import slugify

from .forms import AssignIssueForm
from .forms import SolutionForm
from .forms import SolutionIssueForm
from .interfaces import IIssue
from .interfaces import ISolution
from .interfaces import ISolutionIssue
from .models import Issue
from .models import query_issue_raises
from .models import query_issue_solves


def solution_nav(node, nav, active):
    active = active or ('index',)

    nav.append({
        'key': 'node-title',
        'title': _('Sprendimas'),
        'header': True,
    })

    key = 'index'
    nav.append({
        'key': key,
        'url': node.permalink(),
        'title': _('Sprendimas'),
        'children': [],
        'active': key in active,
    })

    key = 'seimo-pozicija'
    nav.append({
        'key': key,
        'url': node.permalink(key),
        'title': _('Seimo pozicija'),
        'children': [],
        'active': key in active,
    })

    key = 'balsavimai'
    nav.append({
        'key': key,
        'url': node.permalink(key),
        'title': _('Balsavimai'),
        'children': [],
        'active': key in active,
    })

    return nav


class SolutionDetailsView(DetailsView):
    adapts(ISolution)

    template = 'solutions/node_details.html'

    def nav(self, active=tuple()):
        nav = super(SolutionDetailsView, self).nav(active)
        return solution_nav(self.node, nav, active)

    def render(self, **overrides):
        context = {
            'issues': self.node.issues(),
        }
        context.update(overrides)
        return super(SolutionDetailsView, self).render(**context)

provideAdapter(SolutionDetailsView)


class CreateSolutionView(CreateView):
    adapts(object, ISolution)

    form = SolutionForm

provideAdapter(CreateSolutionView, name="create")


class AssignSolutionIssue(CreateView):
    form = AssignIssueForm

    def __init__(self, node):
        self.node = node  # solution
        self.factory = getNodeFactory('solution-issue')

    def before_save(self, form, node, create):
        if not node.issue:
            issue = Issue()
            issue.set_new_id()
            issue.slug = slugify(node.title)
            issue.title = node.title
            issue.save()
            node.issue = issue

        # Title is never saved for SolutionIssue, it is taken from Issue.
        node.title = None
        solves = 'sprendimas' if self.solves else 'priezastis'
        node.slug = '%s-%s-%s' % (node.issue.ref.get_slug(), solves,
                                  self.node.get_slug())
        node.solves = self.solves
        node.solution = self.node
<commit_msg>Rename CreateSolutionView to SolutionCreateView.<commit_after># coding: utf-8

# Copyright (C) 2012  <NAME> <<EMAIL>>
#
# This file is part of manoseimas.lt project.
#
# manoseimas.lt is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# manoseimas.lt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with manoseimas.lt.  If not, see <http://www.gnu.org/licenses/>.

import itertools

from zope.component import adapts
from zope.component import provideAdapter

from django.utils.translation import ugettext_lazy as _

from sboard.factory import getNodeFactory
from sboard.nodes import CreateView
from sboard.nodes import DetailsView
from sboard.nodes import UpdateView
from sboard.utils import slugify

from .forms import AssignIssueForm
from .forms import SolutionForm
from .forms import SolutionIssueForm
from .interfaces import IIssue
from .interfaces import ISolution
from .interfaces import ISolutionIssue
from .models import Issue
from .models import query_issue_raises
from .models import query_issue_solves


def solution_nav(node, nav, active):
    active = active or ('index',)

    nav.append({
        'key': 'node-title',
        'title': _('Sprendimas'),
        'header': True,
    })

    key = 'index'
    nav.append({
        'key': key,
        'url': node.permalink(),
        'title': _('Sprendimas'),
        'children': [],
        'active': key in active,
    })

    key = 'seimo-pozicija'
    nav.append({
        'key': key,
        'url': node.permalink(key),
        'title': _('Seimo pozicija'),
        'children': [],
        'active': key in active,
    })

    key = 'balsavimai'
    nav.append({
        'key': key,
        'url': node.permalink(key),
        'title': _('Balsavimai'),
        'children': [],
        'active': key in active,
    })

    return nav


class SolutionDetailsView(DetailsView):
    adapts(ISolution)

    template = 'solutions/node_details.html'

    def nav(self, active=tuple()):
        nav = super(SolutionDetailsView, self).nav(active)
        return solution_nav(self.node, nav, active)

    def render(self, **overrides):
        context = {
            'issues': self.node.issues(),
        }
        context.update(overrides)
        return super(SolutionDetailsView, self).render(**context)

provideAdapter(SolutionDetailsView)


class SolutionCreateView(CreateView):
    adapts(object, ISolution)

    form = SolutionForm

provideAdapter(SolutionCreateView, name="create")


class AssignSolutionIssue(CreateView):
    form = AssignIssueForm

    def __init__(self, node):
        self.node = node  # solution
        self.factory = getNodeFactory('solution-issue')

    def before_save(self, form, node, create):
        if not node.issue:
            issue = Issue()
            issue.set_new_id()
            issue.slug = slugify(node.title)
            issue.title = node.title
            issue.save()
            node.issue = issue

        # Title is never saved for SolutionIssue, it is taken from Issue.
        node.title = None
        solves = 'sprendimas' if self.solves else 'priezastis'
        node.slug = '%s-%s-%s' % (node.issue.ref.get_slug(), solves,
                                  self.node.get_slug())
        node.solves = self.solves
        node.solution = self.node

{'fraction_non_alphanumeric': 0.10246398276558502, 'fraction_numerical': 0.0016157264036623133, 'mean_word_length': 2.8308406395048995, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2949044', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2130, 'n_words': 677}