From: Radek Czajka
Date: Tue, 26 Mar 2013 16:10:46 +0000 (+0100)
Subject: Added: Fundusz, dummy payments.
X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/575e58df64c98b53edca9fb6a29b284dbc375609?ds=sidebyside;hp=-c
Added: Fundusz, dummy payments.
---
575e58df64c98b53edca9fb6a29b284dbc375609
diff --git a/.gitignore b/.gitignore
index c3e3e48b6..6714e2301 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ dev.sqlite
*~
*.orig
*.log
+.sass-cache
# Compress output
/static
diff --git a/apps/funding/admin.py b/apps/funding/admin.py
index 132c86304..7fbb4c488 100755
--- a/apps/funding/admin.py
+++ b/apps/funding/admin.py
@@ -1,6 +1,7 @@
from django.contrib import admin
-from .models import Offer, Perk, Funding
+from .models import Offer, Perk, Funding, Spent
+admin.site.register(Spent)
admin.site.register(Offer)
admin.site.register(Perk)
admin.site.register(Funding)
diff --git a/apps/funding/forms.py b/apps/funding/forms.py
new file mode 100755
index 000000000..eb75fb6f1
--- /dev/null
+++ b/apps/funding/forms.py
@@ -0,0 +1,30 @@
+from django import forms
+from .models import Offer
+
+
+class DummyForm(forms.Form):
+ amount = forms.DecimalField()
+ name = forms.CharField()
+ email = forms.EmailField()
+
+ def __init__(self, offer, *args, **kwargs):
+ self.offer = offer
+ super(DummyForm, self).__init__(*args, **kwargs)
+
+ def clean_amount(self):
+ if self.cleaned_data['amount'] <= 0:
+ raise forms.ValidationError("A!")
+ return self.cleaned_data['amount']
+
+ def clean(self):
+ if self.offer != Offer.current():
+ raise forms.ValidationError("B!")
+ return self.cleaned_data
+
+ def save(self):
+ print self.cleaned_data
+ return self.offer.fund(
+ name=self.cleaned_data['name'],
+ email=self.cleaned_data['email'],
+ amount=self.cleaned_data['amount'])
+
diff --git a/apps/funding/migrations/0002_auto__add_spent__del_field_offer_book_url__add_field_offer_book.py b/apps/funding/migrations/0002_auto__add_spent__del_field_offer_book_url__add_field_offer_book.py
new file mode 100644
index 000000000..1c03bdbf3
--- /dev/null
+++ b/apps/funding/migrations/0002_auto__add_spent__del_field_offer_book_url__add_field_offer_book.py
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Spent'
+ db.create_table('funding_spent', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('amount', self.gf('django.db.models.fields.DecimalField')(max_digits=10, decimal_places=2)),
+ ('timestamp', self.gf('django.db.models.fields.DateField')()),
+ ('book', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Book'])),
+ ))
+ db.send_create_signal('funding', ['Spent'])
+
+ # Deleting field 'Offer.book_url'
+ db.delete_column('funding_offer', 'book_url')
+
+ # Adding field 'Offer.book'
+ db.add_column('funding_offer', 'book',
+ self.gf('django.db.models.fields.related.ForeignKey')(to=orm['catalogue.Book'], null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting model 'Spent'
+ db.delete_table('funding_spent')
+
+ # Adding field 'Offer.book_url'
+ db.add_column('funding_offer', 'book_url',
+ self.gf('django.db.models.fields.URLField')(default='', max_length=200, blank=True),
+ keep_default=False)
+
+ # Deleting field 'Offer.book'
+ db.delete_column('funding_offer', 'book_id')
+
+
+ models = {
+ 'catalogue.book': {
+ 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'},
+ '_related_info': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}),
+ 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'common_slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}),
+ 'cover': ('catalogue.fields.EbookField', [], {'max_length': '100', 'null': 'True', 'format_name': "'cover'", 'blank': 'True'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'epub_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'epub'", 'blank': 'True'}),
+ 'extra_info': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}),
+ 'fb2_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'fb2'", 'blank': 'True'}),
+ 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+ 'html_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'html'", 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}),
+ 'mobi_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'mobi'", 'blank': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}),
+ 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'pdf_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'pdf'", 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'}),
+ 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+ 'txt_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'txt'", 'blank': 'True'}),
+ 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
+ 'xml_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'xml'", 'blank': 'True'})
+ },
+ 'funding.funding': {
+ 'Meta': {'ordering': "['-payed_at']", 'object_name': 'Funding'},
+ 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '127'}),
+ 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['funding.Offer']"}),
+ 'payed_at': ('django.db.models.fields.DateTimeField', [], {}),
+ 'perks': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['funding.Perk']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'funding.offer': {
+ 'Meta': {'ordering': "['-end']", 'object_name': 'Offer'},
+ 'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']", 'null': 'True', 'blank': 'True'}),
+ 'end': ('django.db.models.fields.DateField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'redakcja_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+ 'start': ('django.db.models.fields.DateField', [], {}),
+ 'target': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'funding.perk': {
+ 'Meta': {'ordering': "['-price']", 'object_name': 'Perk'},
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['funding.Offer']", 'null': 'True', 'blank': 'True'}),
+ 'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'})
+ },
+ 'funding.spent': {
+ 'Meta': {'object_name': 'Spent'},
+ 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}),
+ 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'timestamp': ('django.db.models.fields.DateField', [], {})
+ }
+ }
+
+ complete_apps = ['funding']
\ No newline at end of file
diff --git a/apps/funding/models.py b/apps/funding/models.py
index a088a07b7..8c1ee9a72 100644
--- a/apps/funding/models.py
+++ b/apps/funding/models.py
@@ -6,13 +6,14 @@ from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _, ugettext as __
from datetime import date, datetime
+from catalogue.models import Book
class Offer(models.Model):
author = models.CharField(_('author'), max_length=255)
title = models.CharField(_('title'), max_length=255)
slug = models.SlugField(_('slug'))
- book_url = models.URLField(_('book URL'), blank=True)
+ book = models.ForeignKey(Book, null=True, blank=True)
redakcja_url = models.URLField(_('redakcja URL'), blank=True)
target = models.DecimalField(_('target'), decimal_places=2, max_digits=10)
start = models.DateField(_('start'))
@@ -100,3 +101,12 @@ class Funding(models.Model):
def __unicode__(self):
return "%s payed %s for %s" % (self.name, self.amount, self.offer)
+
+
+class Spent(models.Model):
+ amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10)
+ timestamp = models.DateField(_('when'))
+ book = models.ForeignKey(Book)
+
+ def __unicode__(self):
+ return u"Spent: %s" % unicode(self.book)
diff --git a/apps/funding/static/funding/.sass-cache/9a22640771b7b9d791c15ce50176b00a63a474df/funding.scssc b/apps/funding/static/funding/.sass-cache/9a22640771b7b9d791c15ce50176b00a63a474df/funding.scssc
deleted file mode 100644
index eea6a038f..000000000
Binary files a/apps/funding/static/funding/.sass-cache/9a22640771b7b9d791c15ce50176b00a63a474df/funding.scssc and /dev/null differ
diff --git a/apps/funding/static/funding/funding.css b/apps/funding/static/funding/funding.css
index 7ed53e140..0b3f56344 100755
--- a/apps/funding/static/funding/funding.css
+++ b/apps/funding/static/funding/funding.css
@@ -1,17 +1,27 @@
-.standalone-funding {
- border: 1px solid black; }
-
.funding {
font-size: 1.5em;
padding: 0;
padding: .5em 1em;
background-image: url(/static/img/green-pixel.png);
- background-repeat: repeat-y; }
+ background-repeat: repeat-y;
+ background-color: rgba(13, 126, 133, 0.2); }
.funding a {
+ display: block;
color: black; }
-.funding-plus {
- background: rgba(13, 126, 133, 0.2); }
-
-.funding-minus {
- background: rgba(255, 0, 0, 0.2); }
+.wlfund {
+ width: 100%;
+ border-collapse: collapse; }
+ .wlfund td {
+ padding: 0 0 1em 0;
+ text-align: center; }
+ .wlfund td:last-child {
+ text-align: right; }
+ .wlfund td div {
+ padding: 1em;
+ box-shadow: 0 2px 0 #DDDDDD; }
+ .wlfund .funding-plus td div {
+ background: rgba(13, 126, 133, 0.2); }
+ .wlfund .funding-minus td div {
+ bbackground: rgba(255, 0, 0, 0.2);
+ background: white; }
diff --git a/apps/funding/static/funding/funding.scss b/apps/funding/static/funding/funding.scss
index 6268f48ac..8de3ef8a7 100755
--- a/apps/funding/static/funding/funding.scss
+++ b/apps/funding/static/funding/funding.scss
@@ -1,23 +1,41 @@
-.standalone-funding {
- border: 1px solid black;
-}
-
.funding {
font-size: 1.5em;
padding: 0;
padding: .5em 1em;
background-image: url(/static/img/green-pixel.png);
background-repeat: repeat-y;
+ background-color: fade-out(#0D7E85, .8);
a {
+ display: block;
color: black;
}
}
-.funding-plus {
- background: fade-out(#0D7E85, .8);
-}
+.wlfund {
+ width: 100%;
+ border-collapse: collapse;
+
+ td {
+ padding: 0 0 1em 0;
+ text-align: center;
+ }
+
+ td:last-child {
+ text-align: right;
+ }
+
+ td div {
+ padding: 1em;
+ box-shadow: 0 2px 0 #DDDDDD;
+ }
-.funding-minus {
- background: fade-out(red, .8);
+ .funding-plus td div {
+ background: fade-out(#0D7E85, .8);
+ }
+
+ .funding-minus td div {
+ bbackground: fade-out(red, .8);
+ background: white;
+ }
}
diff --git a/apps/funding/templates/funding/offer_detail.html b/apps/funding/templates/funding/offer_detail.html
index c7aa6392a..3f49b8828 100755
--- a/apps/funding/templates/funding/offer_detail.html
+++ b/apps/funding/templates/funding/offer_detail.html
@@ -1,5 +1,7 @@
{% extends "base.html" %}
+{% load url from future %}
{% load funding_tags %}
+{% load uni_form_tags %}
{% block titleextra %}{{ object }}{% endblock %}
@@ -8,24 +10,28 @@
{{ object }}
-{% funding object add_class="standalone-funding" %}
+{% funding object %}
{% if object.state == 'running' %}
WpÅaÄ:
-
{% endif %}
+
+
Zobacz wszystkie zbiórki.
diff --git a/apps/funding/templates/funding/offer_list.html b/apps/funding/templates/funding/offer_list.html
index 926d1d3e2..6114e377c 100755
--- a/apps/funding/templates/funding/offer_list.html
+++ b/apps/funding/templates/funding/offer_list.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load url from future %}
{% load funding_tags %}
{% block titleextra %}Funding{% endblock %}
@@ -19,7 +20,7 @@
{% endif %}
{% elif funding.state == "lose" %}
Cel finansowania nie zostaÅ osiÄ
gniÄty. Zgromadzone Årodki
- zostaÅy przekazane na Fundusz Wolnych Lektur.
+ zostaÅy przekazane na Fundusz Wolnych Lektur.
{% endif %}
{% endfor %}
diff --git a/apps/funding/templates/funding/thanks.html b/apps/funding/templates/funding/thanks.html
new file mode 100755
index 000000000..baf227558
--- /dev/null
+++ b/apps/funding/templates/funding/thanks.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+{% load funding_tags %}
+
+{% block titleextra %}DziÄkujemy!{% endblock %}
+
+{% block body %}
+
+DziÄkujemy!
+
+
+
+{% endblock %}
diff --git a/apps/funding/templates/funding/wlfund.html b/apps/funding/templates/funding/wlfund.html
index eb33257a5..5f3ca65b5 100755
--- a/apps/funding/templates/funding/wlfund.html
+++ b/apps/funding/templates/funding/wlfund.html
@@ -5,16 +5,35 @@
{% block body %}
Fundusz Wolnych Lektur
-Suma: {{ amount }}
-
-
- {% for entry in log %}
- -
- {{ entry.end }} +{{ entry.sum }}
- CzÄÅciowa zbiórka na: {{ entry }}
-
+
+
+
+
+ Bilans: | {{ amount }} | |
+
+
+
+ {% for tag, entry in log %}
+ {% if tag == 'spent' %}
+
+ {{ entry.timestamp }} |
+ {{ entry.total }} |
+ -{{ entry.amount }} zÅ |
+ |
+
+ {% else %}
+
+ {{ entry.end }} |
+ {{ entry.total }} |
+ +{{ entry.sum }} zÅ |
+ |
+
+ {% endif %}
{% endfor %}
-
+
{% endblock %}
diff --git a/apps/funding/urls.py b/apps/funding/urls.py
index c712b5e08..dc79f3130 100755
--- a/apps/funding/urls.py
+++ b/apps/funding/urls.py
@@ -3,14 +3,15 @@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf.urls import patterns, url
-from django.views.generic import DetailView, ListView, FormView
+from django.views.generic import ListView, FormView, TemplateView
from .models import Offer
-from .views import WLFundView
+from .views import WLFundView, OfferDetailView, ThanksView
urlpatterns = patterns('',
url(r'^$', ListView.as_view(queryset=Offer.public()), name='funding'),
- url(r'lektura/^(?P[^/]+)/$', DetailView.as_view(queryset=Offer.public()), name='funding_offer'),
- url(r'fundusz/$', WLFundView.as_view(), name='funding_wlfund'),
+ url(r'^lektura/(?P[^/]+)/$', OfferDetailView.as_view(), name='funding_offer'),
+ url(r'^dziekujemy/$', ThanksView.as_view(), name='funding_thanks'),
+ url(r'^fundusz/$', WLFundView.as_view(), name='funding_wlfund'),
)
diff --git a/apps/funding/views.py b/apps/funding/views.py
index dab996a75..05bf3983c 100644
--- a/apps/funding/views.py
+++ b/apps/funding/views.py
@@ -1,21 +1,24 @@
# Create your views here.
-from django.views.generic import TemplateView
-from .models import Offer
+from django.core.urlresolvers import reverse
+from django.shortcuts import redirect, get_object_or_404
+from django.views.generic import TemplateView, FormView, DetailView
+from .forms import DummyForm
+from .models import Offer, Spent
def mix(*streams):
substreams = []
- for stream, read_date in streams:
+ for stream, read_date, tag in streams:
iterstream = iter(stream)
try:
item = next(iterstream)
except StopIteration:
pass
else:
- substreams.append([read_date(item), item, iterstream, read_date])
+ substreams.append([read_date(item), item, iterstream, read_date, tag])
while substreams:
i, substream = max(enumerate(substreams), key=lambda x: x[0])
- yield substream[1]
+ yield substream[4], substream[1]
try:
item = next(substream[2])
except StopIteration:
@@ -28,12 +31,56 @@ class WLFundView(TemplateView):
template_name = "funding/wlfund.html"
def get_context_data(self):
+ def add_total(total, it):
+ for tag, e in it:
+ e.total = total
+ if tag == 'spent':
+ total += e.amount
+ else:
+ total -= e.sum()
+ yield tag, e
+
ctx = super(WLFundView, self).get_context_data()
offers = [o for o in Offer.objects.all() if o.state() == 'lose' and o.sum()]
- amount = sum(o.sum() for o in offers)
+ amount = sum(o.sum() for o in offers) - sum(o.amount for o in Spent.objects.all())
print offers
- #offers = (o for o in Offer.objects.all() if o.state() == 'lose' and o.sum())
ctx['amount'] = amount
- ctx['log'] = mix((offers, lambda x: x.end))
+ ctx['log'] = add_total(amount, mix(
+ (offers, lambda x: x.end, 'offer'),
+ (Spent.objects.all(), lambda x: x.timestamp, 'spent'),
+ ))
+ return ctx
+
+
+class OfferDetailView(FormView):
+ form_class = DummyForm
+ template_name = "funding/offer_detail.html"
+
+ def dispatch(self, request, slug):
+ self.object = get_object_or_404(Offer.public(), slug=slug)
+ return super(OfferDetailView, self).dispatch(request, slug)
+
+ def get_form(self, form_class):
+ if self.request.method == 'POST':
+ return form_class(self.object, self.request.POST)
+ else:
+ return form_class(self.object)
+
+ def get_context_data(self, *args, **kwargs):
+ ctx = super(OfferDetailView, self).get_context_data(*args, **kwargs)
+ ctx['object'] = self.object
+ return ctx
+
+ def form_valid(self, form):
+ form.save()
+ return redirect(reverse("funding_thanks"))
+
+
+class ThanksView(TemplateView):
+ template_name = "funding/thanks.html"
+
+ def get_context_data(self, *args, **kwargs):
+ ctx = super(ThanksView, self).get_context_data(*args, **kwargs)
+ ctx['object'] = Offer.current()
return ctx