# Path: poetry/apps/corpus/models.py
# class Markup(Model):
#     poem = ForeignKey(Poem, related_name="markups")
#     text = TextField("Слоговая разметка по ударениям", blank=True, default="")
#     author = CharField("Автор разметки", max_length=50, blank=False)
#     additional = TextField("Дополнительная ифнормация", blank=True)
#     markup_version = ForeignKey(MarkupVersion, related_name="markups")
#     is_standard = BooleanField("Эталонная (проверенная) разметка", default=False)
# 
#     class Meta:
#         verbose_name = "Экзепляр разметки"
#         verbose_name_plural = "Экзепляры разметки"
# 
#     def __str__(self):
#         return 'Разметка' + str(self.poem.name) + " " + str(self.markup_version) + " " + str(self.author)
# 
#     def get_absolute_url(self):
#         return reverse("corpus:markup", kwargs={"pk": self.pk})
# 
#     def get_markup(self):
#         markup = InternalMarkup()
#         markup.from_json(self.text)
#         return markup
# 
#     def get_automatic_additional(self):
#         if self.additional:
#             clf = jsonpickle.decode(self.additional)
#             a = list([a for l in clf.corrections.values() for a in l]) + \
#                 list([a for l in clf.additions.values() for a in l]) + \
#                 list([a for l in clf.resolutions.values() for a in l])
#             if len(a) != 0 and type(a[0]) is not StressCorrection:
#                 self.__compatibility_stress_correction(clf.corrections)
#                 self.__compatibility_stress_correction(clf.resolutions)
#                 self.__compatibility_stress_correction(clf.additions)
#             return clf
#         else:
#             return ""
# 
#     def __compatibility_stress_correction(self, collection):
#         for key, value in collection.items():
#             new_value = []
#             for info in value:
#                 new_value.append(StressCorrection(info['line_number'], info["word_number"],
#                                                   info["syllable_number"], info["word_text"], info["accent"]))
#             collection[key] = new_value
# 
# class MarkupVersion(Model):
#     name = CharField("Имя версии разметки", max_length=50, blank=False)
#     additional = TextField("Дополнительная ифнормация", blank=True)
#     is_manual = BooleanField("Ручные разметки?", default=False)
# 
#     class Meta:
#         verbose_name = "Версия разметки"
#         verbose_name_plural = "Версии разметки"
# 
#     def __str__(self):
#         return str(self.name)
# 
#     def count_markups(self):
#         return self.markups.count()


from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import JsonResponse
from django.views.generic import DetailView, View, DeleteView
from django.views.generic.detail import SingleObjectMixin
from braces.views import LoginRequiredMixin, GroupRequiredMixin
from poetry.apps.corpus.models import Markup, MarkupVersion
from rupo.main.markup import Markup as TextMarkup
from rupo.util.preprocess import VOWELS
        context['poem'] = markup.poem
        context['poem'].name = markup.poem.get_name()
        context['lines_count'] = markup.poem.count_lines()
        context['additional'] = markup.get_automatic_additional()
        markups = set()
        for markup_instance in markup.poem.markups.all():
            markups.add(markup_instance.markup_version)
        context['markups'] = list(markups)
        return context

    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            diffs = request.POST.getlist('diffs[]')

            m = self.get_object()
            poem = m.poem
            markup = m.get_markup()

            for diff in diffs:
                l = int(diff.split('-')[0])
                w = int(diff.split('-')[1])
                s = int(diff.split('-')[2])
                syllable = markup.lines[l].words[w].syllables[s]
                if syllable.stress != -1:
                    syllable.stress = -1
                else:
                    for i in range(len(syllable.text)):
                        if syllable.text[i] in VOWELS:
                            syllable.stress = syllable.begin + i


# Path: poetry/apps/corpus/models.py
# class Markup(Model):
#     poem = ForeignKey(Poem, related_name="markups")
#     text = TextField("Слоговая разметка по ударениям", blank=True, default="")
#     author = CharField("Автор разметки", max_length=50, blank=False)
#     additional = TextField("Дополнительная ифнормация", blank=True)
#     markup_version = ForeignKey(MarkupVersion, related_name="markups")
#     is_standard = BooleanField("Эталонная (проверенная) разметка", default=False)
# 
#     class Meta:
#         verbose_name = "Экзепляр разметки"
#         verbose_name_plural = "Экзепляры разметки"
# 
#     def __str__(self):
#         return 'Разметка' + str(self.poem.name) + " " + str(self.markup_version) + " " + str(self.author)
# 
#     def get_absolute_url(self):
#         return reverse("corpus:markup", kwargs={"pk": self.pk})
# 
#     def get_markup(self):
#         markup = InternalMarkup()
#         markup.from_json(self.text)
#         return markup
# 
#     def get_automatic_additional(self):
#         if self.additional:
#             clf = jsonpickle.decode(self.additional)
#             a = list([a for l in clf.corrections.values() for a in l]) + \
#                 list([a for l in clf.additions.values() for a in l]) + \
#                 list([a for l in clf.resolutions.values() for a in l])
#             if len(a) != 0 and type(a[0]) is not StressCorrection:
#                 self.__compatibility_stress_correction(clf.corrections)
#                 self.__compatibility_stress_correction(clf.resolutions)
#                 self.__compatibility_stress_correction(clf.additions)
#             return clf
#         else:
#             return ""
# 
#     def __compatibility_stress_correction(self, collection):
#         for key, value in collection.items():
#             new_value = []
#             for info in value:
#                 new_value.append(StressCorrection(info['line_number'], info["word_number"],
#                                                   info["syllable_number"], info["word_text"], info["accent"]))
#             collection[key] = new_value
# 
# class MarkupVersion(Model):
#     name = CharField("Имя версии разметки", max_length=50, blank=False)
#     additional = TextField("Дополнительная ифнормация", blank=True)
#     is_manual = BooleanField("Ручные разметки?", default=False)
# 
#     class Meta:
#         verbose_name = "Версия разметки"
#         verbose_name_plural = "Версии разметки"
# 
#     def __str__(self):
#         return str(self.name)
# 
#     def count_markups(self):
#         return self.markups.count()


# Path: poetry/apps/corpus/views/markup_view.py
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import JsonResponse
from django.views.generic import DetailView, View, DeleteView
from django.views.generic.detail import SingleObjectMixin
from braces.views import LoginRequiredMixin, GroupRequiredMixin
from poetry.apps.corpus.models import Markup, MarkupVersion
from rupo.main.markup import Markup as TextMarkup
from rupo.util.preprocess import VOWELS

        context['poem'] = markup.poem
        context['poem'].name = markup.poem.get_name()
        context['lines_count'] = markup.poem.count_lines()
        context['additional'] = markup.get_automatic_additional()
        markups = set()
        for markup_instance in markup.poem.markups.all():
            markups.add(markup_instance.markup_version)
        context['markups'] = list(markups)
        return context

    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated():
            diffs = request.POST.getlist('diffs[]')

            m = self.get_object()
            poem = m.poem
            markup = m.get_markup()

            for diff in diffs:
                l = int(diff.split('-')[0])
                w = int(diff.split('-')[1])
                s = int(diff.split('-')[2])
                syllable = markup.lines[l].words[w].syllables[s]
                if syllable.stress != -1:
                    syllable.stress = -1
                else:
                    for i in range(len(syllable.text)):
                        if syllable.text[i] in VOWELS:
                            syllable.stress = syllable.begin + i


            m = Markup()