Example #1
0
def upload_img(request):
    if not request.FILES:
        return render(
            request, 'feed/index.html', {
                'error_message': "You Should Choose A File Before Upload",
                'posts': Post.objects.filter(share=True).order_by('-pub_date'),
            })
    if request.method == 'POST':
        img = request.FILES['photo']
        post = Post(name=img.name, photo=img)
        post.save()
        request.session['photo_pk'] = post.pk
        context = {'post': post, 'crop_form': Crop_Form}
        return render(request, 'peditor/editor.html', context=context)
Example #2
0
        friends = json.load(f_f)
        user = [None] * 100

        print('Make admins and theirs posts')
        with open('private/admin_posts.json') as f:
            admin_posts = json.load(f)
            for p in admin_posts:
                if not User.objects.filter(username=p['author']).exists():
                    User.objects.create_user(username=p['author'],
                                             password='******')
                    # Put user in list
                    for i in friends['ends'][::-1]:
                        if user[i] is None:
                            user[i] = p['author']
                            break
                post = Post()
                post.author = User.objects.get(username=p['author'])
                post.text = p['text']
                if 'isPublic' in p:
                    post.isPublic = p['isPublic']
                post.save()

        print('Make random users and their random posts')
        with open('private/random_users.json') as f_u, open('private/random_posts.json', encoding='utf-8') as f_posts, \
                open('private/passwords.json') as f_pass:
            users = json.load(f_u)
            posts = json.load(f_posts)
            passwords = json.load(f_pass)
            for u in users:
                # Put user in list and setup password
                for i in range(100):
Example #3
0
 def test_post_representation(self):
     """Check the correctness of string representation"""
     post = Post(title="Test post")
     self.assertEquals(str(post), "Test post")