add working karma module to django bot site

tmp/79b4e7d7e0424f8155715d7c458859a1/head
Mike Bloy 12 years ago
parent 154eb9753f
commit 69aa4016bc

@ -8,6 +8,10 @@ class LogEntry(models.Model):
userhost = models.CharField(max_length=512)
timestamp = models.DateTimeField(db_column='karmatime')
def __unicode__(self):
return "%s given %s by %s on %s" % (self.key, self.delta,
self.who, self.timestamp)
class Meta:
db_table = 'karma_log'
ordering = ['timestamp']
@ -18,6 +22,13 @@ class User(models.Model):
pos = models.IntegerField()
neg = models.IntegerField()
def _get_total(self):
return self.pos + self.neg
total = property(_get_total)
def __unicode__(self):
return "Karma User %s (%s/%s)" % (self.who, self,pos, self.neg)
class Meta:
db_table = 'karma_users'
ordering = ['who']
@ -27,6 +38,9 @@ class Value(models.Model):
key = models.CharField(max_length=255, primary_key=True)
value = models.IntegerField()
def __unicode__(self):
return "Karma Value %s (%s)" % (self.key, self.value)
class Meta:
db_table = 'karma_values'
ordering = ['value']

@ -0,0 +1,7 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('karma.views',
(r'^$', 'index'),
(r'^givers/$', 'givers'),
(r'^stats/$', 'stats'),
)

@ -1 +1,16 @@
# Create your views here.
from django.shortcuts import render_to_response
from karma.models import Value, User
def index(request):
karma_values = len(Value.objects.all())
karma_users = len(User.objects.all())
return render_to_response('karma/index.html', {'value_count': karma_values,
'user_count': karma_users})
def stats(request):
values = Value.objects.all().order_by('-value')
return render_to_response('karma/stats.html', {'values': values})
def givers(request):
users = User.objects.all().order_by('who')
return render_to_response('karma/givers.html', {'users': users})

@ -83,10 +83,15 @@ MIDDLEWARE_CLASSES = (
ROOT_URLCONF = 'botweb.urls'
TEMPLATE_BASE_LOC = os.path.normpath(
os.path.join(os.path.abspath(os.path.dirname(__file__)),
'templates'))
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
TEMPLATE_BASE_LOC,
)
INSTALLED_APPS = (
@ -104,3 +109,4 @@ INSTALLED_APPS = (
if __name__ == "__main__":
print DB_LOCATION
print TEMPLATE_DIRS

@ -0,0 +1,7 @@
<ul>
{% for user in users %}
<li>
{{ user.who }} - {{ user.pos }} positive, {{ user.neg }} negative, {{ user.total }} total
</li>
{% endfor %}
</ul>

@ -0,0 +1,4 @@
<ul>
<li><a href="/karma/stats/">Karma Stats</a> ({{ value_count }} karma entries)</li>
<li><a href="/karma/givers/">Karma Giver Stats</a> ({{ user_count }} karma givers)</li>
</ul>

@ -0,0 +1,7 @@
<ol>
{% for value in values %}
<li>
{{ value.key }} ({{ value.value }})
</li>
{% endfor %}
</ol>

@ -6,9 +6,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns(
'',
(r'^karma/$', 'karma.views.index'),
(r'^karma/givers/$', 'karma.views.givers'),
(r'^karma/stats/$', 'karma.views.stats'),
(r'^karma/', include('karma.urls')),
# Example:
# (r'^botweb/', include('botweb.foo.urls')),

Loading…
Cancel
Save