]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/backend/wishlist.py
3 from __future__
import division
8 from databases
import Databases
9 from misc
import Singleton
11 class Wishlist(object):
12 __metaclass__
= Singleton
16 return Databases().webapp
19 wish
= self
.db
.get("SELECT * FROM wishlist WHERE slug = %s", slug
)
22 return Wish(self
, wish
.id)
24 def get_all_by_query(self
, query
, *args
):
27 for row
in self
.db
.query(query
, *args
):
28 wish
= Wish(self
, row
.id, row
)
33 def get_all_running(self
):
34 return self
.get_all_by_query("SELECT * FROM wishlist \
35 WHERE DATE(NOW()) >= date_start AND DATE(NOW()) <= date_end AND status = 'running' \
36 ORDER BY prio ASC, date_end ASC")
38 def get_all_finished(self
, limit
=5, offset
=None):
39 query
= "SELECT * FROM wishlist WHERE DATE(NOW()) > date_end AND status IS NOT NULL \
40 ORDER BY date_end DESC"
45 query
+= " LIMIT %s,%s"
46 args
+= [limit
, offset
]
51 return self
.get_all_by_query(query
, *args
)
53 def get_hot_wishes(self
, limit
=3):
54 query
= "SELECT * FROM wishlist \
55 WHERE status = %s AND DATE(NOW()) BETWEEN date_start AND date_end AND ( \
56 ((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date_start)) <= 864000) \
57 OR ((UNIX_TIMESTAMP(date_end) - UNIX_TIMESTAMP()) <= 1209600) \
58 OR ((donated / goal) >= 0.9) \
60 ) ORDER BY prio ASC, date_end ASC LIMIT %s"
62 return self
.get_all_by_query(query
, "running", limit
)
66 def __init__(self
, wishlist
, id, data
=None):
67 self
.wishlist
= wishlist
73 return "<%s %s>" % (self
.__class
__.__name
__, self
.title
)
75 def __cmp__(self
, other
):
76 return cmp(self
.date_end
, other
.date_end
)
80 return self
.wishlist
.db
84 if self
.__data
is None:
85 self
.__data
= self
.db
.get("SELECT * FROM wishlist WHERE id = %s", self
.id)
92 return self
.data
.title
95 def title_short(self
):
96 if len(self
.title
) > 30:
97 return "%s..." % self
.title
[:30]
103 return self
.data
.slug
110 def description(self
):
111 return textile
.textile(self
.data
.description
)
115 return self
.data
.goal
119 return self
.data
.donated
122 def percentage(self
):
123 return (self
.donated
/ self
.goal
) * 100
126 def percentage_bar(self
):
127 if self
.percentage
> 100:
130 return self
.percentage
133 def progressbar_colour(self
):
137 if self
.percentage
>= 90:
144 if self
.data
.status
== "running" and not self
.running
:
147 return self
.data
.status
151 if self
.remaining_days
< 0:
157 def date_start(self
):
158 return self
.data
.date_start
162 return self
.data
.date_end
165 def running_days(self
):
166 today
= datetime
.datetime
.today()
169 running
= today
- self
.date_start
173 def remaining_days(self
):
174 today
= datetime
.datetime
.today()
177 remaining
= self
.date_end
- today
178 return remaining
.days
181 return self
.running_days
<= 10
183 def get_tweet(self
, locale
):
187 _("Checkout this crowdfunding wish from #ipfire:"),
188 "http://wishlist.ipfire.org/wish/%s" % self
.slug
,