Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
fix #262 + improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxMaSk committed Nov 27, 2017
1 parent aa1e000 commit 5e50e74
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
2 changes: 2 additions & 0 deletions django_th/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def clean(self):
cleaned_data.get('client_id') == '' or \
cleaned_data.get('client_secret') == '':
self.add_error('username', 'All the five fields are altogether mandatory')
elif cleaned_data.get('host') is None:
self.add_error('host', 'Check its protocol and its name')
elif cleaned_data.get('host').endswith('/'):
cleaned_data['host'] = cleaned_data['host'][:-1]

Expand Down
14 changes: 6 additions & 8 deletions django_th/management/commands/read.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals
from concurrent.futures import ThreadPoolExecutor
# django
from django.conf import settings
from django.core.management.base import BaseCommand
Expand All @@ -10,7 +11,6 @@
from django_th.read import Read

from logging import getLogger
from multiprocessing import Pool, TimeoutError
# create logger
logger = getLogger('django_th.trigger_happy')

Expand All @@ -34,10 +34,8 @@ def handle(self, *args, **options):
provider__name__status=True,
consumer__name__status=True,
).select_related('consumer__name', 'provider__name')
try:
with Pool(processes=settings.DJANGO_TH.get('processes')) as pool:
r = Read()
result = pool.map_async(r.reading, trigger)
result.get(timeout=60)
except TimeoutError as e:
logger.warning(e)

with ThreadPoolExecutor(max_workers=settings.DJANGO_TH.get('processes')) as executor:
r = Read()
for t in trigger:
executor.submit(r.reading, t)
20 changes: 20 additions & 0 deletions django_th/migrations/0013_auto_20171127_2122.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-27 20:22
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_th', '0012_auto_20171003_2152'),
]

operations = [
migrations.AlterField(
model_name='userservice',
name='host',
field=models.URLField(blank=True, default='', verbose_name='host'),
),
]
2 changes: 1 addition & 1 deletion django_th/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UserService(models.Model):
name = models.ForeignKey(ServicesActivated, to_field='name', related_name='+')
username = models.CharField(_('username'), max_length=255, default='', blank=True)
password = models.CharField(_('password'), max_length=128, default='', blank=True)
host = models.CharField(_('host'), max_length=255, default='', blank=True)
host = models.URLField(_('host'), default='', blank=True)
client_id = models.CharField(_('client id'), max_length=255, default='', blank=True)
client_secret = models.CharField(_('client secret'), max_length=255, default='', blank=True)
duration = models.CharField(max_length=1, choices=DURATION, default=NONE)
Expand Down
14 changes: 6 additions & 8 deletions django_th/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from django_th.models import UserService, ServicesActivated, TriggerService
from django_th.publishing_limit import PublishingLimit
from django_th.html_entities import HtmlEntities

import feedparser
# Using OAuth(12)Session
from requests_oauthlib import OAuth1Session, OAuth2Session

Expand Down Expand Up @@ -67,17 +69,13 @@ def _get_content(data, which_content):
"""
content = ''
if data.get(which_content):
if not isinstance(data.get(which_content), str):
if isinstance(data.get(which_content), feedparser.FeedParserDict):
content = data.get(which_content)['value']
elif not isinstance(data.get(which_content), str):
if 'value' in data.get(which_content)[0]:
content = data.get(which_content)[0].value
else:
if type(data.get(which_content)) is str:
content = data.get(which_content)
else:
# if not str or list or tuple
# or dict it could be feedparser.FeedParserDict
# so get the item value
content = data.get(which_content)['value']
content = data.get(which_content)
return content

@staticmethod
Expand Down
9 changes: 4 additions & 5 deletions th_evernote/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def remove_prohibited_elements(document_element):
"ilayer", "input", "isindex", "label", "layer", "legend", "link",
"marquee", "menu", "meta", "noframes", "noscript", "object",
"optgroup", "option", "param", "plaintext", "script", "select",
"style", "textarea", "xml", 'wbr']
"style", "textarea", "xml", 'wbr', 'figure', 'canvas']
for tag_name in prohibited_tag_names:
remove_prohibited_element(tag_name, document_element)

Expand All @@ -46,10 +46,9 @@ def remove_prohibited_element(tag_name, document_element):


def filter_term(att):
if att.startswith("on") or \
att.startswith("data-") or \
att in ["id", "class", "accesskey", "data", "dynsrc", "tabindex",
"frame", "rules", "width", "trbidi", "imageanchor"]:
if att.startswith("on") or att.startswith("data-") or \
att in ["id", "class", "accesskey", "data", "dynsrc", "tabindex", "srcset",
"frame", "rules", "width", "trbidi", "imageanchor", "sizes"]:
return True


Expand Down

0 comments on commit 5e50e74

Please sign in to comment.