Exemple #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
        }
Exemple #2
0
    def handle(self, *args, **options):
        users = list(User.objects.all())

        for i in range(10):
            t = Topic()
            t.name = u'Topic Name {}'.format(i)
            t.description = u'Topic Description {}'.format(i)
            t.save()
        topics = list(Topic.objects.all())

        for j in range(100):
            q = Question()
            q.author = random.choice(users)
            q.title = u'title {}'.format(j)
            q.text = u'text {}'.format(j)
            q.pub_date = datetime.datetime.now()
            q.is_published = True
            q.save()
            q.topics = random.sample(topics, random.randint(1, 6))
        questions = list(Question.objects.all())

        for k in range(100):
            c = Comment()
            c.author = random.choice(users)
            c.question = random.choice(questions)
            c.text = u'text {}'.format(k)
            c.pub_date = datetime.datetime.now()
            c.save()
Exemple #3
0
    def save(self, user):
        model = Topic(title=self.cleaned_data['title'],
                      node=self.cleaned_data['node'],
                      content=self.cleaned_data['content'],
                      creater=user)
        model.save()

        return model
Exemple #4
0
 def add_topics(self, topics):
     for t_name in topics:
         try:
             topic = Topic.objects.get(name=t_name)
         except Topic.DoesNotExist:
             topic = Topic(name=t_name)
             topic.save()
         self.topics.add(topic)
Exemple #5
0
    def save(self, user):
        model = Topic(
            title = self.cleaned_data['title'],
            node = self.cleaned_data['node'],
            content = self.cleaned_data['content'],
            creater = user)
        model.save()

        return model
Exemple #6
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
        }
Exemple #7
0
    def test_index_with_one_topic(self):
        new_topic = Topic(slug="binary-numbers",
                          name="Binary Numbers",
                          content="content",
                          other_resources="content",
                          icon="icon")
        new_topic.save()

        url = reverse("topics:index")
        response = self.client.get(url)
        self.assertEqual(200, response.status_code)
        self.assertQuerysetEqual(response.context["all_topics"],
                                 ["<Topic: Binary Numbers>"])
Exemple #8
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
        }
    def create_topic(self, number):
        """Create topic object.

        Args:
            number: Identifier of the topic (int).

        Returns:
            Topic object.
        """
        topic = Topic(
            slug="topic-{}".format(number),
            name="Topic {}".format(number),
            content="<p>Content for topic {}.</p>".format(number),
        )
        topic.save()
        return topic
Exemple #10
0
def create_topic(request):
    def render_page():
        params = {'all_subjects':Subject.objects.all()}
        return render(request, 'topics/create_topic.html', params)
        
    if request.method == 'POST':
        subject_name = request.POST.get('subject')
        topic_name = request.POST.get('topic')
        
        if not Topic.objects.filter(name=topic_name):
            subj = Subject.objects.get(name=subject_name)
            topic = Topic.create(topic_name, subj)
            topic.save()
            
            for vocab in _vocab_words(topic_name):
                vocab.topic = topic
                vocab.save()
                
            for link in _bing_api_call(topic_name):
                link.topic = topic
                link.save()
        else:
            topic = Topic.objects.get(name=topic_name)
        return HttpResponseRedirect(reverse('topics.views.view_topic', args=(topic.slug,)))
    else:
        return render_page()
Exemple #11
0
def create_topic(request):
    def render_page():
        params = {'all_subjects': Subject.objects.all()}
        return render(request, 'topics/create_topic.html', params)

    if request.method == 'POST':
        subject_name = request.POST.get('subject')
        topic_name = request.POST.get('topic')

        if not Topic.objects.filter(name=topic_name):
            subj = Subject.objects.get(name=subject_name)
            topic = Topic.create(topic_name, subj)
            topic.save()

            for vocab in _vocab_words(topic_name):
                vocab.topic = topic
                vocab.save()

            for link in _bing_api_call(topic_name):
                link.topic = topic
                link.save()
        else:
            topic = Topic.objects.get(name=topic_name)
        return HttpResponseRedirect(
            reverse('topics.views.view_topic', args=(topic.slug, )))
    else:
        return render_page()
Exemple #12
0
def initialize():
    # init user
    admin = 'cacate'
    if not getuserbyname(admin):
        user = newuser(truename=admin, password='******',
                email='*****@*****.**', description="I am the boss!", avatar=None)
        user.is_staff = True
        user.is_superuser = True
        user.save()
    for i in range(10):
        truename = 'test%d'%i
        if not getuserbyname(truename):
            user = newuser(truename=truename, password='******',
                    email='*****@*****.**'%i, description="%d"%i, avatar=None)
            print('create user %s'%truename)

    # init genres
    glist = ['Quantum Computation', 'Machine Learning',
            'Tensor Network', 'Monte Carlo']
    for g in glist:
        try:
            g = Genre(text=g)
            g.save()
            print('create genre %s'%g)
        except Exception:
            pass

    # init topics
    for i in range(10):
        try:
            t = Topic(text='topic%d'%i, ref = None, url='www.baidu.com',
                    add_date=datetime.now(), genre=random.choice(Genre.objects.all()),
                    user=getuserbyname('test%d'%random.randint(0,9)))
            t.save()
            print('create topic %s'%t)
        except:
            pass

    for t in Topic.objects.all():
        try:
            for j in range(5):
                kind = random.choice([1, 0, -1])
                v = newvote(topic=t, user=getuserbyname('test%d'%j), kind=kind)
                print('create vote %s'%v)
        except Exception:
            print(traceback.format_exc())
Exemple #13
0
def topic(**kwargs):
    """Return a topic with enough stuff filled out that it can be saved."""
    defaults = {
        'title': u'đ' + str(datetime.now()),
        'display_order': 1,
        'visible': True
    }
    defaults.update(kwargs)
    if 'slug' not in kwargs:
        defaults['slug'] = slugify(defaults['title'])
    return Topic(**defaults)
Exemple #14
0
    def handle(self, *args, **options):
        users = list(User.objects.all())

        for i in range(10):
            t = Topic()
            t.name = u'Topic Name {}'.format(i)
            t.description = u'Topic Description {}'.format(i)
            t.save()
        topics = list(Topic.objects.all())

        for j in range(100):
            q = Question()
            q.author = random.choice(users)
            q.title = u'title {}'.format(j)
            q.text = u'text {}'.format(j)
            q.pub_date = datetime.datetime.now()
            q.is_published = True
            q.save()
            q.topics = random.sample(topics, random.randint(1, 6))
        questions = list(Question.objects.all())

        for k in range(100):
            c = Comment()
            c.author = random.choice(users)
            c.question = random.choice(questions)
            c.text = u'text {}'.format(k)
            c.pub_date = datetime.datetime.now()
            c.save()
Exemple #15
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
        }
Exemple #16
0
    def run(self):
        chunks = {}

        chunks['bottom'] = (self.amount * 60) / 100
        chunks['middle'] = (self.amount * 30) / 100
        chunks['top'] = self.amount - (chunks['bottom'] + chunks['middle'])

        bottom_vals = [random.randint(1, 80) for i in range(chunks['bottom'])]
        bottom = []

        print colored.white("Generating topics level 0:")
        for elem in progress.bar(bottom_vals):
            new_topic = Topic()
            bottom.append(new_topic)
            
            new_topic.save()
        middle = []
        transaction.commit()

        print colored.white("Generating topics level 1:")
        for i in progress.bar(range(chunks['middle'])):
            children = random.sample(bottom, random.randint(8, 11))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

            middle.append(new_topic)
        
        print colored.white("Generating topics level 2:")
        for i in progress.bar(range(chunks['top'])):
            children = random.sample(middle, random.randint(4, 7))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

        transaction.commit()
Exemple #17
0
 def clean_topics(self):
     topics = self.cleaned_data.get('topics', []).strip()
     if topics:
         topics = ', '.join(Topic.parse_names(topics))
     return topics
    def load(self):
        """Load the content for a topic.

        Raise:
            MissingRequiredFieldError: when no object can be found with the matching
                attribute.
        """
        topic_structure = self.load_yaml_file(self.structure_file_path)

        unit_plans = topic_structure.get("unit-plans", None)
        if unit_plans is None:
            raise MissingRequiredFieldError(self.structure_file_path,
                                            ["unit-plans"], "Topic")

        topic_translations = self.get_blank_translation_dictionary()

        content_filename = "{}.md".format(self.topic_slug)
        content_translations = self.get_markdown_translations(content_filename)
        for language, content in content_translations.items():
            topic_translations[language]["content"] = content.html_string
            topic_translations[language]["name"] = content.title

        if "other-resources" in topic_structure and topic_structure[
                "other-resources"] is not None:
            other_resources_filename = topic_structure["other-resources"]
            other_resources_translations = self.get_markdown_translations(
                other_resources_filename)
            for language, content in other_resources_translations.items():
                topic_translations[language][
                    "other_resources"] = content.html_string

        # Check if icon is given
        if "icon" in topic_structure:
            topic_icon = topic_structure["icon"]
            if topic_icon is not None:
                find_image_files([topic_icon], self.structure_file_path)
            else:
                topic_icon = None
        else:
            topic_icon = None

        # Create topic objects and save to the db
        topic = Topic(
            slug=self.topic_slug,
            icon=topic_icon,
        )

        self.populate_translations(topic, topic_translations)
        self.mark_translation_availability(topic,
                                           required_fields=["name", "content"])
        topic.save()

        self.log("Added Topic: {}".format(topic.name))

        # Load programming challenges
        if "programming-challenges" in topic_structure:
            programming_challenges_structure_file_path = topic_structure[
                "programming-challenges"]
            if programming_challenges_structure_file_path is not None:
                programming_challenges_path, structure_filename = os.path.split(
                    programming_challenges_structure_file_path)
                self.factory.create_programming_challenges_loader(
                    topic,
                    base_path=self.base_path,
                    content_path=os.path.join(self.content_path,
                                              programming_challenges_path),
                    structure_filename=structure_filename).load()

        # Load unit plans
        for unit_plan_file_path in unit_plans:
            content_path, structure_filename = os.path.split(
                unit_plan_file_path)
            self.factory.create_unit_plan_loader(
                topic,
                base_path=self.base_path,
                content_path=os.path.join(self.content_path, content_path),
                structure_filename=structure_filename).load()

        if "curriculum-integrations" in topic_structure:
            curriculum_integrations_structure_file_path = topic_structure[
                "curriculum-integrations"]
            if curriculum_integrations_structure_file_path is not None:
                curriculum_integrations_path, structure_filename = os.path.split(
                    curriculum_integrations_structure_file_path)
                self.factory.create_curriculum_integrations_loader(
                    topic,
                    base_path=self.base_path,
                    content_path=os.path.join(self.content_path,
                                              curriculum_integrations_path),
                    structure_filename=structure_filename).load()

        self.log("")
Exemple #19
0
                                 password=os.environ.get('DUMMY_PASS')))

public_user = User.objects.create_user(username=os.environ.get('PUBLIC_USER'),
                                       password=os.environ.get('PUBLIC_PASS'))

tz = timezone.get_current_timezone()

f = open('populate_lorem_ipsium.txt', 'r')
if f.mode == 'r':
    text = f.read()
else:
    text = 'nothing'

Topic.objects.all().delete()
for i in range(100):
    t = Topic()
    day = random.randrange(1, 27)
    month = random.randrange(1, 12)
    year = 2010 + random.randrange(1, 8)
    date = datetime.date(year, month, day)
    time = datetime.time(8, 0, tzinfo=timezone.get_current_timezone())
    t.published_at = datetime.datetime.combine(date, time)
    t.title = 'New Article {}/{}/{}'.format(day, month, year)
    t.slug = 'new-article-{}-{}-{}-{}'.format(i, day, month, year)
    t.content = text
    t.author = users[random.randrange(0, len(users) - 1)]
    Topic.save(t)

topics = Topic.objects.all()
for t in topics:
    for i in range(random.randrange(2, 7)):
Exemple #20
0
 def clean_topics(self):
     topics = self.cleaned_data['topics'].strip()
     if topics:
         topics = ', '.join(Topic.parse_names(topics))
     return topics
Exemple #21
0
    def run(self):
        chunks = {}

        chunks['bottom'] = (self.amount * 60) / 100
        chunks['middle'] = (self.amount * 30) / 100
        chunks['top'] = self.amount - (chunks['bottom'] + chunks['middle'])

        bottom_vals = [random.randint(1, 80) for i in range(chunks['bottom'])]
        bottom = []

        print colored.white("Generating topics level 0:")
        for elem in progress.bar(bottom_vals):
            new_topic = Topic()
            bottom.append(new_topic)

            new_topic.save()
        middle = []
        transaction.commit()

        print colored.white("Generating topics level 1:")
        for i in progress.bar(range(chunks['middle'])):
            children = random.sample(bottom, random.randint(8, 11))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

            middle.append(new_topic)

        print colored.white("Generating topics level 2:")
        for i in progress.bar(range(chunks['top'])):
            children = random.sample(middle, random.randint(4, 7))

            new_topic = Topic()
            new_topic.save()

            for child in children:
                new_topic.parent.add(child)

        transaction.commit()
    def load(self):
        """Load the content for a topic.

        Raise:
            MissingRequiredFieldError: when no object can be found with the matching
                attribute.
        """
        topic_structure = self.load_yaml_file(self.structure_file_path)

        unit_plans = topic_structure.get("unit-plans", None)
        if unit_plans is None:
            raise MissingRequiredFieldError(self.structure_file_path,
                                            ["unit-plans"], "Topic")

        # Convert the content to HTML
        topic_content = self.convert_md_file(
            os.path.join(self.BASE_PATH, "{}.md".format(self.topic_slug)),
            self.structure_file_path)

        # If other resources are given, convert to HTML
        if "other-resources" in topic_structure:
            topic_other_resources_file = topic_structure["other-resources"]
            if topic_other_resources_file is not None:
                other_resources_content = self.convert_md_file(
                    os.path.join(self.BASE_PATH, topic_other_resources_file),
                    self.structure_file_path)
                topic_other_resources_html = other_resources_content.html_string
            else:
                topic_other_resources_html = None
        else:
            topic_other_resources_html = None

        # Check if icon is given
        if "icon" in topic_structure:
            topic_icon = topic_structure["icon"]
            if topic_icon is not None:
                find_image_files([topic_icon], self.structure_file_path)
            else:
                topic_icon = None
        else:
            topic_icon = None

        # Create topic objects and save to the db
        topic = Topic(slug=self.topic_slug,
                      name=topic_content.title,
                      content=topic_content.html_string,
                      other_resources=topic_other_resources_html,
                      icon=topic_icon)
        topic.save()

        self.log("Added Topic: {}".format(topic.name))

        # Load programming challenges
        if "programming-challenges" in topic_structure:
            programming_challenges_structure_file_path = topic_structure[
                "programming-challenges"]
            if programming_challenges_structure_file_path is not None:
                self.factory.create_programming_challenges_loader(
                    programming_challenges_structure_file_path, topic,
                    self.BASE_PATH).load()

        # Load unit plans
        for unit_plan_file_path in unit_plans:
            self.factory.create_unit_plan_loader(unit_plan_file_path, topic,
                                                 self.BASE_PATH).load()

        if "curriculum-integrations" in topic_structure:
            curriculum_integrations_structure_file_path = topic_structure[
                "curriculum-integrations"]
            if curriculum_integrations_structure_file_path is not None:
                self.factory.create_curriculum_integrations_loader(
                    curriculum_integrations_structure_file_path, topic,
                    self.BASE_PATH).load()

        self.log("")
Exemple #23
0
def buildTopic(key):
    return Topic(key=key)
Exemple #24
0
    def update(self, request):

        meeting = Meeting.objects.get(id = request.data.get('meeting'))

        meeting.title = request.data.get('title')
        meeting.subject_matter = request.data.get('subject_matter')
        meeting.status = request.data.get('status')
        meeting.initial_date = request.data.get('initial_date')
        meeting.final_date = request.data.get('final_date')
        meeting.initial_hour = request.data.get('initial_hour')
        meeting.final_hour = request.data.get('final_hour')
        meeting.save()

        if request.data.get('topics') != None:

            for topic in request.data.get('topics'):

                new_topic = Topic()
                new_topic.title = topic['title']

                if Topic.objects.all().filter(title = new_topic.title) != True:

                    new_topic.save()
                    meeting.topics.add(new_topic)

        if request.data.get('rules') != None:

            for rules in request.data.get('rules'):

                new_rule = Rules()
                new_rule.title = rules['title']

                if Rules.objects.all().filter(title = new_rule.title) != True:

                    new_rule.save()
                    meeting.rules.add(new_rule)

        if request.data.get('users') != None:

            for users in request.data.get('users'):

                new_user = User.objects.get(id = users['id'])
                meeting.users.add(new_user)

        if request.data.get('questtionaire') != None:

            questtionaires = Questionnaire()
            questtionaires.title = request.data.get('questtionaire').get('title')
            questtionaires.save()
            meeting.questtionaire.add(questtionaires)

            order = 1

            for quiz in request.data.get('questtionaire').get('questions'):

                new_quiz = Quiz()
                new_quiz.title = quiz['title']
                new_quiz.order = order
                new_quiz.save()

                for user in meeting.users.all():

                    if user.name == str(meeting.meeting_leader):

                        print('Usuário é o Líder da Reunião')

                    else:

                        new_quiz.users.add(user)

                for choice in quiz.get('choices'):

                    new_choice = Choice()
                    new_choice.title = choice
                    new_choice.save()
                    new_quiz.choices.add(new_choice)

                new_quiz.questtionaire = questtionaires
                new_quiz.save()
                order += 1

        return meeting
def read_csv(source_csv, dept_name, order='esd'):
    count = 0
    #with codecs.open(source_csv, 'rb', encoding='utf-8') as csvfile:
    with open(source_csv) as csvfile:
        reader = unicode_csv_reader(csvfile)

        #just print the first row:
        print '>, <'.join(reader.next())

        for row in reader:
            count += 1

            if order == 'esd':
                url = row[0]
                alias = row[2]
                #aka status/notes, or topic?
                tag = row[3]
                notes = row[4]
                title = row[5]
                page_views = to_int(row[6])
                page_views_unique = to_int(row[7])
                average_time = row[8]
                entrances = to_int(row[9])
                bounce_rate = row[10]
                exit_percent = row[11]
                section_id = row[12]
                categories = ','.join(row[13:])
            else:
                raise ValueError, "Unknown Order: %s" % order

            dept_options = Department.objects.filter(name=dept_name)
            if len(dept_options):
                department = dept_options[0]
            else:
                print "Be sure to import departments with 'make_departments.py'"
                raise ValueError, "Couldn't find department: %s" % dept_name

            #there is some filtering we can do here...
            tag = re.sub("DAM: keep", '', tag)
            tag = re.sub("DAM: Keep", '', tag)

            tags = []
            items = tag.split('/')
            for item in items:
                current = item.strip()
                if not current in tags:
                    tags.append(current)            

            default_topic = None
            for tag in tags:
                #aka status/notes, or topic?
                #tag = row[3]
                topic_options = Topic.objects.filter(name=tag)
                if len(topic_options):
                    topic = topic_options[0]
                elif tag:
                    topic = Topic()
                    #TODO: associate alias here?
                    topic.name = tag
                    topic.tag = to_tag(tag)
                else:
                    topic = None

                if topic:
                    #doing this again, for updates
                    #topic.name = tag
                    topic.save()
                    #print "Save topic here"
                    if not default_topic:
                        default_topic = topic

            page_options = Page.objects.filter(url=url)
            if len(page_options):
                page = page_options[0]
            elif url:
                #make a new one:
                page = Page()
                page.url = url

                page.alias = alias
                
                page.notes = notes
                page.title = title
                page.page_views = page_views
                page.page_views_unique = page_views_unique
                page.average_time = average_time
                page.entrances = entrances
                page.bounce_rate = bounce_rate
                page.exit_percent = exit_percent
                page.section_id = section_id
                page.categories = categories
                
            else:
                page = None

            if page:
                page.position = count
                page.default_topic = topic
                page.site = "bloomington.in.gov"
                page.save()
                #print "Save page here"

            department_page_options = DepartmentPage.objects.filter(page=page, department=department)
            if len(department_page_options):
                department_page = department_page_options[0]
            elif department and page:
                department_page = DepartmentPage()
                department_page.page = page
                department_page.department = department
            else:
                department_page = None

            if department_page:
                department_page.save()
                #print "Save department_page here"


            page_topic_options = PageTopic.objects.filter(page=page, topic=topic)
            if len(page_topic_options):
                page_topic = page_topic_options[0]
            elif page and topic:
                page_topic = PageTopic()
                page_topic.page = page
                page_topic.topic = topic
            else:
                #print "no page: %s -OR- no topic: %s" % (page, topic)
                page_topic = None

            if page_topic:
                page_topic.save()