Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Customer Care. Canned responses, incl. initial data. Bug 591942.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Wenzel authored and Alex Buchanan committed Sep 27, 2010
1 parent 78f55c9 commit 3d9d460
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/customercare/admin.py
@@ -0,0 +1,35 @@
from django.contrib import admin

from .models import Tweet, CannedCategory, CannedResponse, CategoryMembership


class TweetAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
list_display = ('tweet_id', '__unicode__', 'created', 'locale')
list_filter = ('locale',)
search_fields = ('raw_json',)
admin.site.register(Tweet, TweetAdmin)


class MembershipInline(admin.StackedInline):
"""Inline to show response/category relationships."""
model = CategoryMembership
extra = 1


class CategoryAdmin(admin.ModelAdmin):
list_display = ('title', 'weight', 'response_count')
inlines = (MembershipInline,)

def response_count(self, obj):
return obj.responses.count()
admin.site.register(CannedCategory, CategoryAdmin)


class ResponseAdmin(admin.ModelAdmin):
list_display = ('title', 'category_count')
inlines = (MembershipInline,)

def category_count(self, obj):
return obj.categories.count()
admin.site.register(CannedResponse, ResponseAdmin)
46 changes: 46 additions & 0 deletions apps/customercare/models.py
@@ -1,4 +1,5 @@
from datetime import datetime
import json

from django.db import models

Expand All @@ -15,3 +16,48 @@ class Tweet(ModelBase):
class Meta:
get_latest_by = 'created'
ordering = ('-created',)

def __unicode__(self):
tweet = json.loads(self.raw_json)
return tweet['text']


class CannedCategory(ModelBase):
"""Category for canned responses."""
title = models.CharField(max_length=255)
weight = models.IntegerField(
default=0, db_index=True,
help_text='Heavier items sink, lighter ones bubble up.')

class Meta:
ordering = ('weight', 'title')
verbose_name_plural = 'Canned categories'

def __unicode__(self):
return self.title


class CannedResponse(ModelBase):
"""Canned response to tweets."""
title = models.CharField(max_length=255)
response = models.CharField(max_length=140)
categories = models.ManyToManyField(
CannedCategory, related_name='responses', through='CategoryMembership')

class Meta:
ordering = ('title',)

def __unicode__(self):
return self.title


class CategoryMembership(ModelBase):
"""Mapping table for canned responses <-> categories."""
category = models.ForeignKey(CannedCategory)
response = models.ForeignKey(CannedResponse)
weight = models.IntegerField(
default=0, db_index=True,
help_text='Heavier items sink, lighter ones bubble up.')

def __unicode__(self):
return '%s in %s' % (self.response.title, self.category.title)
27 changes: 27 additions & 0 deletions migrations/42-customercare-cannedresponses.sql
@@ -0,0 +1,27 @@
BEGIN;
CREATE TABLE `customercare_cannedcategory` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`title` varchar(255) NOT NULL,
`weight` integer NOT NULL
)
;
CREATE TABLE `customercare_cannedresponse` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`title` varchar(255) NOT NULL,
`response` varchar(140) NOT NULL
)
;
CREATE TABLE `customercare_categorymembership` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`category_id` integer NOT NULL,
`response_id` integer NOT NULL,
`weight` integer NOT NULL
)
;
ALTER TABLE `customercare_categorymembership` ADD CONSTRAINT `category_id_refs_id_e187a5e8` FOREIGN KEY (`category_id`) REFERENCES `customercare_cannedcategory` (`id`);
ALTER TABLE `customercare_categorymembership` ADD CONSTRAINT `response_id_refs_id_8f9177e9` FOREIGN KEY (`response_id`) REFERENCES `customercare_cannedresponse` (`id`);
CREATE INDEX `customercare_cannedcategory_f8f0a775` ON `customercare_cannedcategory` (`weight`);
CREATE INDEX `customercare_categorymembership_42dc49bc` ON `customercare_categorymembership` (`category_id`);
CREATE INDEX `customercare_categorymembership_d5ea739f` ON `customercare_categorymembership` (`response_id`);
CREATE INDEX `customercare_categorymembership_f8f0a775` ON `customercare_categorymembership` (`weight`);
COMMIT;
19 changes: 19 additions & 0 deletions migrations/43-customercare-acls.sql
@@ -0,0 +1,19 @@
INSERT IGNORE INTO `django_content_type` (`name`, `app_label`, `model`) VALUES
('tweet', 'customercare', 'tweet'),
('canned category', 'customercare', 'cannedcategory'),
('canned response', 'customercare', 'cannedresponse'),
('category membership', 'customercare', 'categorymembership');

INSERT IGNORE INTO `auth_permission` (`name`, `content_type_id`, `codename`) VALUES
('Can add tweet', 36, 'add_tweet'),
('Can change tweet', 36, 'change_tweet'),
('Can delete tweet', 36, 'delete_tweet'),
('Can add canned category', 37, 'add_cannedcategory'),
('Can change canned category', 37, 'change_cannedcategory'),
('Can delete canned category', 37, 'delete_cannedcategory'),
('Can add canned response', 38, 'add_cannedresponse'),
('Can change canned response', 38, 'change_cannedresponse'),
('Can delete canned response', 38, 'delete_cannedresponse'),
('Can add category membership', 39, 'add_categorymembership'),
('Can change category membership', 39, 'change_categorymembership'),
('Can delete category membership', 39, 'delete_categorymembership');
50 changes: 50 additions & 0 deletions migrations/44-cannedresponses-initialdata.sql
@@ -0,0 +1,50 @@
INSERT INTO `customercare_cannedcategory` (`id`, `title`, `weight`) VALUES
(1, 'Welcome and Thanks', 0),
(2, 'Using Firefox', 1),
(3, 'Firefox Beta', 2),
(4, 'Support', 3),
(5, 'Get Involved', 4);

INSERT INTO `customercare_cannedresponse` (`id`, `title`, `response`) VALUES
(1, 'Welcome to our community', 'Thanks for joining Mozilla! You're now part of our global community. We're here if you need help: http://mzl.la/bMDof6'),
(2, 'Thanks for using Firefox', 'Thanks for using Firefox! You’re not just a user to us, but part of a community that''s 400M strong: http://mzl.la/9whtWo'),
(3, 'We’re a non-profit organization', 'Hey, I’m a Mozilla volunteer. Did you know Mozilla is made up of 1000s of us worldwide? More here: http://mzl.la/cvlwvd'),
(4, 'Tip & tricks', 'Need help getting started with Firefox? Here are some tips & tricks for getting the most out of it: http://mzl.la/c0B9P2'),
(5, 'Customize Firefox with add-ons', 'Have you tried add-ons? Cool apps for shopping, music, news, whatever you do online. Start here: http://mzl.la/blOuoD'),
(6, 'Add-on reviews', 'Just getting started with Firefox? Add-ons personalize it with cool features & function. User reviews: http://mzl.la/cGypVI'),
(7, 'Upgrade Firefox', 'Hey, maybe you need to upgrade Firefox? New version is speedier with a lot more going on. Download: http://mzl.la/9wJe30'),
(8, 'Update plugins and add-ons', 'Have you updated your plug-ins and add-ons? Should work out the kinks. Here’s the place to refresh: http://mzl.la/cGCg12'),
(9, 'Try the Beta', 'Try the future of Firefox! We need your help testing the new beta. Hop on board: http://mzl.la/d23n7a'),
(10, 'Firefox Sync', 'Tried Firefox Sync? It’s awesome! Switch computers & it saves open tabs, pwords, history. Try it: http://mzl.la/aHHUYA'),
(11, 'Firefox Panorama', 'Heard about Firefox Panorama? It groups and displays your tabs, eliminating clutter. Give it a whirl! http://mzl.la/d21MyY'),
(12, 'Fix crashes', 'Sorry your Firefox is crashing. Here’s a list of quick fixes to prevent that from happening again: http://mzl.la/atSsFt'),
(13, 'Slow Firefox startup', 'Slow start could mean your Firefox just needs a refresh. Here are tips to make Firefox load faster: http://mzl.la/9bB1FY'),
(14, 'Quick Firefox fixes', 'Have you tried Firefox support? If their quick fixes don’t solve it, volunteers are ready to help out: http://mzl.la/9V9uWd'),
(15, 'Ask SUMO', 'Maybe ask SUMO about this issue? Firefox’s community support team. They’ll know what’s up: http://mzl.la/bMDof6'),
(16, 'Get involved with Mozilla', 'Want a better web? Join the Mozilla movement. There is something to do for everyone. Get started: http://mzl.la/cufJmX'),
(17, 'Join Drumbeat', 'Want to spark a movement? Mozilla Drumbeat is your chance to keep the web open and free. More info: http://mzl.la/aIXCLA'),
(18, 'Become a beta tester', 'Become a beta tester! Help develop the next Firefox. You don’t have to be a techie to contribute: http://mzl.la/d23n7a'),
(19, 'Mozilla Developer Network', 'Open up the web & make it better! Build web pages, apps and add-ons here: Mozilla Developer Network http://mzl.la/9gQfrn'),
(20, 'Report a bug', 'Thanks for finding a bug. It makes everyone’s Firefox experience better if you report it. It''s easy: http://mzl.la/bcujVc');

INSERT INTO `customercare_categorymembership` (`id`, `category_id`, `response_id`, `weight`) VALUES
(1, 1, 1, 0),
(2, 1, 2, 1),
(3, 1, 3, 2),
(4, 1, 4, 3),
(5, 2, 5, 0),
(6, 2, 6, 1),
(7, 2, 7, 2),
(8, 2, 8, 3),
(9, 3, 9, 0),
(10, 3, 10, 1),
(11, 3, 11, 2),
(12, 4, 12, 0),
(13, 4, 13, 1),
(14, 4, 14, 2),
(15, 4, 15, 3),
(16, 5, 16, 0),
(17, 5, 17, 1),
(18, 5, 18, 2),
(19, 5, 19, 3),
(20, 5, 20, 4);

0 comments on commit 3d9d460

Please sign in to comment.