1. Edu Herraiz
  2. Django-template

Commits

Edu Herraiz  committed a1078f9

Demo tasks and backend

  • Participants
  • Parent commits a474a27
  • Branches master

Comments (0)

Files changed (13)

File frontend/admin.py

View file
+from django.contrib import admin
+#from models import CustomUser
+
+class CustomUserAdmin(admin.ModelAdmin):
+    
+    list_display = ('username','email')
+    search_fields = ('username', 'email')
+    list_display_links = ('username','email')
+
+#admin.site.register(CustomUser, CustomUserAdmin)  

File frontend/migrations/0001_initial.py

View file
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'CustomUser'
+        db.create_table(u'frontend_customuser', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['social_auth.UserSocialAuth'], unique=True)),
+            ('configured', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('username', self.gf('django.db.models.fields.CharField')(max_length=128)),
+            ('photo', self.gf('django.db.models.fields.URLField')(max_length=200, null=True, blank=True)),
+            ('language', self.gf('django.db.models.fields.CharField')(default='en', max_length=128, blank=True)),
+            ('last_login', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
+            ('email', self.gf('django.db.models.fields.EmailField')(max_length=75, blank=True)),
+            ('counter', self.gf('django.db.models.fields.IntegerField')(default=0)),
+        ))
+        db.send_create_signal(u'frontend', ['CustomUser'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'CustomUser'
+        db.delete_table(u'frontend_customuser')
+
+
+    models = {
+        u'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        u'auth.permission': {
+            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        u'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        u'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        u'frontend.customuser': {
+            'Meta': {'object_name': 'CustomUser'},
+            'configured': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'counter': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '128', 'blank': 'True'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'photo': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['social_auth.UserSocialAuth']", 'unique': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+        },
+        'social_auth.usersocialauth': {
+            'Meta': {'unique_together': "(('provider', 'uid'),)", 'object_name': 'UserSocialAuth'},
+            'extra_data': ('social_auth.fields.JSONField', [], {'default': "'{}'"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'provider': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'uid': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'social_auth'", 'to': u"orm['auth.User']"})
+        }
+    }
+
+    complete_apps = ['frontend']

File frontend/migrations/0002_auto__add_field_customuser_counter2.py

View file
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'CustomUser.counter2'
+        db.add_column(u'frontend_customuser', 'counter2',
+                      self.gf('django.db.models.fields.IntegerField')(default=0),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'CustomUser.counter2'
+        db.delete_column(u'frontend_customuser', 'counter2')
+
+
+    models = {
+        u'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        u'auth.permission': {
+            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        u'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        u'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        u'frontend.customuser': {
+            'Meta': {'object_name': 'CustomUser'},
+            'configured': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'counter': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'counter2': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'default': "'en'", 'max_length': '128', 'blank': 'True'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'photo': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['social_auth.UserSocialAuth']", 'unique': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+        },
+        'social_auth.usersocialauth': {
+            'Meta': {'unique_together': "(('provider', 'uid'),)", 'object_name': 'UserSocialAuth'},
+            'extra_data': ('social_auth.fields.JSONField', [], {'default': "'{}'"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'provider': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'uid': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'social_auth'", 'to': u"orm['auth.User']"})
+        }
+    }
+
+    complete_apps = ['frontend']

File frontend/migrations/__init__.py

Empty file added.

File frontend/models.py

View file
     email = models.EmailField(blank=True)
      
     objects = CustomUserManager()  
+    
+    counter = models.IntegerField(default=0)
+    counter2 = models.IntegerField(default=0)
+    
+    def inc_counter(self):
+        self.counter = self.counter + 1
+        self.counter2 = self.counter2 + 2 
+        self.save()
         
     def update_login_date(self):
         ##Checkin login in last day to update last_login, used in tasks
         if not self.last_login:
             self.last_login = datetime.utcnow()
             self.save()
-        #elif self.last_login < (datetime.utcnow() - timedelta(seconds=settings.TIME_LOGIN)):
-            #self.last_login = datetime.utcnow()
-            #self.save()
             
     def update_twitter_status(self, text):
         if text:
         #user = api.get_user(self.username)
         #self.photo = user.profile_image_url
         #self.save()
-            
-       
-    def send_email(self, subject,  html_content):
-        send_email_mandrill(subject, html_content,settings.EMAIL_PROJECT ,settings.NAME_PROJECT,self.email, self.username)
-           
+        
     def admin_thumbnail(self):
         return u'<img src="%s" />' % (self.photo)
 
     
     def __unicode__(self):
         return self.username
-
-#from social_auth.signals import pre_update
-#from social_auth.backends.facebook import FacebookBackend
-#from social_auth.backends import google
-#from social_auth.backends.twitter import TwitterBackend
-
-#def social_extra_values(sender, user, response, details, **kwargs):
-    #result = False
-    
-    #if "id" in response:
-        ##from apps.photo.models import Photo
-        #from urllib2 import urlopen, HTTPError
-        #from django.template.defaultfilters import slugify
-        ##from apps.account.utils import user_display
-        #from django.core.files.base import ContentFile
-
-        #try:
-            #url = None
-            #if sender == FacebookBackend:
-                #url = "http://graph.facebook.com/%s/picture?type=large" % response["id"]
-                #provider = "facebook"
-            #elif sender == TwitterBackend:
-                #url = response["profile_image_url"]
-                #provider = "twitter"
-            ##if url:
-                ##avatar = urlopen(url)
-                
-            #instance = UserSocialAuth.objects.filter(provider=provider,user=user).get()
-            #user = CustomUser.objects.filter(user=instance).get()
-
-            #user.photo = url
-            #user.save()
-            ##photo = Photo(author = user, is_avatar = True)
-            ##photo.picture.save(slugify(user.username + " social") + '.jpg', 
-            ##ContentFile(avatar.read()))
-
-            ##photo.save()
-
-        #except HTTPError:
-            #pass
-
-        #result = True
-    #return result
-
-#pre_update.connect(social_extra_values, sender=None)

File frontend/tasks.py

View file
+from celery import task
+from frontend.models import CustomUser
+from datetime import timedelta
+
+@task()
+def counter():
+    logger = counter.get_logger(logfile='tasks.log')
+    users = CustomUser.objects.all()
+    
+    for user in users:
+        user.inc_counter()
+        logger.info('Increase counter: %s (%s)' % (user.username, user.counter))
+
+
+
+

File frontend/templates/done.html

View file
     <tr class="odd"><th>Last name:</th> <td>{{ user.last_name|default:"Not provided" }}</td></tr>
     <tr class="odd"><th>Photo:</th> <td>{{ profile.photo|default:"Not provided" }}</td></tr>
     <tr class="even"><th>Last login backend:</th> <td>{{ last_login }}</td></tr>
+    <tr class="even"><th>Counter:</th> <td>{{ profile.counter }}</td></tr>
     <tr class="even"><th>Backend:</th> <td>{{ backend }}</td></tr>
   </table>
 

File frontend/templates/home.html

View file
     <div class='main-box'>
         <div class='home-initial-text'>
         
-        <h1>Django application template</h1>
+        <h1>{% trans "Django application template" %}</h1>
         By <a href="http://twitter.com/eduherraiz">@eduherraiz</a>
         
         </div>

File locale/ca/LC_MESSAGES/django.po

View file
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-03-26 11:07+0100\n"
+"POT-Creation-Date: 2013-04-01 01:27+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 msgid "About"
 msgstr "Referit"
 
-#: frontend/templates/home.html:35
+#: frontend/templates/home.html:31
+msgid "Django application template"
+msgstr "Plantilla d'aplicació en Django"
+
+#: frontend/templates/home.html:39
 msgid "Text for share on twitter"
 msgstr "Texte per compartir a twitter"
 
-#: frontend/templates/home.html:41 frontend/templates/home.html.py:48
-#: frontend/templates/home.html:58
+#: frontend/templates/home.html:45 frontend/templates/home.html.py:52
+#: frontend/templates/home.html:62
 msgid "Share on"
 msgstr "Comparteix"
 
 msgid ""
 "Please enter your old password, for security's sake, and then enter your new "
 "password twice so we can verify you typed it in correctly."
-msgstr "Per favor, introueix la teva antiga contrasenya, per questió de seguretat, y després "
-"introueix la nova dues vegades, per verificar que l'has escrita correctament."
+msgstr ""
+"Per favor, introueix la teva antiga contrasenya, per questió de seguretat, y "
+"després introueix la nova dues vegades, per verificar que l'has escrita "
+"correctament."
 
 #: frontend/templates/registration/password_change_form.html:23
 msgid "Old password:"
 
 #: frontend/templates/registration/password_reset_complete.html:18
 msgid "Your password has been set.  You may go ahead and log in now."
-msgstr "La teva contrasenya ha estat introduida. Pot serguir endevant i iniciar sessió ara."
+msgstr ""
+"La teva contrasenya ha estat introduida. Pot serguir endevant i iniciar "
+"sessió ara."
 
 #: frontend/templates/registration/password_reset_complete.html:20
 msgid "Log in"
 msgid ""
 "Please enter your new password twice so we can verify you typed it in "
 "correctly."
-msgstr "Per favor, introueix la teva contrasenya dues vegades per tal de comprovar que "
-"l'has escrita be."
+msgstr ""
+"Per favor, introueix la teva contrasenya dues vegades per tal de comprovar "
+"que l'has escrita be."
 
 #: frontend/templates/registration/password_reset_confirm.html:32
 msgid "Password reset unsuccessful"
 msgid ""
 "The password reset link was invalid, possibly because it has already been "
 "used.  Please request a new password reset."
-msgstr "El enllaç per resetjar contrasenya es invalid, possiblement perque ja ha "
+msgstr ""
+"El enllaç per resetjar contrasenya es invalid, possiblement perque ja ha "
 "estat empleat. Per favor, torna a demanar el reseteig de contrasenya."
 
 #: frontend/templates/registration/password_reset_done.html:16
 msgid ""
 "We've e-mailed you instructions for setting your password to the e-mail "
 "address you submitted. You should be receiving it shortly."
-msgstr "Hem enviat un correu electrónic amb instruccions per canviar la contrasenya "
+msgstr ""
+"Hem enviat un correu electrónic amb instruccions per canviar la contrasenya "
 "a la adreça que has introduit. L'hauries de rebre en poc temps."
 
 #: frontend/templates/registration/password_reset_email.html:2
 msgid ""
 "Forgotten your password? Enter your e-mail address below, and we'll e-mail "
 "instructions for setting a new one."
-msgstr "Has per la teva contrasenya? Introdueix la teva adreça de correu i t'enviarem "
-"instruccions detallades per triar una de nova."
+msgstr ""
+"Has per la teva contrasenya? Introdueix la teva adreça de correu i "
+"t'enviarem instruccions detallades per triar una de nova."
 
 #: frontend/templates/registration/password_reset_form.html:23
 msgid "E-mail address:"

File locale/es/LC_MESSAGES/django.po

View file
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-03-26 11:07+0100\n"
+"POT-Creation-Date: 2013-04-01 01:27+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 msgid "About"
 msgstr "Sobre"
 
-#: frontend/templates/home.html:35
+#: frontend/templates/home.html:31
+msgid "Django application template"
+msgstr "Plantilla de aplicación en Django"
+
+#: frontend/templates/home.html:39
 msgid "Text for share on twitter"
 msgstr "Texto para compartir en twitter"
 
-#: frontend/templates/home.html:41 frontend/templates/home.html.py:48
-#: frontend/templates/home.html:58
+#: frontend/templates/home.html:45 frontend/templates/home.html.py:52
+#: frontend/templates/home.html:62
 msgid "Share on"
 msgstr "Comparte"
 

File project/admin.py

-from django.contrib import admin
-

File project/settings.py

View file
 
         
 FACEBOOK_APP_ID              = getattr(properties, 'facebook_app_id', '')
-FACEBOOK_API_SECRET          = getattr(properties, 'facebook_app_secret', '')
+FACEBOOK_API_SECRET          = getattr(properties, 'facebook_api_secret', '')
 
 FACEBOOK_EXTENDED_PERMISSIONS = ['email']
 
 # Disable automatic clean-up of the cropping tool
 CROP_AUTO_CLEAN = False
 # Let Celery workers import our tasks module
-#CELERY_IMPORTS = ("tasks", )
 
 
 #EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
 
 CONTACT_EMAIL = getattr(properties, 'contact_email', '')
 
+CELERY_IMPORTS = ("frontend.tasks", )
+
+CELERYBEAT_SCHEDULE = {
+    "AddCounter": {
+        "task": "frontend.tasks.counter",
+        "schedule": timedelta(seconds=5),
+        "args": ()
+    }
+}
+
+
 djcelery.setup_loader()

File supervisord.conf

View file
 command={{ PYTHON }} {{ PROJECT_DIR }}/manage.py runserver --noreload
 
 [program:celeryd]
-command={{ PYTHON }} {{ PROJECT_DIR }}/manage.py celeryd -l info 
+command={{ PYTHON }} {{ PROJECT_DIR }}/manage.py celeryd -l info
+
+[program:celery]
+command={{ PYTHON }} {{ PROJECT_DIR }}/manage.py celery worker --loglevel=INFO
+directory={{ PROJECT_DIR }}
+numprocs=1
+autostart=true
+autorestart=true
+startsecs=10
+
+; Need to wait for currently executing tasks to finish at shutdown.
+; Increase this if you have very long running tasks.
+stopwaitsecs = 600
+
+; if rabbitmq is supervised, set its priority higher
+; so it starts first
+priority=998
+
+[program:celerybeat]
+command={{ PYTHON }} {{ PROJECT_DIR }}/manage.py celery beat --schedule=/var/lib/celery/celerybeat-schedule --loglevel=INFO
+directory={{ PROJECT_DIR }}
+numprocs=1
+autostart=true
+autorestart=true
+startsecs=10
+
+; if rabbitmq is supervised, set its priority higher
+; so it starts first
+priority=999
+