position oriented text and image save in Django/mysql - mysql

I'm creating a blog application similar to scoopwhoop or mensxp.
Basically I want to create my database in such a way that I can assign image a particular position in the article.
look at this page https://www.scoopwhoop.com/Move-Over-Tony-Stark-Marvels-New-Iron-Man-Is-A-15YearOld-Black-Girl/
or http://www.mensxp.com/health/weight-loss/31372-5-rules-of-fat-loss-that-most-people-ignore.html
you see, in these pages we have some text then a relevant image then again some text and relevant image to just above text and so on.
I mean it should make sense that a particular image comes just before or after the related text.
Currently I'm doing this way
class Post(TimeStamp):
title = models.CharField(max_length=127)
text = models.TextField(verbose_name='full text description')
# some more fields
class Pictures(TimeStamp):
image = models.ImageField(upload_to=upload_to_image_path)
post = models.ForeignKey(Post, related_name="picture")
this schema will create two tables one for blog post and other of images used in posts.
now here I can randomly put images in a post... like count no of words in a post and number of images associated with this post and then use basic math to divide the text in equal length and put images after every blog in frontend. but it wont solve the problem.
I tried to use django_summernote as well but created some other problems so discarded that option.
How do you think I should design my schema so that I can solve this problem and may be i should be able to use django admin smoothly.

I would throw out the Pictures() class altogether. The images should be a part of your post body. So an example entry would be...
title = "How to program an awesome site with Django!"
text = "<p>This is some text.</p><img src='image link'><p>This is some text after the image</p>"
Basically, the images are just as much a part of the post body as the text. There is no need to create a separate database table.
So in summary, this should be your database setup...
class Post(TimeStamp):
title = models.CharField(max_length=127)
text = models.TextField(verbose_name='full text description')
# some more fields
And the post body as a whole should all be contained within the text field.

Related

Docs Inserted Image always before all text

Making a simple app script that puts images and Text into a Google Doc separated by 2 Columns, for whatever reason, no matter the way I try it the images are always above the text (Inline) in the Doc, even though they should be layered (Inline),
//Replace QR Code
let qrText = editLocalBody.findText("{{qrCode}}");
let setImagePlace = qrText.getElement().asText().replaceText("{{qrCode}}", "");
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);
From what I've seen this should insert an image wherever the text was previously located, but when it runs this it's always in the wrong spot, somehow above the text it was suppost to be in!
//Edit - To Show The Progression Of What Is Suppose To Happen And What Actually Happens:
I'm making QR Code badges for a propriety system that runs integrated tightly with Google, so I'm using appscript to get an entry from a google form containing an amount of badges (With relevent data) and autofill a Google Doc Accordingly.
// Loop Start
I fill my template with a text line that has key words in it I can select and replace later, with a keyword it can use to insert another this (This Part Works)
I first edit (findText("{{qrCode}}");) the QR Code, replacing (.replaceText) the keyword for it to nothing ("")
I then get the parent of the piece of code I ran above, which is a block of text (I think all the text in the Doc, I think this is where the issue lies, it puts it above the text because it's just one 'paragraph' or not multiple 'bodies' of text, if I could separate this I think it would work!) As a paragraph, and insert An Inline Image at Child Index (0, of the image ,qrCodeBlob)
I've debugged this script quite a bit, so I know It's that final line that inserting images fails, it sees all the text as 'one'.
// I want this (In Descending Order, each it's own full line):
Image
Text
Image
Text
//What It Gives Me (In Descending Order, each it's own full line):
Image
Image
Text
Text
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);

How to mass add text to existing content via single formula

I currently have an existing Wordpress directory website consisting of 20K city posts. I would like to update the first line of each post to include some text and an image. Each post should have its own unique image.
I am looking for a way to mass enter this into the database.
Tried using a few plugins but none are doing this effectively.
The mysql database has a column called "post_name" which has the city info for each post in "city-state" format. There is also the post title under "post_title" which could be useful for the image alt text. I would like to tap into this to point to the specific city images.
For example:
<img src="/city-state.gif">Post Title</ >
The content for the post sits in "post_content."
So ideally, I would like to create some code that adds this new content to all "post_content" cells from by using "post_name" so URLs are entered in based on that.
Example:
New static text that won't change for any posts.
<img src="/'post_name'.gif">'post_title'</ >
Is something like this possible?

Example to combine headers footers paragraphs of html and Tables

jspdf-autotable examples['header-footer'] example gets me most of what I need for my task.
I am trying to add rich text (constant font some bold and under line words) before and after a table. looking at examples.content did not make it clear.
So a complete PDF might be:
1. some paragraphs of text
2. a table on more than one page
3. some paragraphs of text
4. another table on more than one page
how do I combine all of this in one var doc = new jsPDF(); ?
Example code would be very appreciated.
The key is to use doc.autoTable.previous.finalY to get the final y position where the table ended drawing. You can than dynamically use that to draw text with doc.text(). If you want further guidence, please update your question with more info on what you have tried and what didn't work.

Selenium, Python 3, simple scraping text from Erowid LSD experiences?

Based off of an answer on here about a similar thing, I tried to scrape the text of Erowid trip experiences. The URL has a bunch of trip links. I want to click each link and then print the 'report-text-surround' element, which is the trip text.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.erowid.org/experiences/exp.cgi?S1=2&S2=-3&C1=9&Str=')
#I tried to get hrefs by xpath, knowing that each trip links starts with 'exp.php?ID'.
view_links = driver.find_elements_by_xpath("""//*[contains(text(), 'exp.php?ID')]""")
for index, view in enumerate(view_links):
html = view.get_attribute('innerHTML')
href = html.split('"')[1]
view_links[index] = href
#And then visit each href and get the data
for href in view_links:
driver.get(href)
#I know this is the element containing the trip text.
trip_text = driver.find_elements_by_class_name('report-text-surround')
for trip in trip_text:
print (trip.text.encode('utf-8'))
So you are pretty close but there are just 2 small mistakes.
trip_text = driver.find_elements_by_class_name('report-text-surround')
for trip in trip_text:
print (trip.text.encode('utf-8'))
Your driver.find_elements_by_class_name should not be plural, as there is only one on the page. It has a lot of elements, but only one class ('report-text-surround'). This means you're going to get all the text at once, you could change this but you'd have to go through the child elements or get the elements seperately.
You can change that entire section to this:
text = (driver.find_element_by_class_name('report-text-surround').text).encode('utf-8')
print(text);
That will give you all of the text in the entire article. An easy way to split this up after would be to split each part of the text by \n\n.

How to get a html element content

I want to ask if there is a way for me to get like a web element content. What i mean is:
the site
the program
You don't need to type the site address or where the element is, in need it only in this case(fully empty site with a few words only).
My question is that, wets say that you have a text on a webpage, and you want that text to appear in a textbox...That's it
you can use this :
Dim We As New System.Net.WebClient()
textbox1.text = We.DownloadString(_Url)
We.Dispose()