Skip to content

Commit a403868

Browse files
author
Peter Bengtsson
authored
comments fixes (#504)
1 parent 9c0afa4 commit a403868

File tree

6 files changed

+70
-97
lines changed

6 files changed

+70
-97
lines changed

adminui/build.zip

-352 Bytes
Binary file not shown.

adminui/src/Comments.js

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import md5 from 'md5';
3-
// import { Link } from 'react-router-dom';
43
import {
54
Button,
65
Checkbox,
@@ -13,10 +12,6 @@ import {
1312
Message,
1413
TextArea,
1514
Form
16-
// Table,
17-
// Button,
18-
// Label,
19-
// Input
2015
} from 'semantic-ui-react';
2116
import { DisplayDate, ShowServerError } from './Common';
2217
import { BASE_URL } from './Config';
@@ -110,21 +105,6 @@ class Comments extends React.Component {
110105
});
111106
};
112107

113-
// deleteComment = async oid => {
114-
// const deleting = Object.assign({}, this.state.deleting);
115-
// deleting[oid] = true;
116-
// return this.setState({ deleting }, this._deleteComments);
117-
// };
118-
119-
// _deleteComments = async () => {
120-
// const data = { oids: [] };
121-
// console.log('DATA:', data);
122-
// };
123-
// _approveComments = async () => {
124-
// console.warn('NOT YET');
125-
// throw new Error('work harder');
126-
// };
127-
128108
_deleteOrApproveComments = async (type, data) => {
129109
const { accessToken } = this.props;
130110
if (!accessToken) {
@@ -225,7 +205,6 @@ class Comments extends React.Component {
225205
<form
226206
onSubmit={event => {
227207
event.preventDefault();
228-
console.log(this.refs.q.inputRef.value);
229208
this.setState(
230209
{ search: this.refs.q.inputRef.value },
231210
this.fetchComments
@@ -358,46 +337,28 @@ class Checked extends React.PureComponent {
358337

359338
class CommentsTree extends React.PureComponent {
360339
render() {
361-
const {
362-
comments,
363-
count,
364-
loading,
365-
editing,
366-
approving,
367-
deleting,
368-
approved,
369-
deleted,
370-
approveComment,
371-
deleteComment,
372-
editComment
373-
} = this.props;
340+
const { comments, count } = this.props;
341+
342+
let lastBlogitem = null;
374343
return (
375344
<Comment.Group>
376345
<Header as="h2" dividing>
377346
{count.toLocaleString()} Comments
378347
</Header>
379348

380349
{comments.map(comment => {
381-
// XXX Use {...props} instead!
350+
const differentBlogitem = lastBlogitem !== comment.blogitem.id;
351+
lastBlogitem = comment.blogitem.id;
382352
return (
383353
<CommentTree
384354
key={comment.id}
385355
comment={comment}
386-
editing={editing}
387-
approving={approving}
388-
deleting={deleting}
389-
approved={approved}
390-
deleted={deleted}
391356
root={true}
392-
loading={loading}
357+
showBlogitem={differentBlogitem}
393358
addToSearch={term => {
394359
this.props.updateFilterSearch(term);
395360
}}
396-
setChecked={this.props.setChecked}
397-
setEditing={this.props.setEditing}
398-
approveComment={approveComment}
399-
deleteComment={deleteComment}
400-
editComment={editComment}
361+
{...this.props}
401362
/>
402363
);
403364
})}
@@ -408,7 +369,8 @@ class CommentsTree extends React.PureComponent {
408369

409370
class CommentTree extends React.PureComponent {
410371
static defaultProps = {
411-
root: false
372+
root: false,
373+
showBlogitem: false
412374
};
413375
hotness = seconds => {
414376
if (seconds < 60) {
@@ -435,6 +397,7 @@ class CommentTree extends React.PureComponent {
435397
const {
436398
comment,
437399
root,
400+
showBlogitem,
438401
addToSearch,
439402
setChecked,
440403
setEditing,
@@ -450,7 +413,7 @@ class CommentTree extends React.PureComponent {
450413

451414
return (
452415
<Comment>
453-
{root && (
416+
{root && showBlogitem && (
454417
<Header as="h4" dividing>
455418
<a
456419
href={BASE_URL + comment.blogitem._absolute_url}
@@ -604,7 +567,6 @@ class EditComment extends React.PureComponent {
604567
<Form
605568
onSubmit={event => {
606569
event.preventDefault();
607-
console.log(this.state.text);
608570
this.props.editComment(this.props.comment, this.state.text);
609571
}}
610572
>

adminui/src/PostProcessings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ class Records extends React.PureComponent {
306306
<pre className="exception">{record.exception}</pre>
307307
) : null}
308308

309-
<ul style={{ margin: 0 }}>
309+
<ol style={{ margin: 0 }}>
310310
{record.notes.map((note, i) => {
311311
return <li key={i}>{note}</li>;
312312
})}
313-
</ul>
313+
</ol>
314314
</Table.Cell>
315315
</Table.Row>
316316
);

download-all-plogs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212

1313
def get_urls(base_url, exclude=set()):
14+
urls = []
1415
if base_url.endswith("/"):
1516
base_url = base_url[:-1]
1617
doc = PyQuery(base_url + "/plog/")
1718
doc.make_links_absolute(base_url=base_url)
18-
urls = []
1919
for a in doc("dd a"):
2020
href = a.attrib["href"]
2121
if href in exclude:
22-
# print("EXCLUDE", href)
2322
continue
2423
urls.append(href)
2524

@@ -36,7 +35,10 @@ def get_urls(base_url, exclude=set()):
3635
continue
3736
if href not in urls and href not in exclude:
3837
urls.append(href)
39-
url_start = base_url + "/?page="
38+
urls.append(href)
39+
urls.append(href)
40+
41+
url_start = base_url + "/p"
4042
for i in range(2, 10):
4143
url = url_start + str(i)
4244
if url in exclude:

peterbecom/api/views.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,19 @@ def _post_thumbnails(blogitem):
284284
def postprocessings(request):
285285

286286
context = {
287-
"statistics": _postprocessing_statistics(),
287+
"statistics": _postprocessing_statistics(request.GET),
288288
"records": _postprocessing_records(request.GET),
289289
}
290290

291291
return _response(context)
292292

293293

294-
def _postprocessing_statistics():
294+
def _postprocessing_statistics(request_GET):
295295

296296
context = {"groups": []}
297297

298298
base_qs = PostProcessing.objects.filter(duration__isnull=False)
299+
base_qs = _filter_postprocessing_queryset(base_qs, request_GET)
299300

300301
ongoing = (
301302
PostProcessing.ongoing()
@@ -404,10 +405,21 @@ def serialize_record(each):
404405
"_previous": None,
405406
}
406407

407-
duration_regex = re.compile(r"duration:?\s*(>|<)\s*([\d\.]+)s?")
408-
409408
qs = PostProcessing.objects.all()
409+
qs = _filter_postprocessing_queryset(qs, request_GET)
410+
411+
for each in qs.order_by("-created")[:limit]:
412+
record = serialize_record(each)
413+
if each.previous:
414+
record["_previous"] = serialize_record(each.previous)
415+
records.append(record)
416+
417+
return records
418+
419+
420+
def _filter_postprocessing_queryset(qs, request_GET):
410421
q = request_GET.get("q")
422+
duration_regex = re.compile(r"duration:?\s*(>|<)\s*([\d\.]+)s?")
411423
if q:
412424
duration = re.findall(duration_regex, q)
413425
if duration:
@@ -423,14 +435,7 @@ def serialize_record(each):
423435
qs = qs.filter(url__endswith=q[:-1])
424436
elif q:
425437
qs = qs.filter(url__contains=q)
426-
427-
for each in qs.order_by("-created")[:limit]:
428-
record = serialize_record(each)
429-
if each.previous:
430-
record["_previous"] = serialize_record(each.previous)
431-
records.append(record)
432-
433-
return records
438+
return qs
434439

435440

436441
@api_superuser_required
@@ -444,7 +449,7 @@ def searchresults(request):
444449
return _response(context)
445450

446451

447-
def _searchresults_statistics():
452+
def _searchresults_statistics(request_GET):
448453

449454
context = {"groups": []}
450455

@@ -588,7 +593,7 @@ def blogcomments(request):
588593
for each in (
589594
BlogComment.objects.filter(parent__isnull=False).values("parent_id").distinct()
590595
):
591-
all_parent_ids.add(each['parent_id'])
596+
all_parent_ids.add(each["parent_id"])
592597

593598
def _serialize_comment(item, blogitem=None):
594599
all_ids.add(item.id)
@@ -604,7 +609,7 @@ def _serialize_comment(item, blogitem=None):
604609
"email": item.email,
605610
"user_agent": item.user_agent,
606611
"ip_address": item.ip_address,
607-
"_clues": rate_blog_comment(item),
612+
"_clues": not item.approved and rate_blog_comment(item) or None,
608613
"replies": [],
609614
}
610615
if blogitem:
@@ -632,7 +637,7 @@ def _serialize_comment(item, blogitem=None):
632637
if since:
633638
base_qs = base_qs.filter(add_date__lt=since)
634639

635-
if request.GET.get('unapproved') == 'only':
640+
if request.GET.get("unapproved") == "only":
636641
base_qs = base_qs.filter(approved=False)
637642

638643
search = request.GET.get("search", "").lower().strip()

requirements.txt

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,37 @@ amqp==2.3.2 \
9797
--hash=sha256:eed41946890cd43e8dee44a316b85cf6fee5a1a34bb4a562b660a358eb529e1b
9898
anyjson==0.3.3 \
9999
--hash=sha256:37812d863c9ad3e35c0734c42e0bf0320ce8c3bed82cd20ad54cb34d158157ba
100-
lxml==4.3.0 \
101-
--hash=sha256:f726444b8e909c4f41b4fde416e1071cf28fa84634bfb4befdf400933b6463af \
102-
--hash=sha256:dd185cde2ccad7b649593b0cda72021bc8a91667417001dbaf24cd746ecb7c11 \
103-
--hash=sha256:241fb7bdf97cb1df1edfa8f0bcdfd80525d4023dac4523a241907c8b2f44e541 \
104-
--hash=sha256:99fdce94aeaa3ccbdfcb1e23b34273605c5853aa92ec23d84c84765178662c6c \
105-
--hash=sha256:1afbac344aa68c29e81ab56c1a9411c3663157b5aee5065b7fa030b398d4f7e0 \
106-
--hash=sha256:1f179dc8b2643715f020f4d119d5529b02cd794c1c8f305868b73b8674d2a03f \
107-
--hash=sha256:69d83de14dbe8fe51dccfd36f88bf0b40f5debeac763edf9f8325180190eba6e \
108-
--hash=sha256:3aa3f5288af349a0f3a96448ebf2e57e17332d99f4f30b02093b7948bd9f94cc \
109-
--hash=sha256:de2e5b0828a9d285f909b5d2e9d43f1cf6cf21fe65bc7660bdaa1780c7b58298 \
110-
--hash=sha256:a7c0cd5b8a20f3093ee4a67374ccb3b8a126743b15a4d759e2a1bf098faac2b2 \
111-
--hash=sha256:c6f24149a19f611a415a51b9bc5f17b6c2f698e0d6b41ffb3fa9f24d35d05d73 \
112-
--hash=sha256:bdd7c1658475cc1b867b36d5c4ed4bc316be8d3368abe03d348ba906a1f83b0e \
113-
--hash=sha256:d6520aa965773bbab6cb7a791d5895b00d02cf9adc93ac2bf4edb9ac1a6addc5 \
114-
--hash=sha256:1baad9d073692421ad5dbbd81430aba6c7f5fdc347f03537ae046ddf2c9b2297 \
115-
--hash=sha256:56115fc2e2a4140e8994eb9585119a1ae9223b506826089a3ba753a62bd194a6 \
116-
--hash=sha256:1d8736421a2358becd3edf20260e41a06a0bf08a560480d3a5734a6bcbacf591 \
117-
--hash=sha256:b4f67b5183bd5f9bafaeb76ad119e977ba570d2b0e61202f534ac9b5c33b4485 \
118-
--hash=sha256:1e1d9bddc5afaddf0de76246d3f2152f961697ad7439c559f179002682c45801 \
119-
--hash=sha256:51102e160b9d83c1cc435162d90b8e3c8c93b28d18d87b60c56522d332d26879 \
120-
--hash=sha256:34dfaa8c02891f9a246b17a732ca3e99c5e42802416628e740a5d1cb2f50ff49 \
121-
--hash=sha256:2f9765ee5acd3dbdcdc0d0c79309e01f7c16bc8d39b49250bf88de7b46daaf58 \
122-
--hash=sha256:abe12886554634ed95416a46701a917784cb2b4c77bfacac6916681d49bbf83d \
123-
--hash=sha256:3273db1a8055ca70257fd3691c6d2c216544e1a70b673543e15cc077d8e9c730 \
124-
--hash=sha256:0dd6589fa75d369ba06d2b5f38dae107f76ea127f212f6a7bee134f6df2d1d21 \
125-
--hash=sha256:312e1e1b1c3ce0c67e0b8105317323e12807955e8186872affb667dbd67971f6 \
126-
--hash=sha256:d1e111b3ab98613115a208c1017f266478b0ab224a67bc8eac670fa0bad7d488
100+
lxml==4.2.6 \
101+
--hash=sha256:51a9a441aefc8c93512bad5efe867d2ff086e7249ce0fc3b47c310644b352936 \
102+
--hash=sha256:29b8acd8ecdf772266dbac491f203c71664b0b07ad4309ba2c3bb131306332fc \
103+
--hash=sha256:a07447e46fffa5bb4d7a0af0a6505c8517e9bd197cfd2aec79e499b6e86cde49 \
104+
--hash=sha256:a378fd61022cf4d3b492134c3bc48204ac2ff19e0813b23e07c3dd95ae8df0bc \
105+
--hash=sha256:cc039668f91d8af8c4094cfb5a67c7ae733967fdc84c0507fe271db81480d367 \
106+
--hash=sha256:3ce5488121eb15513c4b239dadd67f9e7959511bd766aac6be0c35e80274f298 \
107+
--hash=sha256:60a5323b2bc893ca1059d283d6695a172d51cc95a70c25b3e587e1aad5459c38 \
108+
--hash=sha256:f52fe795e08858192eea167290033b5ff24f50f51781cb78d989e8d63cfe73d1 \
109+
--hash=sha256:2b05e5e06f8e8c63595472dc887d0d6e0250af754a35ba690f6a6abf2ef85691 \
110+
--hash=sha256:16cf8bac33ec17049617186d63006ba49da7c5be417042877a49f0ef6d7a195d \
111+
--hash=sha256:4e9822fad564d82035f0b6d701a890444560210f8a8648b8f15850f8fe883cd9 \
112+
--hash=sha256:30d6ec05fb607a5b7345549f642c7c7a5b747b634f6d5e935596b910f243f96f \
113+
--hash=sha256:eca305b200549906ea25648463aeb1b3b220b716415183eaa99c998a846936d9 \
114+
--hash=sha256:76d62cc048bda0ebf476689ad3eb8e65e6827e43a7521be3b163071020667b8c \
115+
--hash=sha256:aa7d096a44ae3d475c5ed763e24cf302d32462e78b61bba73ce1ad0efb8f522a \
116+
--hash=sha256:48be0c375350a5519bb9474b42a9c0e7ab709fb45f11bfcd33de876791137896 \
117+
--hash=sha256:3bf683f0237449ebc1851098f664410e3c99ba3faa8c9cc82c6acfe857df1767 \
118+
--hash=sha256:260868f69d14a64dd1de9cf92e133d2f71514d288de4906f109bdf48ca9b756a \
119+
--hash=sha256:ade8785c93a985956ba6499d5ea6d0a362e24b4a9ba07dd18920fd67cccf63ea \
120+
--hash=sha256:5bbed9efc8aeb69929140f71a30e655bf496b45b766861513960e1b11168d475 \
121+
--hash=sha256:83b58b2b5904d50de03a47e2f56d24e9da4cf7e3b0d66fb4510b18fca0faf910 \
122+
--hash=sha256:78163b578e6d1836012febaa1865e095ccc7fc826964dd69a2dbfe401618a1f7 \
123+
--hash=sha256:49bc343ca3b30cd860845433bb9f62448a54ff87b632175108bacbc5dc63e49e \
124+
--hash=sha256:18f2d8f14cc61e66e8a45f740d15b6fc683c096f733db1f8d0ee15bcac9843de \
125+
--hash=sha256:d89f1ffe98744c4b5c11f00fb843a4e72f68a6279b5e38168167f1b3c0fdd84c \
126+
--hash=sha256:4cc7531e86a43ea66601763c5914c3d3adb297f32e4284957609b90d41825fca \
127+
--hash=sha256:e750da6ac3ca624ae3303df448664012f9b6f9dfbc5d50048ea8a12ce2f8bc29 \
128+
--hash=sha256:e691b6ef6e27437860016bd6c32e481bdc2ed3af03289707a38b9ca422105f40 \
129+
--hash=sha256:a17d808b3edca4aaf6b295b5a388c844a0b7f79aca2d79eec5acc1461db739e3 \
130+
--hash=sha256:7035d9361f3ceec9ccc1dd3482094d1174580e7e1bf6870b77ea758f7cad15d2
127131
django-semanticui-form==0.0.1 \
128132
--hash=sha256:2a08d5fe4afadfe48ad8077092cfa1de2ecb14404358b6daad5fb47a4efaeb3a \
129133
--hash=sha256:d3fe71ea4586b1bfb214f7b549321879cc4104bbf7e73f1d64f81a27322ef8c9 \

0 commit comments

Comments
 (0)