示例#1
0
 def cleanup_threads():
     for t in cdw.threads.all():
         doDel = False
         if isinstance(t.firstPost, DBRef) or t.firstPost == None:
             doDel = True
             
         elif isinstance(t.question, DBRef) or t.question == None:
             doDel = True
             
         elif isinstance(t.firstPost.author, DBRef) or t.firstPost.author == None:
             doDel = True
         
         '''
         try:
             cdw.users.with_id(str(t.authorId))
         except:
             doDel = True
         '''
                 
         if doDel:
             Post.objects(thread=t).delete()
             t.delete()
         else:
             t.postCount = cdw.posts.with_fields(thread=t).count()
             t.flags = t.firstPost.flags
             t.origin = t.firstPost.origin
             t.yesNo = t.firstPost.yesNo
             t.save()
     return 'success'
示例#2
0
def dashboard():
    days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=30)
    recent_posts_with_flags = Post.objects(created__gte=days_ago, 
                                           flags__gt=0).order_by('-flags')[:30]
    return render_template('admin/dashboard.html',
                           section_selector='dashboard',
                           page_selector='index',
                           recent_posts_with_flags=recent_posts_with_flags)
示例#3
0
 def test_delete_user_deletes_threads_and_posts(self):
     with self.testApp as app:
         app.post('/auth', data={"username":self.user.email, "password":"******"})
         r = app.delete('/admin/crud/users/%s' % str(self.user.id))
         assert 'Redirecting...' in r.data
         
         from cdw.models import Post
         posts = Post.objects(author=self.user)
         assert 0 == len(posts)
示例#4
0
    def to_post(self):
        try:
            responseTo = cdw.posts.with_id(self.responseto.data)
        except:
            responseTo = None

        return Post(yesNo=int(self.yesno.data),
                    text=self.text.data,
                    author=User.objects.with_id(self.author.data),
                    origin=self.origin.data,
                    responseTo=responseTo)
示例#5
0
    def test_delete_user_deletes_threads_and_posts(self):
        with self.testApp as app:
            app.post('/auth',
                     data={
                         "username": self.user.email,
                         "password": "******"
                     })
            r = app.delete('/admin/crud/users/%s' % str(self.user.id))
            assert 'Redirecting...' in r.data

            from cdw.models import Post
            posts = Post.objects(author=self.user)
            assert 0 == len(posts)
示例#6
0
 def threads_apply_first_post():
     for t in cdw.threads.all():
         p = Post.objects_recent_first(thread=t).first()
         
         if p is None:
             t.delete()
             continue
         
         t.firstPost = p 
         t.origin = t.firstPost.origin
         t.yesNo = t.firstPost.yesNo
         t.save()
     return "success"
示例#7
0
def thread_create():
    thread_form = ThreadCrudForm(csrf_enabled=False)
    current_app.logger.debug(thread_form.question_id.data)

    if thread_form.validate():
        author_id = thread_form.author_id.data if isinstance(
            thread_form.author_id.data,
            basestring) else thread_form.author_id.data[0]
        q = cdw.questions.with_id(thread_form.question_id.data)
        u = cdw.users.with_id(author_id)

        post = Post(yesNo=int(thread_form.yesno.data),
                    text=thread_form.text.data,
                    author=u,
                    likes=thread_form.likes.data,
                    origin=u.origin)
        cdw.create_thread(q, post)
        flash('Thread created successfully', 'info')
    else:
        current_app.logger.debug(thread_form.errors)
        flash('Error creating debate. Try again.', 'error')

    return redirect(request.referrer)
示例#8
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()
示例#9
0
            self.send_sms_message(msg, [user.phoneNumber])
            abort(500, description='User sent bad words')

        current_app.logger.debug('post via sms')

        thread = user.threadSubscription
        lastPost = None

        try:
            lastPost = cdw.posts.with_fields_first(author=user, thread=thread)

        except EntityNotFoundException:

            user = cdw.users.with_fields(
                phoneNumber=user.phoneNumber,
                origin='kiosk').order_by('-lastPostDate').first()

            lastPost = cdw.posts.with_fields_first(author=user, thread=thread)

        except Exception, e:
            current_app.logger.error('Error posting via SMS: %s' % e)
            raise

        p = Post(yesNo=lastPost.yesNo,
                 author=user,
                 text=message,
                 thread=thread,
                 origin="cell")

        cdw.post_to_thread(thread, p)