Пример #1
0
    def create(self, key):

        form = forms.TemplateForm(
            key, prototypes.TemplatePrototype.get_start_verificatos(key=key),
            self.request.POST)

        if not form.is_valid():
            return self.json_error('linguistics.templates.create.form_errors',
                                   form.errors)

        utg_template = utg_templates.Template()
        utg_template.parse(form.c.template,
                           externals=[v.value for v in key.variables])

        template = prototypes.TemplatePrototype.create(
            key=key,
            raw_template=form.c.template,
            utg_template=utg_template,
            verificators=form.verificators,
            author=self.account,
            restrictions=form.get_restrictions())

        prototypes.ContributionPrototype.get_for_or_create(
            type=relations.CONTRIBUTION_TYPE.TEMPLATE,
            account_id=template.author_id,
            entity_id=template.id,
            source=relations.CONTRIBUTION_SOURCE.MODERATOR
            if self.can_moderate_templates else
            relations.CONTRIBUTION_SOURCE.PLAYER,
            state=template.state.contribution_state)

        return self.json_ok(
            data={'next_url': url('linguistics:templates:show', template.id)})
Пример #2
0
    def edit(self):

        if self._template.state.is_ON_REVIEW and not self.can_moderate_templates and self._template.author_id != self.account.id:
            return self.auto_error(
                'linguistics.templates.edit.can_not_edit_anothers_template',
                u'Вы не можете редактировать вариант фразы, созданный другим игроком. Подождите пока его проверит модератор.'
            )

        if self._template.get_child():
            return self.auto_error(
                'linguistics.templates.edit.template_has_child',
                u'У этой фразы уже есть копия. Отредактируйте её или попросите автора копии сделать это.'
            )

        verificators = self._template.get_all_verificatos()

        form = forms.TemplateForm(self._template.key,
                                  verificators=verificators,
                                  initial=forms.TemplateForm.get_initials(
                                      self._template, verificators))

        return self.template(
            'linguistics/templates/edit.html', {
                'template':
                self._template,
                'form':
                form,
                'page_type':
                'keys',
                'copy_will_be_created':
                not (self._template.author_id == self.account.id
                     and self._template.state.is_ON_REVIEW),
                'LEXICON_KEY':
                keys.LEXICON_KEY
            })
Пример #3
0
    def update(self):

        if self._template.state.is_ON_REVIEW and not self.can_edit_templates and self._template.author_id != self.account.id:
            return self.auto_error('linguistics.templates.update.can_not_edit_anothers_template',
                                   u'Вы не можете редактировать вариант фразы, созданный другим игроком. Подождите пока его проверит модератор.')

        if self._template.get_child():
            return self.auto_error('linguistics.templates.update.template_has_child',
                                   u'У этой фразы уже есть копия. Отредактируйте её или попросите автора копии сделать это.')


        form = forms.TemplateForm(self._template.key,
                                  self._template.get_all_verificatos(),
                                  self.request.POST)

        if not form.is_valid():
            return self.json_error('linguistics.templates.update.form_errors', form.errors)

        utg_template = utg_templates.Template()
        utg_template.parse(form.c.template, externals=[v.value for v in self._template.key.variables])

        if (form.verificators == self._template.get_all_verificatos() and
            form.c.template == self._template.raw_template and
            form.get_restrictions() == self._template.raw_restrictions):
            return self.json_error('linguistics.templates.update.full_copy_restricted', u'Вы пытаетесь создать полную копию шаблона, в этом нет необходимости.')


        if self.can_edit_templates or (self._template.author_id == self.account.id and self._template.state.is_ON_REVIEW):
            self._template.update(raw_template=form.c.template,
                                  utg_template=utg_template,
                                  verificators=form.verificators,
                                  restrictions=form.get_restrictions())

            prototypes.ContributionPrototype.get_for_or_create(type=relations.CONTRIBUTION_TYPE.TEMPLATE,
                                                               account_id=self.account.id,
                                                               entity_id=self._template.id,
                                                               source=relations.CONTRIBUTION_SOURCE.MODERATOR if self.can_edit_templates else relations.CONTRIBUTION_SOURCE.PLAYER,
                                                               state=self._template.state.contribution_state)


            return self.json_ok(data={'next_url': url('linguistics:templates:show', self._template.id)})


        template = prototypes.TemplatePrototype.create(key=self._template.key,
                                                       raw_template=form.c.template,
                                                       utg_template=utg_template,
                                                       verificators=form.verificators,
                                                       restrictions=form.get_restrictions(),
                                                       author=self.account,
                                                       parent=self._template)

        prototypes.ContributionPrototype.get_for_or_create(type=relations.CONTRIBUTION_TYPE.TEMPLATE,
                                                           account_id=template.author_id,
                                                           entity_id=template.id,
                                                           source=relations.CONTRIBUTION_SOURCE.MODERATOR if self.can_edit_templates else relations.CONTRIBUTION_SOURCE.PLAYER,
                                                           state=template.state.contribution_state)


        return self.json_ok(data={'next_url': url('linguistics:templates:show', template.id)})
Пример #4
0
    def new(self, key):

        form = forms.TemplateForm(key, prototypes.TemplatePrototype.get_start_verificatos(key=key))

        return self.template('linguistics/templates/new.html',
                             {'key': key,
                              'form': form,
                              'page_type': 'keys',
                              'linguistics_settings': linguistics_settings,
                              'LEXICON_KEY': keys.LEXICON_KEY} )