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

Commit

Permalink
yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
monty5811 committed Nov 15, 2016
1 parent 6086899 commit 77311df
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 17 deletions.
4 changes: 3 additions & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from rest_framework import serializers

from apostello.models import (
Keyword, QueuedSms, Recipient, RecipientGroup, SmsInbound, SmsOutbound, UserProfile
Keyword, QueuedSms, Recipient, RecipientGroup, SmsInbound, SmsOutbound,
UserProfile
)
from elvanto.models import ElvantoGroup

Expand Down Expand Up @@ -136,6 +137,7 @@ class Meta:
fields = ('full_name',
'pk', )


class RecipientGroupSerializer(serializers.ModelSerializer):
"""Serialize apostello.models.RecipientGroup for use in edit page."""
cost = serializers.CharField(source='calculate_cost')
Expand Down
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
CanSeeKeywords, CanSeeOutgoing, IsStaff
)
from apostello.models import (
Keyword, QueuedSms, Recipient, RecipientGroup, SmsInbound, SmsOutbound, UserProfile
Keyword, QueuedSms, Recipient, RecipientGroup, SmsInbound, SmsOutbound,
UserProfile
)
from elvanto.models import ElvantoGroup

Expand Down
3 changes: 2 additions & 1 deletion apostello/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def f(*args, **kwargs):
# this hsould not be neccessary, but it works...
if not request.user.is_authenticated():
redirect_url = settings.LOGIN_URL + '?next=' + quote(
request.get_full_path())
request.get_full_path()
)
return redirect(redirect_url)
# check approval status:
if not request.user.profile.approved:
Expand Down
8 changes: 4 additions & 4 deletions apostello/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def send_message(self, content, sent_by, eta=None):
'apostello.tasks.group_send_message_task', content, self.name,
sent_by, eta
)

def archive(self):
"""Archive the group."""
self.is_archived = True
Expand Down Expand Up @@ -246,7 +245,6 @@ def save(self, *args, **kwargs):
if add_to_group_flag:
from apostello.tasks import add_new_contact_to_groups
async('apostello.tasks.add_new_contact_to_groups', self.pk)

def __str__(self):
"""Pretty representation."""
return self.full_name
Expand Down Expand Up @@ -670,15 +668,17 @@ def send(self):
else:
group = None
recipient_send_message_task(
self.recipient.pk, self.content, group, self.sent_by,
self.recipient.pk,
self.content,
group,
self.sent_by,
)
self.sent = True
except Exception as e:
self.failed = True

self.save()


def __str__(self):
"""Pretty representation."""
status = "Sent" if self.sent else "Queued"
Expand Down
2 changes: 1 addition & 1 deletion apostello/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def reply_to_name(self):
if not last_name:
raise ValidationError('No last name')
last_name = last_name.split('\n')[0]
last_name = last_name[0:40] # truncate last name
last_name = last_name[0:40] # truncate last name
self.contact.last_name = last_name
self.contact.save()
# update old messages with this person's name
Expand Down
5 changes: 4 additions & 1 deletion apostello/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ def recipient_send_message_task(recipient_pk, body, group, sent_by):
else:
raise e


def send_queued_sms():
"""Check for and send any queued messages."""
from apostello.models import QueuedSms
for sms in QueuedSms.objects.filter(sent=False, time_to_send__lte=timezone.now()):
for sms in QueuedSms.objects.filter(
sent=False, time_to_send__lte=timezone.now()
):
sms.send()


Expand Down
4 changes: 1 addition & 3 deletions apostello/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,4 @@
# debu toolbar
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls)), ]
4 changes: 3 additions & 1 deletion scripts/run_yapf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
def yapf_file(f):
"""Run yapf on file."""
print(f.path)
subprocess.call("yapf -i {} --style scripts/.style.yapf".format(f.path), shell=True)
subprocess.call(
"yapf -i {} --style scripts/.style.yapf".format(f.path), shell=True
)


def yapf_or_recr(f):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_send_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ def test_send_adhoc_soon(self, recipients, users):
'/send/adhoc/', {
'content': 'test',
'recipients': ['1'],
'scheduled_time': datetime.strftime(
datetime.now(), '%Y-%m-%d %H:%M'
)
'scheduled_time':
datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M')
}
)
tasks.send_queued_sms()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_twilio_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def test_request_data_blocked():
(u"Test", u"Test custom response"),
(u"2testing", u"your message has been received"),
(u"name John", u"Something went wrong"),
(u"name John Calvin\nthis is a really really long surname now", u"John"),
(
u"name John Calvin\nthis is a really really long surname now",
u"John"
),
(u"name John Calvin", u"John"),
(u"start", u"Thanks for signing up"),
]
Expand Down
1 change: 1 addition & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_no_name_raises(self):
(s.sms_char_limit - settings.MAX_NAME_LENGTH + len('%name%'))
)


class TestStartswithPlus:
def test_no_plus(self):
with pytest.raises(ValidationError):
Expand Down

0 comments on commit 77311df

Please sign in to comment.