Ejemplo n.º 1
0
def suggestion_approve(question_id):
    question = cdw.suggestions.with_id(question_id)
    new_question = Question(category=question.category, text=question.text)
    new_question.save()
    question.delete()
    flash("Question approved", "info")
    return redirect("/admin/debates/suggestions")
Ejemplo n.º 2
0
def suggestion_approve(question_id):
    question = cdw.suggestions.with_id(question_id)
    new_question = Question(
            category=question.category,
            text=question.text)
    new_question.save()
    question.delete()
    flash("Question approved", "info")
    return redirect("/admin/debates/suggestions")
Ejemplo n.º 3
0
    def test_api_threads_post_from_kiosk_with_phone(self):
        # Get the user we just created
        from cdw.models import User, Question

        # Get a question to post to
        question = Question.objects().first()

        # Create and get the user
        r = self.doApiPost('/api/users', {
            "username": "******",
            "phonenumber": "3155690000"
        })
        user = User.objects(username="******").first()

        # Post as if from the kiosk
        params = {
            'yesno': '1',
            'author': str(user.id),
            'text': 'Creating a thread',
            'origin': 'kiosk'
        }
        r = self.doApiPost('/api/questions/%s/threads' % str(question.id),
                           params)

        # Get the user again
        user = User.objects(username="******").first()

        # Check if their thread subscription was set
        assert str(user.threadSubscription.id) in r.data
Ejemplo n.º 4
0
    def to_question(self):
        try:
            user = cdw.users.with_id(self.author.data)
        except:
            user = None

        return Question(category=cdw.categories.with_id(self.category.data),
                        author=user,
                        text=self.text.data)
Ejemplo n.º 5
0
 def test_api_threads_post_from_kiosk_with_phone(self):
     # Get the user we just created
     from cdw.models import User, Question
     
     # Get a question to post to
     question = Question.objects().first()
     
     # Create and get the user 
     r = self.doApiPost('/api/users', {"username":"******", "phonenumber":"3155690000"})
     user = User.objects(username="******").first()
             
     # Post as if from the kiosk
     params = {'yesno': '1', 'author': str(user.id), 'text': 'Creating a thread', 'origin':'kiosk'}
     r = self.doApiPost('/api/questions/%s/threads' % str(question.id), params)
     
     # Get the user again
     user = User.objects(username="******").first()
     
     # Check if their thread subscription was set
     assert str(user.threadSubscription.id) in r.data
Ejemplo n.º 6
0
def do_db_seed():
    """
    Python based seed data
    """
    mongoengine.connect('%(app_mongodb_db)s' % env,
                        '%(app_mongodb_username)s' % env,
                        '%(app_mongodb_password)s' % env,
                        host='%(app_mongodb_host)s' % env,
                        port=int('%(app_mongodb_port)s' % env))
    
    User.drop_collection()
    Category.drop_collection()
    Question.drop_collection()
    Thread.drop_collection()
    Post.drop_collection()
    SaasConnection.drop_collection()
    
    users = []
    phone = 3155696216
    for f, l in [('matt','wright'),('sundar','raman'),('ethan','holda'),
                 ('philipp','rockell'),('jen','snyder')]:
        phone += 1
        users.append(UserFactory(username=f, 
                                 email='*****@*****.**' % (f, l), 
                                 phoneNumber=str(phone)))
    
    categories = []
    for c in ['Politics', 'Environment', 'Religion', 'World', 'Technology', 'Misc']:
        categories.append(CategoryFactory(name=c))
        
    questions = []
    for q, c, u, a, ed in [('Archived question?',0,0,False, datetime.timedelta(days=-7)),
                           ('Should the legal age to recieve a driver\'s license be raised?',0,0,True, datetime.timedelta(days=7)),
                           ('Does the employment strategy directed to help disadvantaged ethnic minorities constitute racial discrimination?',0,1,False, datetime.timedelta(days=14)),
                           ('Is space exploration a waste of federal tax dollars?',4,2,False, datetime.timedelta(days=21)),
                           ('Should creationism and evolution be taught side by side?',2,3,False, datetime.timedelta(days=28)),]:
        questions.append(QuestionFactory(text=q, category=categories[c], author=users[u], active=a, endDate=datetime.datetime.utcnow() + ed))
        
    threads = []
    for u, yn, t in [(0, 1, 'Too many young drivers are causing a lot of accidents on the road'),
                 (1, 0, 'It\'s fine. You need to start driving at some point.'),
                 (2, 1, 'Yes, their bad driving habits are causing my insurance prices to rise.'),
                 (3, 1, 'It should be raise to 18 just like most goverment priviledges are set to.'),
                 (4, 0, 'The driving age is just fine, there\'s no reason to suddenly change it.'),]:
        
        for i in range(2):
            for n in range(20):
                thread = ThreadFactory(question=questions[i], firstPost=None, postCount=1, yesNo=None, origin='web')
                threads.append(thread)
                thread.firstPost = PostFactory(author=users[u], text=t, yesNo=yn, thread=thread, 
                                               created=datetime.datetime.utcnow() + datetime.timedelta(days=random.randint(-20, 0)))
                thread.created = thread.firstPost.created
                thread.yesNo = thread.firstPost.yesNo
                thread.authorId = thread.firstPost.author.id
                thread.save()
    
    import lipsum
    g = lipsum.Generator()
    
    for n in range(1, len(threads)):
        for i in range(0, random.randint(0, 30)):
            thread = threads[n]
            PostFactory(author=users[random.randint(0,4)], 
                        text=g.generate_paragraph(start_with_lorem=False)[0:random.randint(20, 139)],
                        yesNo=random.randint(0,1),
                        thread=thread,
                        created=thread.created + datetime.timedelta(seconds=i))
            thread.postCount += 1
            thread.save()
            
    user = users[0]
    user.threadSubscription = threads[7]
    user.save()