Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue1021] Add asynchronous page update capability #1359

Merged
merged 5 commits into from Aug 17, 2014
Merged
Diff settings

Always

Just for now

@@ -32,16 +32,32 @@ class BugsForm(django.forms.Form):
def bug_list_from_set(bugset):
return [bug.url for bug in bugset.bugs.all()]

# What is happening here?!
# 1. Split the hunk of text on newlines
# 2. Strip all the strings of leading/trailing whitespace
# 3. Filter out all empty strings by passing the first-order function
# "bool" (to see why: bool(x) == False if and only if x == "")
@staticmethod
def url_list_from_bugtext(bugtext):
"""
Convert newline-delimited text blob into list of URLs.
What is happening here?!
1. Split the hunk of text on newlines
2. Strip all the strings of leading/trailing whitespace
3. Filter out all empty strings by passing the first-order function
"bool" (to see why: bool(x) == False if and only if x == "")
"""
return filter(bool, [x.strip() for x in bugtext.split("\n")])

@staticmethod
def is_valid_url(x):

This comment has been minimized.

Copy link
@paulproteus

paulproteus Aug 17, 2014

Contributor

You might, for the lulz, and for posterity, explain why we wrap this core Django thing in our own function.

The answer is that exceptions are a pain, and we prefer nice simple functions that return True or False.

This comment has been minimized.

Copy link
@ehashman

ehashman Aug 17, 2014

Author Member

Exceptions = "my poor call stack :'("

u = URLValidator()

try:
u(x)
except django.forms.ValidationError:
return False
return True

def __init__(self, *args, **kwargs):
# FIXME: Our home-baked "ModelForm" could be implemented with django

This comment has been minimized.

Copy link
@paulproteus

paulproteus Aug 17, 2014

Contributor

Such +1 on this comment.

# ModelForms, but the m2m text blob of URLs will be tricky to work with
self.pk = kwargs.get('pk')
self.object = None

@@ -69,16 +85,7 @@ def clean_buglist(self):
# Turn the list into a set to filter out duplicates
buglist = set(BugsForm.url_list_from_bugtext(bugtext))

u = URLValidator()

def is_valid_url(x):
try:
u(x)
except django.forms.ValidationError:
return False
return True

if not all([is_valid_url(url) for url in buglist]):
if not all([BugsForm.is_valid_url(url) for url in buglist]):

This comment has been minimized.

Copy link
@paulproteus

paulproteus Aug 17, 2014

Contributor

I suppose if we care about properly functioning in the face of inheritance, we should refer to is_valid_url() via self. or something. Shrug.

This comment has been minimized.

Copy link
@ehashman

ehashman Aug 17, 2014

Author Member

I'm probably just going to leave this as is; this code wasn't written to be extended.

raise django.forms.ValidationError(
"You have entered an invalid URL: " + url) # evil

@@ -91,7 +98,9 @@ def save(self):
s.save()

for url in self.cleaned_data.get('buglist').split("\n"):
b = mysite.bugsets.models.AnnotatedBug(url=url)
# get_or_create returns a tuple (object b, bool created?)
b = mysite.bugsets.models.AnnotatedBug.objects.get_or_create(
url=url)[0]

try:
o = mysite.search.models.Bug.all_bugs.get(
@@ -131,7 +140,6 @@ def update(self):
url=bug))

for bug in new_bugs - old_bugs:
# get_or_create returns a tuple (object b, bool created?)
b = mysite.bugsets.models.AnnotatedBug.objects.get_or_create(
url=bug)[0]
s.bugs.add(b)
@@ -25,9 +25,7 @@
{% block body_id %}bugset_create{% endblock %}

{% block pagetop %}
<h1 style='margin: 10px 0 0 10px; font-weight: bold; color: #222'>
Create a Bug Set
</h1>
<h1>Create a Bug Set</h1>

This comment has been minimized.

Copy link
@paulproteus

paulproteus Aug 17, 2014

Contributor

Yay! Go away, inline style.

{% endblock %}

{% block main %}
@@ -25,9 +25,7 @@
{% block body_id %}bugset_create{% endblock %}

{% block pagetop %}
<h1 style='margin: 10px 0 0 10px; font-weight: bold; color: #222'>
Edit a Bug Set
</h1>
<h1>Edit a Bug Set</h1>
{% endblock %}

{% block main %}
@@ -48,7 +48,7 @@
{% endblock css %}

{% block pagetop %}
<h1 style='margin: 0 0 10px 10px; font-weight: bold; color: #222'>{{ bugset.name }}</h1>
<h1>{{ bugset.name }}</h1>
{% endblock pagetop %}


@@ -76,4 +76,5 @@ <h1 style='margin: 0 0 10px 10px; font-weight: bold; color: #222'>{{ bugset.name
$(SearchResults.bindEventHandlers);
});
</script>
<script src='/static/js/bugsets/bugsets.js'></script>
{% endblock js %}
@@ -21,10 +21,10 @@
Event Bug Sets
{% endblock title %}

{% block body_id %}bugsets_main{% endblock %}

This comment has been minimized.

Copy link
@paulproteus

paulproteus Aug 17, 2014

Contributor

Yay.


{% block pagetop %}
<h1 style='margin: 10px 0 0 10px; font-weight: bold; color: #222'>
OpenHatch's Bug Set Organizer
</h1>
<h1>OpenHatch's Bug Set Organizer</h1>
{% endblock %}

{% block main %}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.