Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tests pass

  • Loading branch information...
commit 718fb0ed609167c876872cf39dbcf762233a83fb 1 parent 6966f95
@andreysobol authored
View
5 testsobol/mainapp/admin.py
@@ -0,0 +1,5 @@
+from django.contrib import admin
+
+from models import RequestPriority
+
+admin.site.register(RequestPriority)
View
2  testsobol/mainapp/fixtures/initial_data.json
@@ -1 +1 @@
-[{"pk": 1, "model": "mainapp.bio", "fields": {"bio": "i like rusty spoons", "surname": "Sobol", "name": "Andrey", "other": "pigeon post - white pigeon only", "birth": "1990-09-18", "skype": "andreysobol", "jabber": "pisecs@gmail.com", "email": "asobol@mail.ua", "img": "img/1.jpg"}},{"pk": 1, "model": "sites.site", "fields": {"domain": "", "name": ""}},{"pk": 28, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 10}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 2}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_message", "name": "Can add message", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_message", "name": "Can change message", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_message", "name": "Can delete message", "content_type": 4}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 1}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 3}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_bio", "name": "Can add bio", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_bio", "name": "Can change bio", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_bio", "name": "Can delete bio", "content_type": 8}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_request", "name": "Can add request", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_request", "name": "Can change request", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_request", "name": "Can delete request", "content_type": 9}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_site", "name": "Can add site", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_site", "name": "Can change site", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_site", "name": "Can delete site", "content_type": 7}}, {"pk": 1, "model": "auth.user", "fields": {"username": "admin", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2012-02-27 09:16:49", "groups": [], "user_permissions": [], "password": "sha1$16a12$92b9c0c1e98639d9c3cd51eadd542520b357426d", "email": "admin@admin.com", "date_joined": "2012-02-27 09:16:49"}}]
+[{"pk": 1, "model": "mainapp.bio", "fields": {"bio": "i like rusty spoons", "surname": "Sobol", "name": "Andrey", "other": "pigeon post - white pigeon only", "birth": "1990-09-18", "skype": "andreysobol", "jabber": "pisecs@gmail.com", "email": "asobol@mail.ua", "img": "img/1.jpg"}},{"pk": 1, "model": "sites.site", "fields": {"domain": "", "name": ""}},{"pk": 28, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 10}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 2}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_message", "name": "Can add message", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_message", "name": "Can change message", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_message", "name": "Can delete message", "content_type": 4}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 1}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 3}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_bio", "name": "Can add bio", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_bio", "name": "Can change bio", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_bio", "name": "Can delete bio", "content_type": 8}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_request", "name": "Can add request", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_request", "name": "Can change request", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_request", "name": "Can delete request", "content_type": 9}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_site", "name": "Can add site", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_site", "name": "Can change site", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_site", "name": "Can delete site", "content_type": 7}}, {"pk": 1, "model": "auth.user", "fields": {"username": "admin", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2012-02-27 09:16:49", "groups": [], "user_permissions": [], "password": "sha1$16a12$92b9c0c1e98639d9c3cd51eadd542520b357426d", "email": "admin@admin.com", "date_joined": "2012-02-27 09:16:49"}}, {"pk": 1, "model": "mainapp.requestpriority", "fields": {"url": "/edit/", "priority": 1}}, {"pk": 2, "model": "mainapp.requestpriority", "fields": {"url": "/http/", "priority": 2}}]
View
7 testsobol/mainapp/models.py
@@ -26,6 +26,13 @@ class Request(models.Model):
url = models.CharField(max_length=250)
ip = models.CharField(max_length=250)
+class RequestPriority(models.Model):
+ url = models.CharField(max_length=250)
+ priority = models.IntegerField()
+
+ def __unicode__(self):
+ return 'url="' + self.url + '" prioryty=' + str(self.priority)
+
class Log(models.Model):
date = models.DateTimeField(auto_now_add=True)
model = models.CharField(max_length=250)
View
38 testsobol/mainapp/views.py
@@ -6,7 +6,7 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
-from models import Bio, Request
+from models import Bio, Request, RequestPriority
from forms import BioForm
class Index(TemplateView):
@@ -46,11 +46,37 @@ def post(self, request):
return self.render(request,form,'content.html')
-class Http(ListView):
+class Http(TemplateView):
- context_object_name = 'custom_request'
template_name = 'http.html'
- paginate_by = 10
- def get_queryset(self):
- return Request.objects.order_by('-date')
+ def get_context_data(self, **kwargs):
+
+ def add(filter):
+
+ req = Request.objects.exclude(url__in = exlude_list)
+
+ if filter:
+ req = req.filter(url = p.url)
+
+ req = req.order_by('-date')
+
+ return [dict(model_to_dict(r).items() + ([('priority', p.priority)] if filter else [('priority', 0)])) for r in req]
+
+ paginate_by = 10
+
+ exlude_list = []
+ result = []
+
+ for p in RequestPriority.objects.order_by('-priority'):
+
+ result += add(True)
+
+ if len(result) > paginate_by:
+ return {'custom_request':result[0:paginate_by]}
+ else:
+ exlude_list.append(p.url)
+
+ result += add(False)
+
+ return {'custom_request':(result if len(result) < paginate_by else result[0:paginate_by])}
View
1  testsobol/templates/http.html
@@ -7,6 +7,7 @@ <h1 style="float:none;">10 Requests</h1>
<td>{{ r.date }}</td>
<td>{{ r.url }}</td>
<td>{{r.ip}}</td>
+ <td>{{r.priority}}</td>
</tr>
{% endfor %}
</table>
Please sign in to comment.
Something went wrong with that request. Please try again.