Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent b5ba8a9 commit 125bc84eea52557a947c70e9306dabfb9b99e33e Mark Ransom committed Jun 23, 2012
View
@@ -0,0 +1 @@
+* Mark Ransom <megamark16@gmail.com>
View
10 LICENSE
@@ -0,0 +1,10 @@
+Copyright (c) 2011, Mark Ransom
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* Neither the name of the Salva O'Renick nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,7 @@
+include AUTHORS
+include LICENSE
+include README.rst
+recursive-include live_support/templates/live_support *
+recursive-include live_support/static *
+
+
View
@@ -1,4 +0,0 @@
-django-live-support
-===================
-
-A simple live support chat app for django
View
@@ -0,0 +1,48 @@
+django-live-support
+=================
+A live support chat app for django that lets you chat with visitors to your
+site through the Django Admin interface.
+
+Dependancies
+============
+
+- django (tested with 1.3)
+
+Getting Started
+=============
+
+To get started simply install using ``pip``:
+::
+ pip install django-live-support
+
+Add ``live_support`` to your installed apps and ``syncdb`` (or migrate, if
+you have south installed).
+
+Your installed apps should look something like this:
+::
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.admin',
+ 'live_support',
+ )
+
+Add ``live_support.urls`` to your urls.py, like so:
+::
+ from django.conf.urls.defaults import patterns, include, url
+
+ from django.contrib import admin
+ admin.autodiscover()
+
+ urlpatterns = patterns('',
+ url(r'^admin/', include(admin.site.urls)),
+ url(r'^support/', include('live_support.urls')),
+ )
+
+
+Usage
+=============
+
View
No changes.
View
Binary file not shown.
View
View
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
@@ -0,0 +1,155 @@
+# Django settings for demo project.
+import os
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': os.path.join(PROJECT_DIR, 'demo.db'), # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# URL prefix for admin static files -- CSS, JavaScript and images.
+# Make sure to use a trailing slash.
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = ')q_50ls3!(ftwsnvwmds_x(2yzn(pu17j(bz6@@#4vvi^#=gr0'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+ 'django.contrib.auth.context_processors.auth',
+ 'django.core.context_processors.i18n',
+ 'django.core.context_processors.request',
+ 'django.core.context_processors.media',
+ 'django.core.context_processors.static',
+ 'sekizai.context_processors.sekizai',
+)
+
+ROOT_URLCONF = 'demo.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'django.contrib.admin',
+ 'live_support',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
View
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import patterns, include, url
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ url('^admin/', include(admin.site.urls)),
+ url('^', include('live_support.urls')),
+)
+
View
No changes.
View
@@ -0,0 +1,34 @@
+from django.contrib import admin
+from django.conf import settings
+
+from live_support.models import Chat, ChatMessage
+
+class ChatAdmin(admin.ModelAdmin):
+ list_display = ('id','name','started',)
+ list_display_links = ('id','name',)
+ list_filter = ('started',)
+
+ class Media:
+ js = (
+ "live_support/js/live_support_admin.js",
+ "live_support/js/live_support.js",
+ )
+ css = {
+ 'all': ('live_support/css/live_support.css',),
+ }
+
+ def changelist_view(self, request, extra_context=None):
+ pending_chats = Chat.objects.filter(ended=None, agents=None).order_by('-started')
+ active_chats = Chat.objects.filter(ended=None).filter(agents=request.user)
+ c = {
+ 'pending_chats': pending_chats,
+ 'active_chats': active_chats,
+ }
+ print "ACTIVE CHATS: %s" % active_chats
+ return super(ChatAdmin, self).changelist_view(request, extra_context=c)
+
+
+admin.site.register(Chat, ChatAdmin)
+admin.site.register(ChatMessage)
+
+
View
@@ -0,0 +1,15 @@
+from django import forms
+
+from live_support.models import Chat, ChatMessage
+
+
+class ChatForm(forms.ModelForm):
+ class Meta:
+ model = Chat
+ fields = ('name','details',)
+
+class ChatMessageForm(forms.ModelForm):
+ message = forms.CharField()
+ class Meta:
+ model = ChatMessage
+ fields = ('message',)
View
@@ -0,0 +1,50 @@
+import os
+from django.conf import settings
+from django.db import models
+from django.contrib.auth.models import User
+from datetime import datetime
+from uuid import uuid4
+
+class ChatManager(models.Manager):
+ def get_query_set(self):
+ return super(ChatManager, self).get_query_set().filter(ended=None)
+
+class Chat(models.Model):
+ name = models.CharField(max_length=255)
+ hash_key = models.CharField(unique=True, max_length=64,
+ editable=False, blank=True, default=uuid4)
+ details = models.TextField(blank=True)
+ started = models.DateTimeField(auto_now_add=True)
+ ended = models.DateTimeField(null=True, blank=True)
+ agents = models.ManyToManyField(User, blank=True, related_name='chats')
+ objects = models.Manager()
+ active = ChatManager()
+
+ def __unicode__(self):
+ return '%s: %s' % (self.started, self.name)
+
+ def end(self):
+ self.ended = datetime.now()
+ self.save()
+
+ class Meta:
+ permissions = (
+ ("chat_admin", "Chat Admin"),
+ )
+
+class ChatMessage(models.Model):
+ chat = models.ForeignKey(Chat, related_name='messages')
+ name = models.CharField(max_length=255, blank=True)
+ agent = models.ForeignKey(User, blank=True, null=True)
+ message = models.TextField()
+ sent = models.DateTimeField(auto_now_add=True)
+
+ def get_name(self):
+ if self.agent:
+ return self.agent.first_name or self.agent.username
+ else:
+ return self.name
+
+ def __unicode__(self):
+ return '%s: %s' % (self.sent, self.message)
+
Oops, something went wrong.

0 comments on commit 125bc84

Please sign in to comment.