From 6fe878855d6fde00fa860046dfe36b48aebbcd9e Mon Sep 17 00:00:00 2001 From: Shweta4321 <201552042@iiitvadodara.ac.in> Date: Sat, 24 Mar 2018 14:01:32 +0530 Subject: [PATCH] votes --- Procfile | 0 cosmos | 1 - cosmos_search/settings.py | 4 +- manage.py | 0 runtime.txt | 0 search/admin.py | 5 +- search/form.py | 29 +++ search/models.py | 19 +- search/static/css/calculator.css | 203 ++++++++------------- search/templates/cosmos/calculator.html | 164 ++++++++--------- search/templates/cosmos/header.html | 125 ++++++++++++- search/templates/cosmos/index.html | 3 + search/templates/cosmos/searchresults.html | 19 +- search/templatetags/calculator.py | 2 +- search/urls.py | 6 +- search/views.py | 45 ++++- 16 files changed, 384 insertions(+), 241 deletions(-) mode change 100755 => 100644 Procfile delete mode 160000 cosmos mode change 100755 => 100644 manage.py mode change 100755 => 100644 runtime.txt create mode 100644 search/form.py diff --git a/Procfile b/Procfile old mode 100755 new mode 100644 diff --git a/cosmos b/cosmos deleted file mode 160000 index 2006c24..0000000 --- a/cosmos +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2006c2485eaf090132886f06c8df8b484f66069e diff --git a/cosmos_search/settings.py b/cosmos_search/settings.py index ae5400d..76fd893 100644 --- a/cosmos_search/settings.py +++ b/cosmos_search/settings.py @@ -45,14 +45,14 @@ # Application definition INSTALLED_APPS = [ - 'update.apps.UpdateConfig', - 'search.apps.SearchConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'update.apps.UpdateConfig', + 'search.apps.SearchConfig', ] MIDDLEWARE = [ diff --git a/manage.py b/manage.py old mode 100755 new mode 100644 diff --git a/runtime.txt b/runtime.txt old mode 100755 new mode 100644 diff --git a/search/admin.py b/search/admin.py index 6af52da..57e8db2 100644 --- a/search/admin.py +++ b/search/admin.py @@ -1,3 +1,4 @@ -from django.contrib import admin # noqa +from django.contrib import admin -# Register your models here. +from search.models import Votes +admin.site.register(Votes) diff --git a/search/form.py b/search/form.py new file mode 100644 index 0000000..6b4724e --- /dev/null +++ b/search/form.py @@ -0,0 +1,29 @@ +from django import forms +from .models import Votes + + +VOTES_CHOICES = [ + ('1', ''), + ('2', ''), + ['3', ''], + ('4', ''), + ('5', ''), +] + + +class VotesForm(forms.Form): + project_name = forms.CharField(max_length=500, required=False) + ip_address = forms.CharField(max_length=50, required=False) + vote_value = forms.ChoiceField(VOTES_CHOICES, required=True, + widget=forms.RadioSelect(attrs={"onclick": "this.form.submit();", + "class": "votes", + "data-fa-icon": ""})) + + def save(self): + u = Votes.objects.create( + project_name=self.cleaned_data['project_name'], + vote_value=self.cleaned_data['vote_value'], + ip_address=self.cleaned_data['ip_address'], + ) + u.save() + return u diff --git a/search/models.py b/search/models.py index 9d57c55..50ab576 100644 --- a/search/models.py +++ b/search/models.py @@ -1,3 +1,18 @@ -from django.db import models # noqa +from django.db import models -# Create your models here. +VOTES_CHOICES = [ + ('1', '1'), + ('2', '2'), + ('3', '3'), + ('4', '4'), + ('5', '5'), +] + + +class Votes(models.Model): + project_name = models.CharField(max_length=500, null=True, blank=True) + vote_value = models.CharField(choices=VOTES_CHOICES, default='1', max_length=20, null=True) + ip_address = models.CharField(max_length=50, null=True, blank=True) + + def __str__(self): + return self.vote_value diff --git a/search/static/css/calculator.css b/search/static/css/calculator.css index 51330a7..cdfc33a 100644 --- a/search/static/css/calculator.css +++ b/search/static/css/calculator.css @@ -1,168 +1,113 @@ #calculator { - width: 475px; + width: 40% !important; + min-width: 320px; height: auto; - margin: 100px auto; - padding: 20px 20px 9px; + margin: 0 auto; + padding: 1em; background: #949494; - /*background: linear-gradient(#9dd2ea, #8bceec);*/ - border-radius: 3px; - } -.cal-top{ - position: relative; - top: -70px; -} -/* Top portion */ -.top span.clear { - float: left; + box-shadow: .15em .15em .15em rgba(0, 0, 0, .2); + border-radius: .2em; } -/* Inset shadow on the screen to create indent */ -.top .screen { - height: 65px; - width: 426px; - float: left; - padding: 10px 10px; - background: rgb(255, 255, 255); - border-radius: 3px; - /*box-shadow: inset 0px 4px rgba(0, 0, 0, 0.2);*/ - font-size: 17px; - line-height: 40px; - color: white !important; - text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2); - text-align: right; - letter-spacing: 1px; - margin-bottom: 2%; +#calculator * { + border-radius: .2em; + border: none; + outline: none; + cursor: pointer; } -/* Clear floats */ -.keys, .top { - overflow: hidden; +#calculator input { + background: white; + text-shadow: .1em .1em .1em rgba(0, 0, 0, .1); } -/* Applying same to the keys */ -.keys span, .top span.clear { - float: left; - position: relative; - top: 0; - - cursor: pointer; - - width: 65px; - height: 36px; - +/* Inset shadow on the screen to create indent */ +.screen { + width: 100%; + padding: .5em; + margin: .5em 0; + font-size: 1em; + line-height: 1.25em; + color: white; background: white; - border-radius: 3px; - box-shadow: 0px 2px rgba(0, 0, 0, 0.2); - - margin: 0 7px 11px 0; - - line-height: 36px; - text-align: center; - - /* prevent selection of text inside keys */ - user-select: none; - - /* Smoothing out hover and active states using css3 transitions */ - transition: all 0.2s ease; + box-shadow: .15em .15em .15em rgba(0, 0, 0, .2); } -/* Remove right margins from operator keys */ -/* style different type of keys (operators/evaluate/clear) differently */ -.keys span.operator { - background: #FFF0F5; - margin-right: 0; +#resultText { + width: 100%; + height: 70%; + text-align: right; + font-size: 1.2em; + outline: none; } -.keys span.eval { - background: #a6e3e4; - /*box-shadow: 0px 4px #9da853;*/ - +#seq { + width: 100%; + height: 30%; + text-align: right; + font-size: .75em; } -.top span.clear { - background: #ff9fa8; - box-shadow: 0px 4px #ff7c87; - color: white; +.keys-row { + width: 100%; + display: flex; + flex-wrap: wrap; } -/* Some hover effects */ -.keys span:hover { - background: #d9d5ec; - color: white; +.keys-col-4 { + width: calc(100% / 12 * 4); } -.keys span.eval:hover { - background: #96cfd0; - /*box-shadow: 0px 4px #717a33;*/ - color: #ffffff; -} -input#seq:focus { - outline: none; - background: transparent; -} -.top span.clear:hover { - background: #f68991; - box-shadow: 0px 4px #d3545d; - color: white; +.keys-col-8 { + width: calc(100% / 12 * 8); } -.keys span:active { - top: 4px; +.adv-keys span { + width: calc(100% / 2 - .2em); + margin: .1em; } -.keys span.eval:active { - box-shadow: 0px 0px #717a33; - top: 4px; +.base-keys span{ + width: calc(100% / 4 - .2em); + margin: .1em; } -.top span.clear:active { - top: 4px; - box-shadow: 0px 0px #d3545d; +/* Applying same to the keys */ +.keys * { + float: left; + width: 100%; + box-shadow: .1em .1em .1em rgba(0, 0, 0, .2); + text-align: center; + + /* prevent selection of text inside keys */ + user-select: none; + + /* Smoothing out hover and active states using css3 transitions */ + transition: all .2s ease; } -.sp { - margin-right: 7px !important; +/* Remove right margins from operator keys */ +/* style different type of keys (operators/evaluate/clear) differently */ +.keys .operator input { + background: #FFF0F5 !important; } -input { - border: none; - background: none; +.keys .eval input { + background: #a6e3e4 !important; } -.clear { +.keys .clear input { background: #dcbd5e !important; - color: #fff; } -input.num { - width: 100% !important; -} -input.num:focus { - outline: none; -} -input#resultText { - outline: none; - padding-bottom: 4px; - width: 100%; - float: right; - text-align: right; - height: 15px; - position: relative; - top: -10px; +/* Some hover effects */ +.keys span:hover { + opacity: .75; + top: .1em; } -input[type="text"], textarea { - background-color: rgb(255, 255, 255); - background-image: none; - color: rgb(0, 0, 0); + +.keys *:active { + top: .1em; } -input#seq { - width: 100%; - text-align: right; - padding: 0px !important; - margin: 0px !important; - position: relative; - top: -15px; - font-size: 10px; -} \ No newline at end of file diff --git a/search/templates/cosmos/calculator.html b/search/templates/cosmos/calculator.html index 4276c2a..ca25138 100644 --- a/search/templates/cosmos/calculator.html +++ b/search/templates/cosmos/calculator.html @@ -4,121 +4,111 @@ {% endblock %} -
-
{% csrf_token %} +
+ {% csrf_token %}
{% if result_val is not None %} - -
+ {% else %} -
+ {% endif %} - - +
-
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - +
+
+
+ + + + + + + + + + +
+
+
+
+ + + + + + + + +
+ + + + + + + + + + + +
+
- diff --git a/search/templates/cosmos/header.html b/search/templates/cosmos/header.html index d08ecc8..66aae9c 100644 --- a/search/templates/cosmos/header.html +++ b/search/templates/cosmos/header.html @@ -11,7 +11,9 @@ - {% block style %} {% endblock %} + + @@ -58,14 +162,14 @@

{# align search bar and middle of vw #}
-
+
@@ -100,6 +204,11 @@ } }); }); + $("#formq").submit(function () { + if ($('input').val().replace(/[\s,\/#!$%\^&\*;:{}=\-_`~().]/g, '').length === 0) { + return false; + } + }); diff --git a/search/templates/cosmos/index.html b/search/templates/cosmos/index.html index 45530e1..ce895f0 100644 --- a/search/templates/cosmos/index.html +++ b/search/templates/cosmos/index.html @@ -17,6 +17,9 @@

a library of every algorithm and data structure code that you will ever enco To search for an algorithm, just enter your search keywords in the box above.

OpenGenus, The Open Group to help the needy

+ {% for fetch in data %} +

{{ Votes.project_name }}

+ {% endfor %} {% endblock %} diff --git a/search/templates/cosmos/searchresults.html b/search/templates/cosmos/searchresults.html index 2cfdee6..4c20b8e 100644 --- a/search/templates/cosmos/searchresults.html +++ b/search/templates/cosmos/searchresults.html @@ -32,7 +32,7 @@

- {% if result_val or not result%} + {% if result_val or not result %} {% include 'cosmos/calculator.html' %} {% endif %} @@ -45,6 +45,23 @@

{{ i }} / {% endfor %}

+
+ + {{ entry.avg_vote }} + {% if entry.avg_vote < 3 %} + + {% elif entry.avg_vote >= 4%} + + {% else %} + + {% endif %} + {% csrf_token %} + + + {{ vote_form.vote_value }} + +