Reordered the welcome page, added images and buying option

This commit is contained in:
theresa 2011-10-12 01:21:06 +02:00
parent 7f484ffc52
commit bed84eed06
2 changed files with 260 additions and 29 deletions

View File

@ -1,36 +1,238 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block "content" %} {% block "content" %}
{% if allMost %} <div style="width:1200px">
Am beliebtesten ist: <br /> <br /> {% if allMostDrinks or allMostSnacks %}
{% for buyable in allMost %} <table width="100%" class="showitem" style="border-width:0px">
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> ( {{ buyable.num_buys }} mal) <br /> <tr>
<td>
&nbsp;
</td>
<td>
<h1>Die beliebtesten Artikel</h1>
</td>
<td>
<h1>Deine Lieblingsartikel</h1>
</td>
<td>
<h1>Zuletzt hattest du:</h1>
</td>
</tr>
<tr>
<td style="-moz-transform: rotate(270deg); -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); -o-transform: rotate(270deg); transform: rotate(270deg)">
<h1 style="vertical-align:top">Getr&auml;nke</h1>
</td>
<td style="vertical-align:top">
{% if allMostDrinks %}
<table width=100%>
{% for buyable in allMostDrinks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b><br/>({{ buyable.num_buys }} mal)
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %} {% endfor %}
<br /> </table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
<td style="vertical-align:top">
{% if usersMostDrinks %}
<table width=100%>
{% for buyable in usersMostDrinks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
<td style="vertical-align:top">
{% if usersLastDrinks %}
<table width=100%>
{% for buyable in usersLastDrinks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b>
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
</tr>
<tr>
<th style="-moz-transform: rotate(270deg); -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); -o-transform: rotate(270deg); transform: rotate(270deg)">
<h1>Snacks</h1>
</th>
<td style="vertical-align:top">
{% if allMostSnacks %}
<table width=100%>
{% for buyable in allMostSnacks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
<td style="vertical-align:top">
{% if usersMostSnacks %}
<table width=100%>
{% for buyable in usersMostSnacks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b><br/> ({{ buyable.num_buys }} mal)
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
<td style="vertical-align:top">
{% if usersLastSnacks %}
<table width=100%>
{% for buyable in usersLastSnacks %}
<tr>
<td width="80px">
<a href="/store/show/{{ buyable.buyable__id }}"><img width=64 height=64 src="{{ MEDIA_URL }}{{ buyable.buyable__image }}"></a>
</td>
<td>
<b>{{ buyable.buyable__name }}</b>
</td>
<td width="150px">
<a class="button" href="/store/buy/{{ buyable.buyable__id }}">Kaufen
{% if buyable.buyable__deposit > 0 %}
(Ohne Pfand)</a> <a class="button" href="/store/buy/{{ buyable.buyable__id }}/with/deposit">Kaufen (Mit Pfand)</a>
{% else %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Noch keine gekauft.
{% endif %}
</td>
</tr>
</table>
{% else %} {% else %}
{{ error }} {{ error }}
Noch niemand hat was gekauft? Es hat scheinbar noch niemand etwas gekauft. <a href="/store/">Sei der Erste!</a>
{% endif %} {% endif %}
<hr> </div>
{% if usersMost %}
Am oeftesten hattest du: <br /> <br /> {% comment %}
{% for buyable in usersMost %} <div style="width:800px">
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> ( {{ buyable.num_buys }} mal) <br /> {% if usersMostSnacks or usersMostDrinks %}
{% endfor %} <h1>Deine Lieblingsartikel</h1>
<br /> <table class="showitem" width="100%" style="border-width:0px">
<tr>
<th width="50%">
Getr&auml;nke
</th>
<th width="50%">
Snacks
</th>
</tr>
<tr>
</tr>
</table>
{% else %} {% else %}
{{ error }} {{ error }}
Nix gekauft? Wie es aussieht, hast du noch nichts gekauft. <a href="/store/">Das kannst du &auml;ndern!</a>
{% endif %} {% endif %}
<hr> </div>
{% if usersLast %} <div style="width:800px">
Als letztes hattest du: <br /> <br /> {% if usersLastSnacks or usersLastDrinks %}
{% for buyable in usersLast %} <h1>Du hattest als letztes:</h1>
<a href="/store/show/{{ buyable.buyable__id }}">{{ buyable.buyable__name }}</a> <br /> <table class="showitem" width="100%" style="border-width:0px">
{% endfor %} <tr>
<br /> <th width="50%">
Getr&auml;nke
</th>
<th width="50%">
Snacks
</th>
</tr>
<tr>
</tr>
</table>
{% else %} {% else %}
{{ error }} {{ error }}
Noch nix gekauft?
{% endif %} {% endif %}
</div>
{% endcomment %}
{% endblock %} {% endblock %}

View File

@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.template import RequestContext from django.template import RequestContext
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -5,18 +6,46 @@ from django.db.models import Count
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from main.models import Plugin, PluginPermission from main.models import Plugin, PluginPermission
from buyable.models import Purchase, Buyable, BuyableType
from buyable.models import Purchase, Buyable
@login_required @login_required
def startpage(request): def startpage(request):
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da ''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
sie ueber mehrere Tabellen joined,filtered und wieder reduced. sie ueber mehrere Tabellen joined,filtered und wieder reduced.
''' '''
allMost = Purchase.objects.filter(isDeposit=False).values('buyable__name', 'buyable__id').annotate(num_buys=Count('buyable')).order_by('-num_buys') drinks = BuyableType.objects.get(name="Getränk").buyable_set.all()
usersMost = Purchase.objects.filter(isDeposit=False).values('buyable__name','buyable__id').filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys') snacks = BuyableType.objects.get(name="Snack").buyable_set.all()
usersLast = Purchase.objects.filter(isDeposit=False).values('buyable__name','buyable__id').filter(order__user=request.user.id).order_by('-order__dateTime')
return render_to_response("main/startpage.html", {'allMost' : allMost,'usersMost': usersMost, 'usersLast' : usersLast[:12]}, RequestContext(request)) allMost = Purchase.objects.filter(isDeposit=False).values('buyable__name', 'buyable__id','buyable__image','buyable__price','buyable__deposit')
allMostDrinks = allMost.filter(buyable__in=drinks).annotate(num_buys=Count('buyable')).order_by('-num_buys')
allMostSnacks = allMost.filter(buyable__in=snacks).annotate(num_buys=Count('buyable')).order_by('-num_buys')
usersMostDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
usersMostSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
# usersLastDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-order__dateTime')
# usersLastSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-order__dateTime')
usersLastDrinks = allMost.filter(buyable__in=drinks).filter(order__user=request.user.id).order_by('-order__dateTime')
usersLastSnacks = allMost.filter(buyable__in=snacks).filter(order__user=request.user.id).order_by('-order__dateTime')
#if someone knows a better way to do this, just replace this code
#purpose: filter usersLast so that it only contains unique items
usersLastDrinks_unique = []
for x in usersLastDrinks:
if not x in usersLastDrinks_unique:
usersLastDrinks_unique.append(x)
#usersLastDrinks = map(lambda x:{ "buyable__name" : x }, usersLastDrinks_unique)
usersLastDrinks = usersLastDrinks_unique
usersLastSnacks_unique = []
for x in usersLastSnacks:
if not x in usersLastSnacks_unique:
usersLastSnacks_unique.append(x)
usersLastSnacks = usersLastSnacks_unique
return render_to_response("main/startpage.html", {'allMostDrinks' : allMostDrinks[:5], 'allMostSnacks' : allMostSnacks[:5], 'usersMostDrinks': usersMostDrinks[:5], 'usersMostSnacks': usersMostSnacks[:5], 'usersLastDrinks' : usersLastDrinks[:10], 'usersLastSnacks' : usersLastSnacks[:10]}, RequestContext(request))
def register(request): def register(request):
""" The "no registration available" page... """ """ The "no registration available" page... """