Skip to content

Commit

Permalink
bara led, salatatore cn backbone js - reports
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzobracciale committed Nov 5, 2013
1 parent a4a1676 commit 3877397
Show file tree
Hide file tree
Showing 32 changed files with 1,679 additions and 273 deletions.
3 changes: 3 additions & 0 deletions fusolab2_0/apps/bar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
from bar.models import *

class BarBalanceAdmin(admin.ModelAdmin):
ordering = ('-date',)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'cashier':
kwargs['queryset'] = UserProfile.objects.filter(user__groups__name='turnisti')
return super(BarBalanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

class SmallBalanceAdmin(admin.ModelAdmin):
ordering = ('-date',)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'cashier':
kwargs['queryset'] = UserProfile.objects.filter(user__groups__name='turnisti')
return super(SmallBalanceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)


# Re-register UserAdmin
admin.site.register(PurchasedProduct)
admin.site.register(Product)
Expand Down
1 change: 1 addition & 0 deletions fusolab2_0/apps/bar/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PAYMENT_SUBTYPES = (
('ar','artisti'),
('ba','barman'),
('fo','fonico'),
('pu','pulizie'),
('va','varie')
)
Expand Down
20 changes: 11 additions & 9 deletions fusolab2_0/apps/bar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bar.managers import *
from base.models import UserProfile
from django.conf import settings
import simplejson


DATE_FORMAT = "%d-%m-%Y"
Expand All @@ -30,6 +31,7 @@ class PurchasedProduct(models.Model):
name = models.CharField("nome", max_length=30)
cost = models.DecimalField("prezzo", max_digits=5, decimal_places=2)
receipt = models.ForeignKey('Receipt')

def __unicode__(self):
return self.name + " " + self.receipt.date.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT))
class Meta:
Expand All @@ -47,7 +49,7 @@ def __unicode__(self):
return "#%d - %.2f EUR %s" % (self.id, self.total, self.date.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT)))

class Meta:
ordering = ['-date']
ordering = ['date']
verbose_name = "Scontrino"
verbose_name_plural = "Scontrini"

Expand Down Expand Up @@ -166,7 +168,7 @@ def get_bar_summary(closing):
if transaction.subtype:
notes.append(" "+get_deposit_display(transaction.subtype))
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")
else:
notes.append("\n")
elif transaction.operation in [PAYMENT]:
Expand All @@ -180,12 +182,12 @@ def get_bar_summary(closing):
elif transaction.operation in [WITHDRAW]:
d['expected_balance']-=transaction.amount
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")
else:
notes.append("\n")
else:
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")


d['notes'] = notes
Expand Down Expand Up @@ -245,7 +247,7 @@ def get_small_summary(checkpoint):
if transaction.subtype:
notes.append(" "+get_deposit_display(transaction.subtype))
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")
else:
notes.append("\n")
elif transaction.operation in [PAYMENT]:
Expand All @@ -259,18 +261,18 @@ def get_small_summary(checkpoint):
elif transaction.operation in [WITHDRAW]:
d['expected_balance']-=transaction.amount
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")
else:
notes.append("\n")
else:
if transaction.note:
notes.append(" "+transaction.note.replace("\r\n"," "+"\n"))
notes.append(" "+transaction.note.replace("\r\n"," ")+"\n")

d['notes'] = notes
d['check'] = d['checkpoint'] - d['expected_checkpoint']
if (d['check'] < - settings.MONEY_DELTA):
d['warning'] = True
return d


import signals
Empty file.
4 changes: 4 additions & 0 deletions fusolab2_0/apps/baraled/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from baraled.models import *

admin.site.register(LedString)
38 changes: 38 additions & 0 deletions fusolab2_0/apps/baraled/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.db import models
from django.db.models.signals import post_save
from base.models import *
import socket
from fusolab2_0 import settings


class LedString(models.Model):
"""
Frasi scritte sulla Bara di Led
"""
user = models.ForeignKey('base.UserProfile', blank=True, null=True)
created_on = models.DateTimeField(auto_now_add = True)
sentence = models.CharField(max_length=800)
coded_sentence = models.CharField(max_length=900) #con tag <ID00> bla bla

def __unicode__(self):
if self.user:
return u"%s - %s - %s" % (self.user, self.created_on.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT)), self.sentence )
else:
return u"Sconosciuto - %s - %s" % (self.created_on.strftime("%s %s" % (DATE_FORMAT, TIME_FORMAT)), self.sentence )


#Signals

def send_ledbar_cmd(sender, instance, **kwargs):
'''
After being saved, each LedString sends an UPD message to the Arduino that controls the led bar
'''
BARALED_IP = settings.IP_OPENER
BARALED_PORT = settings.PORT_OPENER
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(instance.coded_sentence, (BARALED_IP, BARALED_PORT))
sock.close()


post_save.connect(send_ledbar_cmd, sender=LedString, dispatch_uid="send_ledbar_cmd")

Empty file.
14 changes: 14 additions & 0 deletions fusolab2_0/apps/baraled/templatetags/baraledtags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from django.contrib.auth.models import User
from baraled.models import *
import datetime

register = template.Library()

@register.assignment_tag
def last_ledstrings(num):
"""
Ultime frasi lette scritte sulla barra
"""
sentences = LedString.objects.filter(user__isnull=False).order_by('-created_on')[:num]
return sentences
7 changes: 7 additions & 0 deletions fusolab2_0/apps/baraled/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('',
url(r'sentences_list/$', 'baraled.views.sentences_list', name="baraled_sentences_list"),
)


45 changes: 45 additions & 0 deletions fusolab2_0/apps/baraled/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect, HttpResponseServerError
from django.utils import simplejson
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
from django.core.exceptions import ValidationError
from django.core.servers.basehttp import FileWrapper
from django.contrib.auth.decorators import login_required
from django.utils import timesince
import os, mimetypes, urllib
from baraled.models import LedString
from sorl.thumbnail import get_thumbnail
from base.utils import *

@csrf_exempt
@login_required
def sentences_list(request):
import json
if request.method == "POST" and request.is_ajax():
#create new element
json_data = simplejson.loads(request.raw_post_data)
try:
post_txt = json_data['text']
except KeyError:
HttpResponseServerError("Malformed data!")

if post_txt:
# protocollo:
# http://www.areasx.com/files/articoli/8195/Protocollo%20MEDIA-LINK%201.1.pdf
if is_polite(post_txt):
LedString(sentence=post_txt, coded_sentence="<ID00><FD>" + post_txt, user=request.user.get_profile()).save()
else:
raise ValidationError('Ti perdono, ma non lo posso scrivere!')

return HttpResponse(str(request.raw_post_data))
else:
qs = LedString.objects.all().order_by("-created_on")[:5]
mlist = []
for q in reversed(qs):
im_url = ""
if q.user.photo:
im_url = get_thumbnail(q.user.photo , '50x50', crop='center', quality=99).url
else:
im_url = settings.STATIC_URL + "images/fusolab_unnamed_avatar.jpg"
mlist.append({"id": q.id, "sender": q.user.user.username, "text": q.sentence, "image": im_url , "date": timesince.timesince(q.created_on)})
return HttpResponse(json.dumps(mlist), content_type="application/json")
1 change: 0 additions & 1 deletion fusolab2_0/apps/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
url(r'^index.html$', 'base.views.home'),
url(r'^tuttoapposto/(?P<next_page>\S+)$', 'base.views.tuttoapposto', name='tuttoapposto'),
url(r'^regolamento/$', TemplateView.as_view(template_name='regolamento.html'), name='base_regolamento'),

url(r'^disponibilita/$', TemplateView.as_view(template_name='base/disponibilita.html'), name='base_disponibilita'),
url(r'^turni/$', TemplateView.as_view(template_name='base/turni.html'), name='base_turni'),
)
10 changes: 10 additions & 0 deletions fusolab2_0/apps/base/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import re

def is_polite(txt):
"""
Search for profanities
"""
r = re.compile(r'porco\s?d\w+|madonna|coop|cazzo|culo|stronz|puttana|troia|coglion', re.IGNORECASE)
return not r.search(txt)


4 changes: 4 additions & 0 deletions fusolab2_0/apps/cancello/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from django.contrib import admin
from cancello.models import *

# class GatePermissionAdmin(admin.ModelAdmin):
# search_fields = ['user__username',]
#
# admin.site.register(GatePermission,GatePermissionAdmin)
admin.site.register(GatePermission)
2 changes: 2 additions & 0 deletions fusolab2_0/apps/cancello/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def open_gate(request):
MESSAGE = settings.OPEN_GATE_PW
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.close()
return HttpResponse("Cancello Aperto")
else:
return HttpResponseForbidden("Non hai i permessi per aprire il cancello del fusolab. Fatti abilitare dal presidente!")
Expand All @@ -29,6 +30,7 @@ def open_door(request):
MESSAGE = settings.OPEN_DOOR_PW
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.close()
return HttpResponse("Porta Aperta")
else:
return HttpResponseForbidden("Non hai i permessi per aprire il cancello del fusolab. Fatti abilitare dal presidente!")
Expand Down
1 change: 1 addition & 0 deletions fusolab2_0/apps/ingresso/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ingresso.models import *

class EntranceBalanceAdmin(admin.ModelAdmin):
ordering = ('-date',)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'cashier':
kwargs['queryset'] = UserProfile.objects.filter(user__groups__name='turnisti')
Expand Down
Loading

0 comments on commit 3877397

Please sign in to comment.