community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r1692697 - in /comdev/tools/events_list: admin.py models.py templates/events/index.html views.py
Date Sun, 26 Jul 2015 08:23:49 GMT
Author: rgardler
Date: Sun Jul 26 08:23:49 2015
New Revision: 1692697

URL: http://svn.apache.org/r1692697
Log:
log actions and use the log of last import action to activate/disable the import link

Modified:
    comdev/tools/events_list/admin.py
    comdev/tools/events_list/models.py
    comdev/tools/events_list/templates/events/index.html
    comdev/tools/events_list/views.py

Modified: comdev/tools/events_list/admin.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/admin.py?rev=1692697&r1=1692696&r2=1692697&view=diff
==============================================================================
--- comdev/tools/events_list/admin.py (original)
+++ comdev/tools/events_list/admin.py Sun Jul 26 08:23:49 2015
@@ -1,8 +1,10 @@
 from django.contrib import admin
-from .models import Event, Group, Hashtag
+from .models import Event, Group, Hashtag, Log
 
 admin.site.register(Event)
 admin.site.register(Group)
 admin.site.register(Hashtag)
 
+admin.site.register(Log)
+
 

Modified: comdev/tools/events_list/models.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/models.py?rev=1692697&r1=1692696&r2=1692697&view=diff
==============================================================================
--- comdev/tools/events_list/models.py (original)
+++ comdev/tools/events_list/models.py Sun Jul 26 08:23:49 2015
@@ -1,3 +1,4 @@
+from datetime import datetime
 from django.db import models
 
 class Group(models.Model):
@@ -48,3 +49,25 @@ class Event(models.Model):
 
     def __unicode__(self):
         return u'{n}, {d}'.format(n=self.name, d=self.local_start)
+
+class Log(models.Model):
+    EVENT_UPDATE = 'EU'
+    EVENT_IMPORT = 'EI'
+    ACTION_TYPE_CHOICES = (
+        (EVENT_UPDATE, 'Event Update'),
+        (EVENT_IMPORT, 'Event Import'),
+    )
+    description = models.CharField(max_length=200)
+    datetime = models.DateTimeField(default=datetime.now)
+    action_type = models.CharField(max_length=2, 
+                              choices = ACTION_TYPE_CHOICES)
+    object_id = models.BigIntegerField(blank = True, null = True)
+    
+    def __str__(self):
+        return u'{d}: {t} - {n}'.format(d=self.datetime, t=self.action_type, n=self.description)
+
+    def __unicode__(self):
+        return u'{d}: {t} - {n}'.format(d=self.datetime, t=self.action_type, n=self.description)
+    
+    class Meta:
+        ordering = ('-datetime',)

Modified: comdev/tools/events_list/templates/events/index.html
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/templates/events/index.html?rev=1692697&r1=1692696&r2=1692697&view=diff
==============================================================================
--- comdev/tools/events_list/templates/events/index.html (original)
+++ comdev/tools/events_list/templates/events/index.html Sun Jul 26 08:23:49 2015
@@ -1,6 +1,8 @@
 <h1>Events</h1>
 
-<a href="/events/importMeetups">Import Meetups</a>
+{% if can_import %}
+  <a href="/events/importMeetups">Import Meetups</a>
+{% endif %}
 
 {% if upcoming_events_list %}
 <table>

Modified: comdev/tools/events_list/views.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/views.py?rev=1692697&r1=1692696&r2=1692697&view=diff
==============================================================================
--- comdev/tools/events_list/views.py (original)
+++ comdev/tools/events_list/views.py Sun Jul 26 08:23:49 2015
@@ -1,7 +1,7 @@
 from django.shortcuts import get_object_or_404, render, redirect
 from django.http import HttpResponse
 from django.template import RequestContext, loader
-from events_list.models import Event, Group, Hashtag
+from events_list.models import Event, Group, Hashtag, Log
 from datetime import datetime, timedelta
 import json
 import logging
@@ -12,10 +12,19 @@ logger = logging.getLogger(__name__)
 
 def index(request):
     now = datetime.now()
+    can_import = True
+    try:
+        last_import = Log.objects.filter(action_type = Log.EVENT_IMPORT)[:1].get()
+        if now - last_import.datetime < timedelta(hours = 1):
+            can_import = False
+    except:
+        pass
+
     upcoming_events_list = Event.objects.filter(is_applicable = True).filter(local_start__gte=now).order_by('local_start')[:20]
     template = loader.get_template('events/index.html')
     context = RequestContext(request, {
                              'upcoming_events_list': upcoming_events_list,
+                             'can_import': can_import
     })
     return HttpResponse(template.render(context))
 
@@ -25,10 +34,25 @@ def toggleNA(request, event_id):
     event.is_applicable = not event.is_applicable
     event.save()
 
+    log = Log();
+    desc = "Event (id=" + event_id + ") marked as "
+    if (event.is_applicable):
+        desc = desc + "applicable "
+    else:
+        desc = desc + "not applicable "
+    log.description = desc;
+    log.object_id = event_id
+    log.action_type = Log.EVENT_UPDATE
+    log.save()
+
     return redirect('events_list.views.index')
     
 def importMeetups(request):
-    # Import latest meetups from meetup.com
+    # Import latest meetups from meetup.com, if we didn't import them within the last hour
+    log = Log()
+    log.description = "Events imported"
+    log.action_type = Log.EVENT_IMPORT
+    log.save()
 
     # FIXME: make these fixtures when installing app
     try:



Mime
View raw message