Esempio n. 1
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
Esempio n. 2
0
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)):
        u = users[random.randrange(0, len(users) - 1)]
        upvoted = False
        if i > 0:
            topic_upvotes = Upvote.objects.filter(topic=t)
            for el in topic_upvotes:
                if el.upvoter == u:
                    upvoted = True