Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions pgd_core/fixtures/users.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion pgd_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ class EditForm(forms.Form):
widget=forms.TextInput(attrs={'placeholder': 'first_name'}))

last_name = forms.CharField(label="Last Name",
widget=forms.TextInput(attrs={'placeholder': 'Last Name'}))
widget=forms.TextInput(attrs={'placeholder': 'Last Name'}))

class SavedSearchesForm(forms.Form):

choices=[('GlobalSearch','Global Search'),
('LocalSearch','Local Search')]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all caps? (not saying change, just wondering why) Also, why this tabbing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even i wonder now :)


query = forms.CharField(label="Search SavedSearches",
widget=forms.TextInput(attrs={'placeholder' : 'Search'}))

search_type = forms.ChoiceField(required = True, label = "Search Type",
choices=choices,
widget=forms.RadioSelect(), initial='GlobalSearch')
61 changes: 48 additions & 13 deletions pgd_core/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

{% block content %}
<head> Welcome, {{full_name}} </head>

<div style="position:fixed; top:70px; right:90px; width:200px;">
<form method="post">{% csrf_token %}

{{ form.query.label }} <br>
{{ form.query}} <br>
{% for choice in form.search_type %}
{{ choice.choice_label }}
<span class="radio"> {{ choice.tag }} </span> <br>
{% endfor %}

</form>
</div>

<table id="profile_details">
<tbody>
<p>
Expand Down Expand Up @@ -35,33 +49,54 @@
<tr>
<td> Saved searches </td>
</tr>
</p>
<p>
<td>
<table class="sSearch">
<tr>

<tr class="sSearch">
<th class="sSearch">
Time stamp
</th>
<th class="sSearch">
Tags
</th>
<th class="sSearch">
Description
</th>
<th class="sSearch">
Title
</th>

<!-- An empty tag because CSS fails to render table border if it has a text -->

<th class="sSearch">

</th>
<th class="sSearch">
Public ?
Public &#63;
</th>


</tr>

{% for attr in saved_search %}

<tr>
<tr class="sSearch">
<td class="sSearch">{{ attr.timestamp }}</td>

<td class="sSearch"> {{ attr.tags }} </td>

<td class="sSearch">{{ attr.description }}</td>

<td class="sSearch">{{ attr.title }}</td>

<td class="sSearch">{{ attr.isPublic }}</td>
<!-- An empty tag because CSS fails to render table border if it has a text -->

<td class="sSearch"> </td>

<td class="sSearch"> {{ attr.isPublic }} </td>

</tr>
{% endfor %}
</table>
Expand All @@ -70,14 +105,14 @@
</tbody>

</table>
<style>

table {
border-collapse: collapse;
}
<style>

.sSearch{
border: 1px solid black;
}
</style>
table {
border-collapse: collapse;
}
.sSearch{
border: 1px solid black;
}
</style>

{% endblock %}
79 changes: 79 additions & 0 deletions pgd_core/templates/saved-search-match.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% extends 'base.html' %}

{% block content %}

<head> Matched Searches </head>

<style>

table {
border-collapse: collapse;
}

.sSearch{
border: 1px solid black;
}
</style>

<table id="search_matches">
<tbody>
<tr>
<th class="sSearch">
Time stamp
</th>

<th class="Search">
Tags
</th>

<th class="sSearch">
Description
</th>

<th class="sSearch">
Title
</th>
<!-- An empty tag because CSS fails to render table border if it has a text -->
<th class="sSearch">

</th>

<th class="sSearch">
User
</th>

<th class="sSearch">
Public &#63;
</th>

</tr>

<p>
{% for var in matches %}

<p>
<tr>
<td class="sSearch">{{ var.timestamp }}</td>

<td class="sSearch"> {{ var.tags }} </td>

<td class="sSearch">{{ var.description }}</td>

<td class="sSearch">{{ var.title }}</td>

<!-- An empty tag because CSS fails to render table border if it has a text -->

<td class="sSearch"> </td>

<td class="sSearch"> {{ var.user.username }} </td>

<td class="sSearch">{{ var.isPublic }}</td>

</tr>
</p>

{% endfor %}
</p>
</tbody>
</table>
{% endblock %}
4 changes: 4 additions & 0 deletions pgd_core/templates/saved-search-notfound.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.html" %}
{% block content %}
<p style="text-align:center;">Sorry, the saved Search that you're trying to search does not exist.</p>
{% endblock %}
53 changes: 51 additions & 2 deletions pgd_core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class RegistrationTestCase(TestCase):


fixtures = ['pgd_core']
fixtures = ['users']
default_url = "http://testserver"
test_email = {'email' : '[email protected]'}
test_credentials = {'username':'test_user', 'password':'hello'}
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_save_search(self):
post_credentials = test_client.post(get_profile.redirect_chain[-1][0], self.test_credentials, follow=True)
self.assertEqual(post_credentials.status_code, 200)
profile_page = test_client.get(reverse('generic_profile', args=('test_user',)))
self.assertIn('<td class="sSearch">False</td>' , profile_page.content)
self.assertIn('<td class="sSearch"> False </td>' , profile_page.content)

def test_search_user(self):

Expand All @@ -110,3 +110,52 @@ def test_search_user(self):
#No matches
search_none = test_client.get(reverse('user-search'), {'q' : 'whatever'}, redirect=True)
self.assertEqual(search_none['Location'], self.default_url+reverse('notfound'))

def test_search_saved_searches(self):

test_client = Client()

#search before login, searches for some tag, checks if..
#The tag that is not related to the search is not present

#Local Search
search = test_client.post(reverse('generic_profile',
args=('test_user',)), {'query' : 'Asp, cys', 'search_type' : 'LocalSearch'},
follow=True)

#Asserts if non-Public search is not listed
self.assertNotIn('<td class="sSearch">False</td>' , search.content)
self.assertNotIn('<td class="sSearch"> Ala, Asn, Arg </td>', search.content)

#Global Search
search = test_client.post(reverse('generic_profile',
args=('test_user',)), {'query' : 'Asp, cys', 'search_type' : 'GlobalSearch'},
follow=True)

#Asserts if non-Public search is not listed
self.assertNotIn('<td class="sSearch">False</td>' , search.content)
self.assertNotIn('<td class="sSearch"> Ala, Asn, Arg </td>', search.content)
#Checks for presence of User: Test
self.assertIn('<td class="sSearch"> test </td>', search.content)

#Search After login
get_profile = test_client.get(reverse('user_profile'), follow=True)
self.assertEqual(get_profile.status_code, 200)
post_credentials = test_client.post(get_profile.redirect_chain[-1][0],
self.test_credentials, follow=True)
self.assertEqual(post_credentials.status_code, 200)
#Local Search
local_search_result = test_client.post( post_credentials.redirect_chain[-1][0],
{'query' : 'Gln, Glu', 'search_type' : 'LocalSearch'}, follow=True)

self.assertIn('<td class="sSearch">False</td>' , local_search_result.content)
self.assertIn('<td class="sSearch"> Glu, Gln, Cys </td>', local_search_result.content)

#Global Search
global_search_result = test_client.post( post_credentials.redirect_chain[-1][0],
{'query' : 'Cys, Asp', 'search_type' : 'GlobalSearch'}, follow=True)

self.assertIn('<td class="sSearch"> Cys, Asp, Asn </td>', global_search_result.content)

#Checks for presence of User: Test
self.assertIn('<td class="sSearch"> test </td>', global_search_result.content)
3 changes: 2 additions & 1 deletion pgd_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth import views as auth_views
from django.core.urlresolvers import reverse_lazy
from forms import UserRegistrationForm
from views import MyRegistrationView , profile_view, edit_profile_view, get_profile_view, search, notfound
from views import MyRegistrationView , profile_view, edit_profile_view, get_profile_view, search, notfound, savedSearches
from registration.backends.default.views import RegistrationView

urlpatterns = patterns('',
Expand Down Expand Up @@ -56,4 +56,5 @@
url(r'^profile-edit/$', edit_profile_view, name='user_profile_edit'),
url(r'^search/$', search, name='user-search'),
url(r'^notfound/$', notfound ,name='notfound' ),
url(r'^savedsearches/(?P<username>[a-zA-Z_\s@\+\.,-]+)/(?P<query>[a-zA-Z_\s@\+\.,-]+)/(?P<search_type>[a-zA-Z_\s@\+\.,-]+)$', savedSearches, name='savedsearches'),
)
Loading