community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r1684218 - in /comdev/tools/events_list: admin.py models.py views.py
Date Mon, 08 Jun 2015 16:37:49 GMT
Author: rgardler
Date: Mon Jun  8 16:37:49 2015
New Revision: 1684218

URL: http://svn.apache.org/r1684218
Log:
make hashtags a manytomany relationship rather than hard coded value

Modified:
    comdev/tools/events_list/admin.py
    comdev/tools/events_list/models.py
    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=1684218&r1=1684217&r2=1684218&view=diff
==============================================================================
--- comdev/tools/events_list/admin.py (original)
+++ comdev/tools/events_list/admin.py Mon Jun  8 16:37:49 2015
@@ -1,7 +1,8 @@
 from django.contrib import admin
-from .models import Event, Group
+from .models import Event, Group, Hashtag
 
 admin.site.register(Event)
 admin.site.register(Group)
+admin.site.register(Hashtag)
 
 

Modified: comdev/tools/events_list/models.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/models.py?rev=1684218&r1=1684217&r2=1684218&view=diff
==============================================================================
--- comdev/tools/events_list/models.py (original)
+++ comdev/tools/events_list/models.py Mon Jun  8 16:37:49 2015
@@ -15,6 +15,13 @@ class Group(models.Model):
 
 class Hashtag(models.Model):
     hashtag = models.CharField(max_length=15)
+
+    def __str__(self):
+        return self.hashtag
+
+    def __unicode__(self):
+        return unicode(self.hashtag)
+
     
 class Event(models.Model):
     name = models.CharField(max_length=200)
@@ -25,14 +32,15 @@ class Event(models.Model):
     local_start = models.DateTimeField()
     local_end = models.DateTimeField()
     utc_offset = models.BigIntegerField()
-    hashtag = models.ForeignKey(Hashtag)
+    hashtag = models.ManyToManyField(Hashtag)
     is_applicable = models.BooleanField(help_text = "Indicates if an event is applicable
to our audience or not.", default=True)
     
     @property
     def tweet(self):
-        hashtags = "#Apache #Meetup"
-        tweet = self.group.city + ", " + self.local_start.strftime("%-d %b") + ": " + self.name

-        tweet = tweet + ' ' + hashtags
+        tweet = self.group.city + ", " + self.local_start.strftime("%-d %b") + ": " + self.name
+        hashtags = self.hashtag.all()
+        for hashtag in hashtags:
+            tweet = tweet + " #" + hashtag.hashtag
         return tweet
     
     def __str__(self):

Modified: comdev/tools/events_list/views.py
URL: http://svn.apache.org/viewvc/comdev/tools/events_list/views.py?rev=1684218&r1=1684217&r2=1684218&view=diff
==============================================================================
--- comdev/tools/events_list/views.py (original)
+++ comdev/tools/events_list/views.py Mon Jun  8 16:37: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
+from events_list.models import Event, Group, Hashtag
 from datetime import datetime, timedelta
 import json
 import logging
@@ -75,7 +75,20 @@ def importMeetups(request):
     grp_deets = {}
     for g in grps:
         grp_deets[ g['id'] ] = g
-    
+
+    # FIXME: make these fixtures when installing app
+    try:
+        apache_hashtag = Hashtag.objects.get(hashtag = 'Apache')
+    except Hashtag.DoesNotExist:
+        apache_hashtag._hashtag = 'Apache'
+        apache_hashtag.save()
+
+    try:
+        meetup_hashtag = Hashtag.objects.get(hashtag = 'Meetup')
+    except Hashtag.DoesNotExist:
+        meetup_hashtag.hashtag = 'Meetup'
+        meetup_hashtag.save()
+        
     for meetup in meetups:
         # Group information ...
         grp = grp_deets[ meetup['group']['id'] ]
@@ -116,6 +129,8 @@ def importMeetups(request):
             event.local_start = datetime.utcfromtimestamp(start + offset)
             event.local_end = datetime.utcfromtimestamp(start + end + offset)
             event.utc_offset = offset
+            event.hashtag.add(apache_hashtag)
+            event.hashtag.add(meetup_hashtag)
             event.save()
         except:
             print('Unable to save Event object: '), sys.exc_info()[0], sys.exc_info()[1]



Mime
View raw message