1. Nattaphoom Ch.
  2. django-ans

Commits

Nattaphoom Ch.  committed 3b9b54b

Nothing much, just follow the PEP8 and in the template also not get the
line over 80 characters too.

  • Participants
  • Parent commits 2a665cd
  • Branches master

Comments (0)

Files changed (9)

File ans_gcm/admin.py

View file
 # -*- encoding: utf-8 -*-
-from ans_gcm.models import Agenda, ANSUser, ApiKey, Device,\
-        Message, Group, Membership
+from ans_gcm.models import Agenda, ANSUser, ApiKey, Device
+from ans_gcm.models import Message, Group, Membership
 from django.contrib import admin, messages
 from django.contrib.auth.admin import UserAdmin
 #from django.contrib.auth.models import User

File ans_gcm/models.py

View file
 
 class Agenda(models.Model):
     """
-    Class description for Agenda.
+    Agenda model for ANS.
     """
 
     #agenda_id = models.AutoField('agenda id', primary_key=True) NO NEED REALLY
     datetime = models.DateTimeField('Appointment date')
     confirm = models.BooleanField(default=False)
     place = models.CharField(max_length=140, choices=LOCATIONS)
-    #alternative_place = models.CharField(max_length=140, null=True, blank=True)
 
     def __unicode__(self):
         return self.place + '_' + str(self.id)
     is_today.short_description = 'Today?'
 
     def get_confirm(self):
-        if self.confirm == True:
+        if self.confirm:
             return "confirmed"
         else:
             return "not confirmed"
     def upload_to_username(self):
         return 'profile_pictues/%s' % self.username
 
-    #asterisk_username = models.CharField(_('asterisk_username'), max_length=30, unique=True, null=True)
-    ##profile_picture = ImageWithThumbsField(upload_to='profile_picture/', sizes=((48, 48), (150, 150)), null=True)
-    #profile_picture = ImageField(upload_to=upload_to_username, null=True)
     profile_picture = ThumbnailerImageField(upload_to=avatar_path,
-            null=True, blank=True, help_text='Profile picture use for identify you on ANS.')
-    asterisk_username = models.CharField(max_length=30, null=True, blank=True, help_text='Asterisk extension, ask your VoIP admin for that. (lecturer or staff only)')
+            null=True, blank=True,
+            help_text='Profile picture use for identify the user.')
+    asterisk_username = models.CharField(max_length=30, null=True, blank=True,
+            help_text='Asterisk extension, please consult your VoIP admin.' +
+            ' (lecturer or staff only)')
     status = models.IntegerField(
             default=2,
             choices=USER_STATUSES,
-            help_text="ANSUser status can be Available, Busy, or Appear offline.")
-    location = models.CharField(max_length=140, null=True, blank=True, help_text="Latest location.")
+            help_text="Status can be Available, Busy, or Appear offline.")
+    location = models.CharField(max_length=140, null=True,
+            blank=True, help_text="Latest location.")
     '''
-    picture = models.CharField(max_length=280, help_text="Path or URL to user picture.")
     phone_number = models.CharField(max_length=20)
     '''
 
         (NORMAL, 'Normal'),
         (MISSED_CALL, 'Missed call'),
     )
-    #message_id = models.IntegerField(primary_key=True)
-    #agenda_id = models.ForeignKey(Agenda)
-    #agenda = models.OneToOneField('Agenda', related_name='message', null=True, blank=True)
     device = models.ForeignKey('Device', null=True, blank=True)
     body = models.TextField(max_length=140)
-    sender = models.ForeignKey('ANSUser', related_name='received_messages', null=False)
-    recipient = models.ForeignKey('ANSUser', related_name='sent_message', null=False)
+    sender = models.ForeignKey('ANSUser', related_name='received_messages',
+            null=False)
+    recipient = models.ForeignKey('ANSUser', related_name='sent_message',
+            null=False)
     created_on = models.DateTimeField(auto_now_add=True, editable=False)
-    sent_from = models.CharField(max_length=20, null=True, blank=True, default=None)
-    missed_call_photo = models.ImageField(upload_to=missed_call_photo_path, null=True, blank=True, default=None)
+    sent_from = models.CharField(max_length=20, null=True, blank=True,
+            default=None)
+    missed_call_photo = models.ImageField(upload_to=missed_call_photo_path,
+            null=True, blank=True, default=None)
     message_status = models.IntegerField(
             choices=MESSAGE_STATUSES,
             help_text="Normal or Missed call")
 
 
 class Device(models.Model):
-    identifier = models.CharField(max_length=200, verbose_name='Device ID') # UID of phone/device
-    registration_id = models.CharField(max_length=200, verbose_name='Registration ID') # C2DM registration ID forwarded by phone
+    identifier = models.CharField(max_length=200,
+            verbose_name='Device ID')  # UID of phone/device
+    registration_id = models.CharField(max_length=200,
+            verbose_name='Registration ID')
+    # GCM registration ID forwarded by phone
     user = models.ForeignKey('ANSUser', null=True, blank=True)
-    registered_on = models.DateTimeField(verbose_name="Registered on", auto_now_add=True)
-    modified_on = models.DateTimeField(verbose_name="Modified on", auto_now=True)
+    registered_on = models.DateTimeField(verbose_name="Registered on",
+            auto_now_add=True)
+    modified_on = models.DateTimeField(verbose_name="Modified on",
+            auto_now=True)
     account_name = models.CharField(max_length=120)
 
     class Meta:
         Check if we can send messsage to this device.
         """
         pass
-    
+
     def send_message(self, message):
         """
         Send message to the current device.
         """
-        return send_gcm_message(api_key=settings.GCM_APIKEY, registration_id=self.registration_id, data='{"message": "%s"}' % message, collapse_key="message")
+        return send_gcm_message(api_key=settings.GCM_APIKEY,
+                registration_id=self.registration_id,
+                data='{"message": "%s"}' % message, collapse_key="message")
+
 
 class ApiKey(models.Model):
     user = models.ForeignKey(User, related_name='keys', unique=True)

File ans_gcm/views.py

View file
 # -*- encoding: utf-8 -*-
 from django.http import HttpResponse, HttpResponseRedirect
-from django.contrib.auth.decorators import login_required
 from django.core.urlresolvers import reverse
 
 #from django.core.files.base import ContentFile

File api/authentication.py

View file
 from django.shortcuts import _get_queryset
 from ans_gcm.models import ApiKey
 
+
 class ApiKeyAuthentication(object):
 
     def is_authenticated(self, request):
         resp.status_code = 401
         return resp
 
+
 def get_object_or_None(klass, *args, **kwargs):
     queryset = _get_queryset(klass)
     try:

File api/forms.py

View file
 from django import forms
 
+
 class DocumentForm(forms.Form):
     docfile = forms.FileField(
         label='Select a file',

File api/handlers.py

View file
 from django.http import HttpResponse
 from django.shortcuts import get_object_or_404
 from django.conf import settings
-from django.db.models import Max, Count, Q
-from piston.utils import rc, require_mime, require_extended
+from django.db.models import Q  # Max, Count, Q
+from piston.utils import rc  # , require_mime, require_extended
 from piston.handler import BaseHandler, AnonymousBaseHandler
 
 import simplejson as json
         """
         Returns all ANS users except user `asterisk`.
         """
-        query = ANSUser.objects.filter(~Q(username='asterisk'),
+        all_users = ANSUser.objects.filter(~Q(username='asterisk'),
                 ~Q(username=request.user)).order_by('first_name', 'last_name')
         if 'filter_lecturer' in request.GET:
-            return query.filter(user_type=0)
+            return all_users.filter(user_type=0)
             return ANSUser.objects.filter(~Q(username='asterisk'),
                     ~Q(username=request.user), user_type=0).order_by(
                             'first_name', 'last_name')
         if 'filter_staff' in request.GET:
-            return query.filter(user_type=1)
+            return all_users.filter(user_type=1)
         if 'filter_student' in request.GET:
-            return query.filter(user_type=2)
-        return query
+            return all_users.filter(user_type=2)
+        return all_users
         return ANSUser.objects.filter(~Q(username='asterisk'),
                 ~Q(username=request.user)).order_by('first_name', 'last_name')
 
 
 
 class MessageHandler2(BaseHandler):
+    #FIXME or asterisk username
     """
-    ANS main messaging handler
-    Send message API (recipient name will be used rather than device ID)
+    Entrypoint for ANS message handling.
+    Send message API (recipient name  will be used rather than device ID)
     access via /api/send_message_to/recipient/
     """
 
                 recipient_user = ANSUser.objects.get(
                         asterisk_username=recipient)
             except ANSUser.DoesNotExist:
-                return HttpResponse("Extension '%s' is not registered with ANS,\
+                return HttpResponse(
+                        "Extension '%s' is not registered with ANS,\
                         visit http://appnosystem.com for more information." %
                         recipient)
         else:
                         recipient=recipient_user,
                         message_status=1)
                 if 'missed_call_photo' in request.FILES:
-                    message.missed_call_photo = request.FILES['missed_call_photo']
+                    #FIXME if not work
+                    message.missed_call_photo = request.FILES[
+                            'missed_call_photo']
                 message.body = message_body
                 message.save()
             return HttpResponse(
 
 class ConversationHandler(BaseHandler):
     """
-    /api/conversation/id_or_name
+    Access via /api/conversation/id_or_name
     """
     model = Message
     fields = ('body', 'sender', 'recipient', 'created_on', 'message_status',
 class GroupsHandler(BaseHandler):
     """
     API endpoint for groups management.
-    /api/groups/
+    Access via /api/groups/
     """
     model = Group
 

File api/models.py

View file
 from django.db import models
 
+
 class Document(models.Model):
     docfile = models.FileField(upload_to='documents/%Y/%m/%d')

File templates/index.html

View file
                     // FIXME 
                     //$('#registerEmail').val(noOfSpaces);
 
-                    if (password != "" && password == password_confirm && email != "" && fullname != "") {
+                    if (password != "" && password == password_confirm 
+                        && email != "" && fullname != "") {
                         enableSignupButton();
                     } else {
                         disableSignupButton();

File templates/main.html

View file
                 <li><a href="{% url contacts %}">Contacts</a></li>
                 <li><a href="{% url messages %}">Messages</a></li>
                 <li class="dropdown">
-                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><b class="icon-user" style="margin-right:3px;"></b>{{ request.session.current_user.get_fullname }}
+                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
+                    <b class="icon-user" style="margin-right:3px;"></b>
+                    {{ request.session.current_user.get_fullname }}
                     <b class="caret" ></b>
                 </a>
                 <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dLabel">
                     <li><a href="{% url agenda %}" >Help</a></li>
-                    <li><a tabindex="-1" href="{% url accounts.user_profile %}">Setting</a></li>
+                    <li><a tabindex="-1" href="{% url accounts.user_profile %}">
+                        Setting</a>
+                    </li>
                     <li class="divider"></li>
-                    <li><a tabindex="-1" href="{% url ans.logout %}" >Logout</a></li>
+                    <li>
+                    <a tabindex="-1" href="{% url ans.logout %}">
+                        Logout
+                    </a>
+                    </li>
                 </ul>
                 </li>
             </ul>