コード例 #1
0
ファイル: methods.py プロジェクト: d-trip/dtrip-mongo
def update_swm_post(post: str, tag=None):
    post = Post(post).export()
    prepare_post(post)

    tag = get_swm_tag(post['body'])

    if tag:
        lat, lng, desc = get_swm_tag(post['body'])
    else:
        raise NoSWMTag(f'Not contains tag {post["identifier"]}')

    try:
        lat = float(clean_coordinate(lat))
        lng = float(clean_coordinate(lng))

    except Exception as e:
        logging.exception('Parsing coords error')
    else:
        geo = {
            "geometry": {
                "type": "Point",
                "coordinates": [lng, lat]
            },
            "properties": {
                'name': "",
                'desc': desc
            }
        }

        PostModel.objects(identifier=post['identifier']).update(**post,
                                                                geo=geo,
                                                                upsert=True)
コード例 #2
0
    def save_to_db(self):
        # Only create a new post instance in the database if it doesn't exist already.
        try:
            PostModel.get(PostModel.link == self.link)
            return 1
        except PostModel.DoesNotExist:
            post_model = PostModel.create(title=self.title, link=self.link, timestamp=self.timestamp)
            post_model.save()

            # Save the tags
            for tag in self.tags:
                # Check that there is already a tag
                try:
                    tag_model = TagModel.get(TagModel.tag_name == tag.string)
                except TagModel.DoesNotExist:
                    tag_model = TagModel.create(tag_name=tag.string, tag_link=tag['href'])
                    tag_model.save()

                # Check that there isn't already a relationship
                try:
                    TagRelation.get(TagRelation.post_id == post_model.get_id(),
                                    TagRelation.tag_id == tag_model.get_id())
                except TagRelation.DoesNotExist:
                    tag_relation = TagRelation.create(post_id=post_model, tag_id=tag_model)
                    tag_relation.save()

            return 0
コード例 #3
0
 def mutate(self, info, title, body, username):
     user = UserModel.query.filter_by(username=username).first()
     post = PostModel(title=title, body=body)
     if user is not None:
         post.author = user
     db.session.add(post)
     db.session.commit()
     return CreatePost(post=post)
コード例 #4
0
ファイル: views.py プロジェクト: nitish1995/InstaClone
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            #fetching image and caption from the form...................................................................
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(image=image, caption=caption, user=user)
                post.save()

                #uploading image on imgur cloud.........................................................................
                client = ImgurClient(client_id, client_secret)
                path = str(BASE_DIR + '/' + post.image.url)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()

                #uploding image on cloudinary cloud.....................................................................
                #path = str(BASE_DIR + '/' + post.image.url)
                #upload = cloudinary.uploader.upload(path)
                #pdb.set_trace()
                #post.image_url = upload['url']
                #post.save()

                #doing the image analysis with the clarifai api.........................................................
                response = model.predict_by_url(post.image_url)
                response = response['outputs'][0]['data']['concepts']
                is_dirty = False
                for word in dirty:
                    for imgword in response:
                        image_word = imgword['name']
                        image_word = image_word.upper()
                        if image_word == word:
                            is_dirty = True
                            break

                if is_dirty:
                    post.dirty = True
                    post.save()

                #redirecting again to feed..............................................................................
                return redirect('/feed/')
        #handling get request...........................................................................................
        else:
            form = PostForm()
            return render(request, 'post.html', {'form': form})
    #if user is not logged in...........................................................................................
    else:
        return redirect('/login/')
コード例 #5
0
def posts():
    post = PostModel.query()
    form = PostForm()
    if form.validate_on_submit():
        post = PostModel(
            title=form.title.data,
            body=form.body.data,
            added_by=users.get_current_user()
        )
        post.put()
        return redirect(url_for('posts'))
    posts = PostModel.query().order(-PostModel.timestamp) # descending
    # qry = Greeting.query().order(Greeting.message, -Greeting.userid) #ascending
    # posts = Post.query.order_by(Post.timestamp.desc()).all()
    return render_template('posts.html', nav_title="Posts", form=form, posts=posts)
コード例 #6
0
ファイル: views.py プロジェクト: seanbradley/Canteen
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = PostModel(
                    title = form.title.data,
                    prose = form.prose.data,
                    author = users.get_current_user()
                    )
        try:
            post.put()
            flash(u'Post successfully saved.', 'success')
            return redirect(url_for('blog'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
            return redirect(url_for('blog'))
    return render_template('new_post.html', form=form)
コード例 #7
0
ファイル: views.py プロジェクト: dushant01/final
def post_view(request):
    user = check_validation(request)
    if user:
        # import pdb; pdb.set_trace()
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                path = str(BASE_DIR + '/' + post.image.url)
                client = ImgurClient(imgur_id, secret)
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                # post.save()

                # classification of images

                app = ClarifaiApp(api_key=clarif_key)
                model = app.models.get('general-v1.3')
                response = model.predict_by_url(url=post.image_url)
                value = response['outputs'][0]['data']['concepts'][0]['value']
                if value > 0.9:  # if post is about garbage
                    post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #8
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                app = ClarifaiApp(api_key='45cd6978c866e241924d5fbbbdcc59145df93f70')
                path = str(BASE_DIR +'/'+ post.image.url)

                client = ImgurClient(Client_ID, Client_secret)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                model = app.models.get("general-v1.3")
                response = model.predict_by_url(post.img_url)
                print response
                r = response['outputs'][0]['data']['concepts']
                for i in range(len(r)):
                    z = r[i]['name']
                    print z
                    temp = tags.objects.create(post=post, tag=z)
                    temp.save()
                return redirect('/feed/')
        else:
            form = PostForm()
            return render(request, 'post.html', {'form': form})
    else:
            return redirect('/login/')
コード例 #9
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "//" + post.image.url)

                client = ImgurClient(
                    '3402b40cf104724',
                    '3c498635c7ea8cee8c9831927c8ebda6b9e69e18')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')
            else:
                return HttpResponse("From data is not valid.")

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #10
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '309da390c4f405d',
                    '0b1e627021ab1fee1c9ae9ed90eaf1565ee0e0f1')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #11
0
ファイル: views.py プロジェクト: Marwari/InstaClone
def PostView(request):
    user = CheckValidation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')

                # saving post in database

                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = os.path.join(BASE_DIR, post.image.url)

                client = ImgurClient(
                    'c83158842a9256e',
                    'ba219c35073b2a80347afaf222e1ebc28dcc8e1a')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                #post.image_url = cloudinary.uploader.upload(path)
                post.save()
                return redirect('/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:

        return redirect('/login/')
コード例 #12
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "\\" + post.image.url)

                client = ImgurClient(
                    '3885ef5f1212538',
                    'b607a83fb4e5d62d3e936075755e3a40eccc7326')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #13
0
ファイル: views.py プロジェクト: AditiBhardwaj0895/mysite
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                z = post.image.url
                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '0e144dffb567600',
                    '17ed6b09b6b16a35f32bfcd307e1b21cb132b21e')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                # using calrifai
                response = model.predict_by_url(url=post.image_url)
                right = response["outputs"][0]["data"]["concepts"][0]["value"]

                # using paralleldots
                set_api_key(PKEY)
                response = sentiment(str(caption))
                sentiment_score = response["sentiment"]

                if sentiment_score >= 0.6 and right > 0.5:
                    post.save()
                    saved_message = 'Post is successfully submitted'
                    return render(request, 'error.html',
                                  {'context': saved_message})
                else:
                    error_message = 'Post cannot be submitted'
                    post.delete()
                    return render(request, 'error.html',
                                  {'context': error_message})

            return redirect('/post/')

        else:
            form = PostForm()
        return render(
            request,
            'post.html',
            {'form': form},
        )
    else:
        return redirect('/login/')
コード例 #14
0
def post_view(
    request
):  # post view funtion is used to upload file or image that you want to add to the feed and also provide funtionality to add caption also
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '319feb40023adce',
                    '2a01664decd3b8b2439bfce7caae16d47b671837')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                add_category(post)
                ctypes.windll.user32.MessageBoxW(
                    0, u"post successsfully created", u"SUCCESS", 0)

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #15
0
ファイル: views.py プロジェクト: Annu3/Instaclone1
def post_view(request):

    # checkinng if user is valid
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "\\" + post.image.url)

                client = ImgurClient(
                    'b05a87fc2d9b16a',
                    'e40bae7fc06026074022bcac6b4f370fe4963cba')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #16
0
ファイル: views.py プロジェクト: AkshiSharma12/InstaClone
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    'f7e1fe53d2e71e7',
                    '4f87a455291c79ff1caec48add2c3c4222116ef0')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                #saving to DB
                post.save()

                return redirect('/Feeds/')

        else:
            form = PostForm()
        return render(request, 'Post.html', {'form': form})
    else:
        return redirect('/Login/')
コード例 #17
0
def post_view(request):
    user = check_validation(request)

    if user:

        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)

            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                ctypes.windll.user32.MessageBoxW(0,u"Post has been created.",u"congrulation", 0)

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(ci, cs)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                return redirect('/feed/')
            else:
                ctypes.windll.user32.MessageBoxW(0, u"Invalid Post", u"Error", 0)
                form = PostForm()
            return render(request, 'post.html', {'form': form})

        else:
            return redirect('/login/')
コード例 #18
0
ファイル: views.py プロジェクト: nirajyadav04/django
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'GET':
            form = PostForm()
        elif request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                path = str(BASE_DIR + "/user_images/" + post.image.url)
                post.save()
                client = ImgurClient(
                    "48b3c07ebcf5ecb",
                    "af316e94ac2544c61623ed0fe4a80f2ce928ce33")
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                app = ClarifaiApp(api_key='dc676a84b0334de7a430b805c57332f4')

                model = app.models.get('food-items v1.0')

                response = model.product_by_url('url = post.image_url')

                print response

                return redirect('/feed/')
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #19
0
ファイル: views.py プロジェクト: vmlkshk7/instaclone
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    '7a6b6f3c625804c',
                    'e8737b3a742e79b4ef2ee548d556b05893771eb0')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #20
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '//' + post.image.url)

                client = ImgurClient(
                    '4bede6ccfad6060',
                    'c598dc22ffa6f6521d905311f2fab28b89098885')

                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                app = ClarifaiApp(api_key="c106317b6810482599634b443a8e01d8")
                model = app.models.get('general-v1.3')
                response = model.predict_by_url(url=post.image_url)
                print response

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #21
0
ファイル: views.py プロジェクト: priyanka017/final_project
 def post_view(request):
     user = check_validation(request)
     if user == None:
         return redirect('/login/')
     elif request.method == 'GET':
         post_form = PostForm()
         return render(request, 'post.html', {'post_form': post_form})
     elif request.method == "POST":
         form = PostForm(request.POST, request.FILES)
         if form.is_valid():
             image = form.cleaned_data.get('image')
             caption = form.cleaned_data.get('caption')
             post = PostModel(user=user, image=image, caption=caption)
             post.save()
             client = ImgurClient(
                 '13aab932636aa80',
                 '5d78c0178cb9258255982d328f803d536413f567')
             path = str(BASE_DIR + "\\" + post.image.url)
             post.image_url = client.upload_from_path(path,
                                                      anon=True)['link']
             post.save()
             return redirect("/feed/")
         else:
             return HttpResponse("Form data is not valid.")
     else:
         return HttpResponse("Invalid request.")
コード例 #22
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '4cf5d8d98bef4a0',
                    '292b9342adb63a7aa1eb188c1a59068c2e51a2d5')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'PostForm.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #23
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                path = str(BASE_DIR +'/'+ post.image.url)
                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                concepts = model.predict_by_url(url=post.image_url)['outputs'][0]['data']['concepts']
                for concept in concepts[:5]:
                    tag = concept['name']
                    hash = HashTag.objects.filter(name  = tag)
                    if(hash.__len__() == 0):
                        hash = HashTag(name = tag)
                        hash.save()
                    else:
                        hash = hash[0]
                    Hash2Post(id_of_hashtag = hash, id_of_post = post).save()
                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #24
0
ファイル: views.py プロジェクト: Saksham25/instaClone
def post_view(request):
    #check if user is valid
    user = check_validation(request)
    #check if user exists
    if user:
        #check if request is post
        if request.method == 'POST':

            form = PostForm(request.POST, request.FILES)
            #check if form is valid
        if form.is_valid():
            #accept image
            image = form.cleaned_data.get('image')
            #accept caption
            caption = form.cleaned_data.get('caption')
            post = PostModel(user=user, image=image, caption=caption)
            #post is  save
            post.save()
            path = str(BASE_DIR + "/" + post.image.url)
            #define client
            client = ImgurClient('8fd0103958ccceb',
                                 'aa73c860636e25e381ec473bd76fb4f2d3ca1adb')
            #define image url
            post.image_url = client.upload_from_path(path, anon=True)['link']
            #save the image url
            post.save()
            #redirect to feed page
            return redirect('/feed/')
        else:
            form = PostForm()
        #load post page
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #25
0
ファイル: views.py プロジェクト: shashwat091/Eye-dentify
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    'e2dd69870de1f73',
                    '1b49cedd71bdbd818498a1c3434ed56bfb0ed676')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #26
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                #caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                ctypes.windll.user32.MessageBoxW(
                    0, u"post successsfully created", u"SUCCESS", 0)
                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #27
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == "GET":
            form = PostForm()
        elif request.method == "POST":
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get("image")
                caption = form.cleaned_data.get("caption")
                post = PostModel(user=user, image=image, caption=caption)
                path = str(BASE_DIR + "\\user_images\\" + post.image.url)
                post.save()
                client = ImgurClient("58d5edc53832303", "d8a989c792b2e5a6cdd0fb0769a7326c4fe013a1")
                post.image_url = client.upload_from_path(path, anon=True)["link"]
                post.save()
                clarifai_data = []
                app = ClarifaiApp(api_key='a1b3910e08a4437b9fe85c5dbe967205')
                model = app.models.get("general-v1.3")
                result = model.predict_by_url(url=post.image_url)
                for x in range(0, len(result['outputs'][0]['data']['concepts'])):
                    model = result['outputs'][0]['data']['concepts'][x]['name']
                    clarifai_data.append(model)
                for z in range(0, len(clarifai_data)):
                    print clarifai_data[z]
                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, "post.html", {"form": form})

    else:
        return redirect("/login/")
コード例 #28
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' +post.image.url)

                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #29
0
ファイル: views.py プロジェクト: trisha94/Instaclone
def PostView(request):
    user = CheckValidation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')

                # saving post in database

                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = os.path.join(BASE_DIR, post.image.url)
                client = ImgurClient('32af2eae25eb458', 'a9c38afeb2cc39aadc9c408557ce3a98d87f2be0')
                post.image_url = client.upload_from_path(path, anon=True)['link']

                post.save()
                return redirect('/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:

       return redirect('/login/')
コード例 #30
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    '37e25d0cbc857c0',
                    'f7a8c883baef922700e185d6b987a607c7a56840')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #31
0
ファイル: views.py プロジェクト: bhattkush97/Instaclone
def post_view(request):
    user_valid = check_validation(request)
    if user_valid:
        if request.method == "GET":
            pform = PostForm()
        elif request.method == "POST":
            pform = PostForm(request.POST, request.FILES)
            if pform.is_valid():
                image_data = pform.cleaned_data.get('image')
                caption_data = pform.cleaned_data.get('caption')
                post_data = PostModel(user=user_valid,
                                      image=image_data,
                                      caption=caption_data)
                post_data.save()
                client = ImgurClient(
                    '42f5481cbd0457f',
                    '7bdf7000862e4cc52c8c320aa8fbb7437216c072')
                path = BASE_DIR + "/" + post_data.image.url
                image_url = client.upload_from_path(path, anon=True)['link']
                caption = post_data.caption
                type_nsfw = nsfw(image_url)
                if type_nsfw is 1:
                    post_data.image_url = image_url
                    post_data.save()
                else:
                    PostModel.objects.latest('created_on').delete()

                return redirect('/myapp/feed')
        return render(request, 'post.html', {'formdata': pform})
    else:
        return redirect('/myapp/login')
コード例 #32
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '9c9bf0c17f4ac16',
                    'cd2f3f14d28677368f0c26ee558ff6841e6e098a')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
コード例 #33
0
ファイル: views.py プロジェクト: anjalisriva95/firstapp
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                z = post.image.url
                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '4127d9468ed87d3',
                    '2ee021fa920430bbd6d998ce47d483e6f4408c63')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                # using paralleldots

                set_api_key(PKEY)
                response = sentiment(str(caption))
                sentiment_score = response['sentiment']

                if sentiment_score >= 0.6:
                    post.save()
                    saved_message = 'Post is successfully submitted'
                    return render(request, 'error.html',
                                  {'context': saved_message})
                else:
                    error_message = 'Post cannot be submitted'
                    post.delete()
                    return render(request, 'error.html',
                                  {'context': error_message})

            return redirect('/post/')

        else:
            form = PostForm()
        return render(
            request,
            'post.html',
            {'form': form},
        )
    else:
        return redirect('/login/')
コード例 #34
0
ファイル: views.py プロジェクト: seanbradley/Canteen
def blog():
    blog = PostModel.all()
    return render_template('blog.html', blog=blog)