Got a situation where currently notes logged by users are saved to a single file, with a timestamp, userid, and the note.
I would like to extract each instance of a note, and put it into a spreadsheet.
For the usernames, I have \([\w']+?, [\w']+?[ \w]{0,2}\) : (http://regexr.com/3fjf5)
The dates will be similarly trivial.
The part with which I'm struggling is grabbing the text following the timestamp and username. I tried using a negative lookahead for timestamp/username, but this will not work for the final line in the log, as it is not followed by a timestamp/username combo.
I have a solutions that involve appending a delimiter, or making two passes with regex, but I'm curious whether this can be done in a single pass.
Here's a sample of the text:
br><br>13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.<br><br>2015-03-13T10:00:13 (Stone, Fred
B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus.
Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae
consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet
et ipsum nec, cursus volutpat leo.<br><br>13/03/2015 09:58 (Stone, Fred B)
: <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus.
Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae
consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet
et ipsum nec, cursus volutpat leo<br> Quisque ipsum risus, cursus at purus in,
dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a
augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis
nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015
11:12 (Smith, Mark L) : Assigned to: Stone, Fred B L<br>Quisque
ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor
odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat.
Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus
volutpat leo<br><br>11/03/2015 11:09 (Johnson, Rod R) : <br> Quisque
ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor
odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat.
Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus
volutpat leo<br><br>19/02/2015 15:30 (Smith, Mark L) : Assigned to:
Stone, Fred B LQuisque ipsum risus, cursus at purus in, dignissim molestie
risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan,
vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo,
imperdiet et ipsum nec, cursus volutpat leo
Resulting matches (italicized) should look like:
13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.
2015-03-13T10:00:13 (Stone, Fred B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo.
etc.
Even returning each note (including the timestamp and UID) in a match would be acceptable. e.g.
13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit
amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In velit massa, porta et arcu hendrerit,
pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in,
gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante
accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper
vestibulum tortor id fringilla.
i hope this can help you (I'm not sure i did understand you):
/\d{2,4}[\/-]{1}\d{1,2}[\/-]{1}\d{2,4}[:0-9T&#;\s]*?\([\w']+?, [\w']+?[ \w]{0,2}\)/g
http://regexr.com/3fjvl
You can make the regex more specific if you want so.
Your input string maybe something like this: (first < was missed in your sample)
var mytext = "<br><br>13/03/2015 10:00 (Stone, Fred B) : Lorem ipsum dolor sit amet - Lorem ipsum dolor sit amet,. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In velit massa, porta et arcu hendrerit, pellentesque pellentesque orci. Etiam ac ante pharetra, elementum nunc in, gravida lacus. Quisque sollicitudin, tellus at imperdiet condimentum, orci ante accumsan elit, sit amet lacinia enim purus eu nisl. Phasellus ullamcorper vestibulum tortor id fringilla.<br><br>2015-03-13T10:00:13 (Stone, Fred B) : Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo.<br><br>13/03/2015 09:58 (Stone, Fred B) : <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015 11:12 (Smith, Mark L) : Assigned to: Stone, Fred B L<br>Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>11/03/2015 11:09 (Johnson, Rod R) : <br> Quisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo<br><br>19/02/2015 15:30 (Smith, Mark L) : Assigned to: Stone, Fred B LQuisque ipsum risus, cursus at purus in, dignissim molestie risus. Aliquam vitae auctor odio. Morbi condimentum sapien a augue accumsan, vitae consequat tortor feugiat. Nam quis consequat lectus. Duis nisl justo, imperdiet et ipsum nec, cursus volutpat leo" ;
//Define Regex patterns:
var dataReg = new RegExp(/(?:^|<br><br>)(\d{2}\/\d{2}\/\d{4}) (\d{2}):(\d{2})\s*?\((\w+,[\w\s]+?)\)\s*:\s*([^]+?)(?=<br><br>\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}|$)/g) ;
//Extract Notes and Data:
var myData = [] ;
while ((myData = dataReg.exec(mytext)) !== null) {
console.log(myData);
}
Description of Regex Pattern: (regex Demo)
/: regex pattern starts
(?:^|<br><br>): start search from beginning or new <br><br> that comes date and time after it.
(\d{2}\/\d{2}\/\d{4}) (\d{2}):(\d{2}): extract date,hour and minute separated.
\s*?: pass spaces
\((\w+,[\w\s]+?)\): extract username inside the parenthesis (..)
\s*:\s*: pass the :
([^]+?): capture all user notes
(?=<br><br>\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}|$): stop capturing when next note or end of string is reached
/g: Global flag means do not return after first successful result
Note:
[0] is all matched string
[1] is date , [2] is hour, [3] is minutes, [4] is username
[5] is user's note
Related
I've read 6 or 7 different threads on Stackoverflow dealing specifically with substituting a Unicode symbol for standard list bullets. Everything does what it's supposed to but I can't get it aligned. Help appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=us-ascii"
http-equiv="Content-Type">
<title>Stylin’ Lists</title>
<style type="text/css">
ul {
list-style: none;
margin-left: 0px;
padding-left: 20px;
text-indent: -20px;}
li {padding-left: 20px;}
li:before {
content: "\25AC";
padding-right: 10px;
color: DODGERBLUE;}
</style>
</head>
<body>
<h2>Stylin’ Lists</h2>
<div style=
"font-family: Helvetica, Sans-Serif; font-size: 16px; line-height: 18px; font-weight: Bold;">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Quisque sed felis.</li>
<li>Etiam augue pede, molestie eget, rhoncus at,
convallis ut, eros. Aliquam pharetra. Nulla in tellus
eget odio sagittis blandit. Aliquam sit amet felis.
Mauris semper, velit semper laoreet dictum, quam diam
dictum urna, nec placerat elit nisl in quam. Etiam
augue pede, molestie eget, rhoncus at, convallis ut,
eros. Aliquam pharetra. Nulla in tellus eget odio
sagittis blandit. Maecenas at nisl. Nullam lorem mi,
eleifend a, fringilla vel, semper at, ligula.</li>
<li>Molestie eget, rhoncus at, convallis ut, eros.
Semper laoreet dictum, quam diam dictum urna, nec
placerat elit nisl in quam. Aliquam pharetra. Nulla in
tellus eget odio sagittis blandit. Maecenas at nisl.
Nullam lorem mi, eleifend a, fringilla vel, semper at,
ligula. Consectetuer adipiscing elit. Quisque sed
felis.</li>
<li>Placerat elit nisl in quam. Nullam lorem mi,
eleifend a, fringilla vel, semper at, ligula. Etiam
augue pede, molestie eget, rhoncus at, convallis ut,
eros. Aliquam pharetra. Nulla in tellus eget odio
sagittis blandit. Maecenas at nisl.</li>
</ul>
</div>
</body>
</html>
So I'm trying to get my routing to work so that I have permalinks in my url for sharing. I.E. "/getting-started".
I can't seem to figure out how the model/serialize works, so how does ember-data know how to find my object with a string? I already did an attempt at the queryFixtures and it returns the right model but it isn't set
Here is my code:
Router:
App.Router.map (match) ->
#resource 'topics', {path: "/support"}, ->
#route 'topic', {path: '/:permalink'}
# Support Routes
App.TopicsRoute = Ember.Route.extend
model: ->
this.store.find('topic')
App.TopicsTopicRoute = Ember.Route.extend
# serialize: (model, params) ->
# return { topic_id: model.get(params.topic_id) }
model: (param) ->
#get('store').findQuery App.Topic, {permalink: param.permalink}
setupController: (controller, model) ->
controller.set("content", model)
actions:
error: (error) ->
console.log error
App.ApplicationAdapter = DS.FixtureAdapter.extend
queryFixtures: (fixtures, query, type) ->
fixtures.filter (item) ->
for property, value of query
if item[property] == value
return item
else
false
And my fixtures:
App.Topic = DS.Model.extend
name: DS.attr('string')
permalink: DS.attr('string')
position: DS.attr('number')
# Fiture data
App.Topic.FIXTURES = [
{
id: 1
name: "Getting Started"
permalink: "getting-started"
position: 1
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 2", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 3", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
},
{
id: 2
name: "Frequently Asked Questions"
permalink: "frequently-asked-questions"
position: 2
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." },
{ name: "test 2", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
},
{
id: 3
name: "Tips & Tricks"
permalink: "tips-tricks"
position: 3
articles: [
{ name: "test 1", content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et." }
]
}
]
For this answer I will assume you're using the version 1.0.0 of Ember and the Beta version 1.0.0 of Ember Data.
For the router you described, you should setup the following Route objects:
App.TopicsIndexRoute = Ember.Route.extend
and
App.TopicIndexRoute = Ember.Route.extend
otherwise Ember will have issues passing the correct model to the routes.
Now in the TopicIndexRoute (TopicsTopicRoute in your code) you use the model hook, which is called ONLY when entering the URL or reloading the page and NOT when coming to the route through the {{link-to}} helper (http://emberjs.com/api/classes/Ember.Route.html#method_model).
When you're going to the TopicIndexRoute from a {{link-to}} helper, the "ember magic" match the dynamic segment (http://emberjs.com/guides/routing/specifying-a-routes-model/#toc_dynamic-models) to the corresponding model only if it's the model's ID. I don't know how to solve this yet. This might help: Using a non-ID dynamic parameter with the ember router v2
I don't know if the fixtures you're using are working but when setting relationships you should use (at least that's how it's shown in the guides: http://emberjs.com/guides/models/connecting-to-an-http-server/#toc_json-conventions) the model ID instead of declaring the instance. It would look like this:
App.Article.FIXTURES = [
{
id: 1,
name: "test 1",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
},
{
id: 2,
name: "test 2",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
},
{
id: 3,
name: "test 3",
content: "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et."
}
]
App.Topic.FIXTURES = [
{
id: 1
name: "Getting Started"
permalink: "getting-started"
position: 1
articles: [1,2,3]
}
]
I hope this helps you.
I want to make my bodyline which is basically my container, be at a height of:
bodyline{
height:500px;
min-height:500px;
height:auto !important;
}
but when I set it to this, it does not actually work. my footer is placed in the middle and it messes up the footer divs that are inside that. Does anyone have any suggestions. maybe I made the code wrong or something im not sure really.
example
http://jsfiddle.net/zrUSr/
please help someone.
Live demo
Hey now define your div id overflow hidden in your css as like this
#bodyline {
background-color: #FFFFFF;
border-radius: 10px 10px 0 0;
margin: 0 auto;
min-height: 300px;
overflow: hidden; // add this line
padding-top: 320px; //add this line
position: relative;
width: 1000px;
}
#midSection {
color: #000000;
float: left;
height: auto !important;
margin: 0 auto;
min-height: 100px;
padding-bottom: 50px;
padding-left: 30px;
padding-right: 10px;
position: relative;
top: 320px; // remove this line
width: 600px;
}
Live demo
Ok so I did what some of the people told me what to do above. then found that the
bodyline{
min-height:500px;
height:500px;
height:auto !important;
}
height:auto was not added, so I added it so check out the jsfiddle http://jsfiddle.net/jAXp2/
and find this code
/*Add this as many times as you want to*/
<div id="midSection">
<h2>Updates</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ultricies condimentum velit vel scelerisque. Nam id libero sit amet libero ultrices interdum dignissim nec lorem. Maecenas placerat massa sit amet augue interdum rutrum. Fusce vel lectus arcu. Quisque quis elit et lorem suscipit faucibus a ut odio. Proin ut ante consectetur dui mattis pulvinar non quis neque. Proin ultrices lectus vel orci lacinia a iaculis nibh hendrerit. Mauris sagittis aliquam odio vitae pulvinar. Suspendisse id dolor nibh, sed consectetur sem. Phasellus lacinia laoreet sem, ac ultrices libero lobortis quis. Morbi accumsan tempus neque, sed varius lectus molestie imperdiet. Vivamus porttitor facilisis nunc, sed feugiat quam adipiscing ac. Quisque dolor tellus, porta in ultrices sit amet, luctus sed nunc. Quisque sodales scelerisque orci sed ullamcorper. Nunc nisl arcu, dignissim sed tempor eget, blandit a massa. Praesent ut metus enim, in dictum felis. Integer sagittis ipsum eu mauris lacinia rhoncus. Mauris turpis ligula, dapibus nec rhoncus bibendum, tristique eu nunc. Duis dapibus blandit justo et auctor. Nunc non elit vel diam luctus ullamcorper.
Nulla elementum tristique ultricies. Etiam sit amet felis leo, non imperdiet sapien. Suspendisse venenatis, erat ac mollis sagittis, nulla arcu semper felis, a tempus dolor nibh in est. Nullam. </p>
</div>
/*Add this as many times as you want to*/
add it as many times after it to see it in action.
you will see that it expands the bodyline as long as it needs to be.
I have a model ..
class News(models.Model):
date = models.DateField(auto_now=True)
title = models.CharField(max_length=100)
slug = models.CharField(max_length=100)
text = models.TextField()
def __unicode__(self):
return self.title
def get_absolute_url(self):
return ('view_item', None, {'slug': self.slug})
class Meta:
verbose_name_plural = "News"
and the template file is as follows
{% extends 'base.html' %}
{% block title %}Welcome to my blog{% endblock %}
{% block content %}
{% if news %}
{% for singleitem in news %}
<h2>{{ singleitem.title }}</h2>
<p>{{ singleitem.date }}</p>
{{ singleitem.text }}
{% endfor %}
{% endif %}
{% endblock %}
the input in the textbox is as follows
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra aliquet arcu. Praesent non elit dolor, vel bibendum lectus. Proin mauris nisl, faucibus sit amet commodo et, interdum a ligula. Ut sapien leo, egestas non molestie vitae, aliquam eget purus. Sed at libero sapien. Ut id dolor elit. Ut placerat massa massa. Quisque posuere pellentesque lorem ac tristique. Nam lacinia tincidunt felis ac adipiscing. Suspendisse elit risus, cursus vel dignissim et, lacinia sit amet neque. Morbi tincidunt sem id augue fermentum adipiscing.
</p>
<p>
Quisque commodo lorem eu tortor auctor sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent condimentum ante id erat dapibus ac rhoncus dui hendrerit. Curabitur at diam vitae ipsum sagittis vestibulum ac et metus. Donec in molestie justo. In eget fringilla lacus. Vestibulum gravida quam quis dui aliquam ut gravida justo rhoncus. Nam euismod mattis purus pulvinar scelerisque. Nam tortor augue, cursus vel ultrices ut, pharetra id leo. Etiam tristique, augue aliquam faucibus dictum, libero justo egestas ante, ut volutpat metus nunc vitae arcu. Aliquam erat volutpat. Sed laoreet posuere sodales.
</p>
<p>
Donec urna urna, facilisis cursus auctor quis, eleifend nec diam. Proin eros dolor, aliquet ut euismod a, viverra sit amet turpis. Suspendisse at dolor quam. Phasellus suscipit rhoncus nisl at feugiat. Aenean in adipiscing purus. Etiam non ligula ligula. Nulla sit amet urna libero, et suscipit nulla. Suspendisse congue purus a eros accumsan eu volutpat ante euismod. Proin ut massa turpis, in gravida diam. Maecenas metus dui, cursus sed commodo eget, accumsan nec arcu.
</p>
which is displayed as follows, django doesn't recognize html tags
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam pharetra aliquet arcu. Praesent non elit dolor, vel bibendum
lectus. Proin mauris nisl, faucibus sit amet commodo et, interdum a
ligula. Ut sapien leo, egestas non molestie vitae, aliquam eget purus.
Sed at libero sapien. Ut id dolor elit. Ut placerat massa massa.
Quisque posuere pellentesque lorem ac tristique. Nam lacinia tincidunt
felis ac adipiscing. Suspendisse elit risus, cursus vel dignissim et,
lacinia sit amet neque. Morbi tincidunt sem id augue fermentum
adipiscing. </p>
<p> Quisque commodo lorem eu tortor auctor sodales. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Praesent condimentum ante
id erat dapibus ac rhoncus dui hendrerit. Curabitur at diam vitae
ipsum sagittis vestibulum ac et metus. Donec in molestie justo. In
eget fringilla lacus. Vestibulum gravida quam quis dui aliquam ut
gravida justo rhoncus. Nam euismod mattis purus pulvinar scelerisque.
Nam tortor augue, cursus vel ultrices ut, pharetra id leo. Etiam
tristique, augue aliquam faucibus dictum, libero justo egestas ante,
ut volutpat metus nunc vitae arcu. Aliquam erat volutpat. Sed laoreet
posuere sodales. </p>
<p> Donec urna urna, facilisis cursus auctor quis, eleifend nec
diam. Proin eros dolor, aliquet ut euismod a, viverra sit amet turpis.
Suspendisse at dolor quam. Phasellus suscipit rhoncus nisl at feugiat.
Aenean in adipiscing purus. Etiam non ligula ligula. Nulla sit amet
urna libero, et suscipit nulla. Suspendisse congue purus a eros
accumsan eu volutpat ante euismod. Proin ut massa turpis, in gravida
diam. Maecenas metus dui, cursus sed commodo eget, accumsan nec arcu.
</p>
how to format text for output using django output field?
//yousuf
Use the "safe" filter. Like {{ singleitem.text|safe }}. I think thats what you are looking for.
Using django templates I would like to split a block of text on the first fullstop.
I would then like to give the first sentence a class of highlight and then the rest of the text a class of normal. how would i do this? e.g. (I know this doesn't work)
text = Aliquam pretium vestibulum nibh, vel molestie velit varius nec Curabitur non neque sed elit tincidunt. Dignissim eget vel du molestie magna auctor faucibus. Curabitur id nisl nec ipsum molestie egestas in at dolor. Morbi et risus ac quam sagittis accumsan. Morbi vitae elementum metus. Vestibulum malesuada ornare elit, et interdum nisi imperdiet sed.
<p class="highlight">{{text|split:"."[0]}}</p>
<p class="normal">{{text|split:"."[1]}}</p>
which would give
<p class="highlight">Aliquam pretium vestibulum nibh, vel molestie velit varius nec Curabitur non neque sed elit tincidunt.</p>
<p class="normal">Dignissim eget vel du molestie magna auctor faucibus. Curabitur id nisl nec ipsum molestie egestas in at dolor. Morbi et risus ac quam sagittis accumsan. Morbi vitae elementum metus. Vestibulum malesuada ornare elit, et interdum nisi imperdiet sed.</p>
I am using Django 1.1
Define a custom filter, say mysplit.
#register.filter
def mysplit(value, sep = "."):
parts = value.split(sep)
return (parts[0], sep.join(parts[1:]))
Then use the filter in your template:
{% with text|mysplit:"." as parts %}
<p class="highlight">{{ parts.0 }}</p>
<p class="normal">{{ parts.1 }}</p>
{% endwith %}
This was tested with Django 1.2.1.