def update_from_pending_change(self, commit_id, changeset):
        """Updates the data from a server-side pending changeset.

        This will fetch the metadata from the server and update the fields on
        the review request.
        """
        if not changeset:
            raise InvalidChangeNumberError()

        # If the SCM supports changesets, they should always include a number,
        # summary and description, parsed from the changeset description. Some
        # specialized systems may support the other fields, but we don't want
        # to clobber the user-entered values if they don't.
        self.commit = commit_id

        if self.rich_text:
            description = markdown_escape(changeset.description)
            testing_done = markdown_escape(changeset.testing_done)
        else:
            description = changeset.description
            testing_done = changeset.testing_done

        self.summary = changeset.summary
        self.description = description

        if testing_done:
            self.testing_done = testing_done

        if changeset.branch:
            self.branch = changeset.branch

        if changeset.bugs_closed:
            self.bugs_closed = ','.join(changeset.bugs_closed)
    def update_from_pending_change(self, commit_id, changeset):
        """Updates the data from a server-side pending changeset.

        This will fetch the metadata from the server and update the fields on
        the review request.
        """
        if not changeset:
            raise InvalidChangeNumberError()

        # If the SCM supports changesets, they should always include a number,
        # summary and description, parsed from the changeset description. Some
        # specialized systems may support the other fields, but we don't want
        # to clobber the user-entered values if they don't.
        self.commit = commit_id

        if self.rich_text:
            description = markdown_escape(changeset.description)
            testing_done = markdown_escape(changeset.testing_done)
        else:
            description = changeset.description
            testing_done = changeset.testing_done

        self.summary = changeset.summary
        self.description = description

        if testing_done:
            self.testing_done = testing_done

        if changeset.branch:
            self.branch = changeset.branch

        if changeset.bugs_closed:
            self.bugs_closed = ','.join(changeset.bugs_closed)
    def update_from_committed_change(self, commit_id):
        """Updates from a committed change present on the server.

        Fetches the commit message and diff from the repository and sets the
        relevant fields.
        """
        commit = self.repository.get_change(commit_id)
        summary, message = commit.split_message()

        self.commit = commit_id

        self.summary = summary.strip()
        if self.rich_text:
            self.description = markdown_escape(message.strip())
        else:
            self.description = message.strip()

        DiffSet.objects.create_from_data(
            repository=self.repository,
            diff_file_name='diff',
            diff_file_contents=commit.diff.encode('utf-8'),
            parent_diff_file_name=None,
            parent_diff_file_contents=None,
            diffset_history=self.get_review_request().diffset_history,
            basedir='/',
            request=None)
    def update_from_committed_change(self, commit_id):
        """Updates from a committed change present on the server.

        Fetches the commit message and diff from the repository and sets the
        relevant fields.
        """
        commit = self.repository.get_change(commit_id)
        summary, message = commit.split_message()

        self.commit = commit_id

        self.summary = summary.strip()
        if self.rich_text:
            self.description = markdown_escape(message.strip())
        else:
            self.description = message.strip()

        DiffSet.objects.create_from_data(
            repository=self.repository,
            diff_file_name='diff',
            diff_file_contents=commit.diff.encode('utf-8'),
            parent_diff_file_name=None,
            parent_diff_file_contents=None,
            diffset_history=self.get_review_request().diffset_history,
            basedir='/',
            request=None)
Example #5
0
def markdown_escape_filter(text, is_rich_text):
    """Returns Markdown text, escaping if necessary.

    If ``is_rich_text`` is ``True``, then the provided text will be
    returned directly. Otherwise, it will first be escaped and then returned.
    """
    if is_rich_text:
        return text
    else:
        return markdown_escape(text)
Example #6
0
def markdown_escape_filter(text, is_rich_text):
    """Returns Markdown text, escaping if necessary.

    If ``is_rich_text`` is ``True``, then the provided text will be
    returned directly. Otherwise, it will first be escaped and then returned.
    """
    if is_rich_text:
        return text
    else:
        return markdown_escape(text)
Example #7
0
    def render_value(self, text):
        """Returns the value of the field.

        If Markdown is enabled, and the text is not in Markdown format,
        the text will be escaped.
        """
        text = text or ''

        if self.enable_markdown and not self.is_text_markdown(text):
            text = markdown_escape(text)

        return escape(text)
Example #8
0
    def render_value(self, text):
        """Returns the value of the field.

        If Markdown is enabled, and the text is not in Markdown format,
        the text will be escaped.
        """
        text = text or ''

        if self.enable_markdown and not self.is_text_markdown(text):
            return markdown_escape(text)
        else:
            return text
Example #9
0
    def normalize_text(self, obj, text, request=None):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        object is set for having rich text.
        """
        text_type = self.get_requested_text_type(obj, request)

        if text_type == self.TEXT_TYPE_PLAIN and obj.rich_text:
            text = markdown_unescape(text)
        elif text_type == self.TEXT_TYPE_MARKDOWN and not obj.rich_text:
            text = markdown_escape(text)

        return text
Example #10
0
    def get_data_attributes(self):
        attrs = super(BaseTextAreaField, self).get_data_attributes()

        if self.always_render_markdown or self.is_text_markdown(self.value):
            attrs['rich-text'] = 'true'

            if self.is_text_markdown(self.value):
                norm_value = self.value
            else:
                norm_value = markdown_escape(self.value)

            attrs['raw-value'] = norm_value

        return attrs
Example #11
0
    def normalize_text(self, obj, text, request=None):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        object is set for having rich text.
        """
        text_type = self.get_requested_text_type(obj, request)

        if text_type == self.TEXT_TYPE_PLAIN and obj.rich_text:
            text = markdown_unescape(text)
        elif text_type == self.TEXT_TYPE_MARKDOWN and not obj.rich_text:
            text = markdown_escape(text)

        return text
Example #12
0
    def _normalize_text(self, text, field_is_rich_text, force_text_type):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        value should be set for rich text.
        """
        assert force_text_type

        if text is not None:
            if force_text_type == self.TEXT_TYPE_PLAIN and field_is_rich_text:
                text = markdown_unescape(text)
            elif (force_text_type == self.TEXT_TYPE_MARKDOWN and
                  not field_is_rich_text):
                text = markdown_escape(text)
            elif force_text_type == self.TEXT_TYPE_HTML:
                if field_is_rich_text:
                    text = render_markdown(text)
                else:
                    text = escape(text)

        return text
Example #13
0
    def _normalize_text(self, text, field_is_rich_text, force_text_type):
        """Normalizes text to the proper format.

        This considers the requested text format, and whether or not the
        value should be set for rich text.
        """
        assert force_text_type

        if text is not None:
            if force_text_type == self.TEXT_TYPE_PLAIN and field_is_rich_text:
                text = markdown_unescape(text)
            elif (force_text_type == self.TEXT_TYPE_MARKDOWN
                  and not field_is_rich_text):
                text = markdown_escape(text)
            elif force_text_type == self.TEXT_TYPE_HTML:
                if field_is_rich_text:
                    text = render_markdown(text)
                else:
                    text = escape(text)

        return text