コード例 #1
0
    def process_objects(self, author):
        # Circuit
        circuit = Circuit(
            name=self.cleaned_data.get('name', ''),
            category=self.cleaned_data.get('category', ''),
            description=self.clean_description(),
            author=author,
            adult_content=self.cleaned_data['adult_content']
        )

        circuit.save()
        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)
        multiple = False
        if len(new_topics) > 0:
            multiple = True
        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)
        circuit.save()
        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
コード例 #2
0
ファイル: forms.py プロジェクト: biznixcn/WR
    def process_objects(self, author):
        name = self.cleaned_data.get('name', u'')
        category = self.cleaned_data.get('category',
            constants.DEFAULT_CIRCUIT_CATEGORY)
        description = self.cleaned_data.get('description', u'')

        # Trimming more than one 2 linebreaks to one
        line_breaks = re.search('.*?(\s{2,}).*?', description)
        if line_breaks is not None:
            trimmed_description = description
            for line_break in line_breaks.groups():
                trimmed_description = description.replace(line_break, u'\r\n')
            description = trimmed_description

        # Circuit
        circuit = Circuit(
            name=name,
            category=category,
            description=description,
            author=author,
            adult_content=self.cleaned_data.get('adult_content', False)
        )
        circuit.save()

        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data.get('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)

        multiple = False
        if len(new_topics) > 0:
            multiple = True

        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)

        circuit.save()

        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
コード例 #3
0
    def process_objects(self, author):
        name = self.cleaned_data.get('name', u'')
        category = self.cleaned_data.get('category',
                                         constants.DEFAULT_CIRCUIT_CATEGORY)
        description = self.cleaned_data.get('description', u'')

        # Trimming more than one 2 linebreaks to one
        line_breaks = re.search('.*?(\s{2,}).*?', description)
        if line_breaks is not None:
            trimmed_description = description
            for line_break in line_breaks.groups():
                trimmed_description = description.replace(line_break, u'\r\n')
            description = trimmed_description

        # Circuit
        circuit = Circuit(name=name,
                          category=category,
                          description=description,
                          author=author,
                          adult_content=self.cleaned_data.get(
                              'adult_content', False))
        circuit.save()

        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data.get('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)

        multiple = False
        if len(new_topics) > 0:
            multiple = True

        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)

        circuit.save()

        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
コード例 #4
0
    def process_objects(self, author):
        # Circuit
        circuit = Circuit.objects.get(pk=self.cleaned_data.get('circuit_id'))
        circuit.name = self.cleaned_data.get('name', '')
        circuit.category = self.cleaned_data.get('category',
            constants.DEFAULT_CIRCUIT_CATEGORY)
        circuit.description = self.clean_description()
        circuit.adult_content = self.cleaned_data['adult_content']

        circuit.author = author
        circuit.save()

        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data.get('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)
        multiple = False
        if len(new_topics) > 0:
            multiple = True
        # Remove all previous topics
        circuit.topics.clear()
        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)
        circuit.save()
        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }