-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bara led, salatatore cn backbone js - reports
- Loading branch information
1 parent
a4a1676
commit 3877397
Showing
32 changed files
with
1,679 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.