Kaydet (Commit) d1956389 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

sectioned view

üst fbf9ac1b
# Generated by Django 2.2.1 on 2019-05-11 23:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('social', '0006_auto_20190507_1848'),
]
operations = [
migrations.AlterField(
model_name='sharable',
name='pub_date',
field=models.DateTimeField(auto_now=True),
),
]
......@@ -27,7 +27,7 @@ class Sharable(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
pub_date = models.TimeField(auto_now=True)
pub_date = models.DateTimeField(auto_now=True)
def __str__(self):
return f"{self.__class__.__name__}@{self.author}"
......
......@@ -13,3 +13,12 @@ function getCookie(c_name)
}
return "";
}
$('.js-captcha-refresh').click(function () {
$.getJSON("/captcha/refresh/", function (result) {
$('.captcha').attr('src', result['image_url']);
$('#id_captcha_0').val(result['key'])
});
});
......@@ -61,6 +61,8 @@
</main>
{% bootstrap_javascript jquery='full' %}
{% block js %}{% endblock %}
{% load static %}
<script src="{% static 'js/main.js' %}"></script>
</body>
</html>
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Post link</button>
{% endbuttons %}
</form>
......
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Post</button>
{% endbuttons %}
</form>
......
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Post snippet</button>
{% endbuttons %}
</form>
......
......@@ -16,6 +16,7 @@
<form method="post" class="form">
{% csrf_token %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary" value="Confirm">Delete Link</button>
{% endbuttons %}
</form>
......
......@@ -16,6 +16,7 @@
<form method="post" class="form">
{% csrf_token %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary" value="Confirm">Delete Post</button>
{% endbuttons %}
</form>
......
......@@ -16,6 +16,7 @@
<form method="post" class="form">
{% csrf_token %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary" value="Confirm">Delete Snippet</button>
{% endbuttons %}
</form>
......
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Update Link</button>
{% endbuttons %}
</form>
......
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Update Post</button>
{% endbuttons %}
</form>
......
......@@ -10,6 +10,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button class='js-captcha-refresh'>Refresh Captcha</button>
<button type="submit" class="btn btn-primary">Update Snippet</button>
{% endbuttons %}
</form>
......
......@@ -8,7 +8,7 @@
{% block content %}
{% load renderer %}
{% load likes_inclusion_tags %}
{% for item in feed %}
{% for item in this_day %}
<div class="container-fluid __{{ item | get_class }}">
<fieldset class="border p-2">
<legend class="w-auto"><a href="{% url 'profile' item.author %}">{{ item.author }}</a></legend>
......@@ -24,10 +24,8 @@
{% endfor %}
{% endblock %}
{% block js %}
{% load static %}
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="{% static 'js/main.js' %}"></script>
<script>
$(function () {
$('button').on('click', function () {
......
......@@ -3,6 +3,9 @@ import docker.errors
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
from datetime import datetime, timedelta
from functools import partial
from evality import Evality
from purima.views import ExtendedListView
......@@ -19,10 +22,27 @@ class Home(ExtendedListView):
template_name = "home.html"
context_object_name = "feed"
def date_sorted(self, qs, to_date, from_date):
return list(filter(lambda item: from_date < item.pub_date < to_date, qs))
def get_queryset(self):
qs = list(super().get_queryset())
qs.sort(key=(lambda item: item.id))
qs.sort(key=(lambda item: item.vote_total))
return reversed(qs)
def get_context_data(self):
context = super().get_context_data()
context['all_time'] = list(context.pop(self.context_object_name))
now = timezone.now()
date_sorted = partial(self.date_sorted, context['all_time'], now)
context['this_year'] = date_sorted(now - timedelta(365))
context['this_month'] = date_sorted(now - timedelta(30))
context['this_week'] = date_sorted(now - timedelta(7))
context['this_day'] = date_sorted(now - timedelta(1))
return context
@csrf_exempt
def run_snippet(request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment