ekkli-maps / common /

Full commit
# Create your views here.
import datetime
from django.conf import settings
from django.core.mail import send_mail
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.utils import simplejson
from common.models import UserChannel
from maps.models import Story, UserProfile, GroupProfile, MapTemplate

def setup_first_user(request):
    if not User.objects.filter(username="admin").count():
        user = User()
        user.username = "admin"
        user.set_password("admin") = " "
        user.is_staff = True
        user.is_superuser = True
        template = MapTemplate() = "Default"
        group = GroupProfile() = "All"
        group.manager = user
        group.default_template = template
        profile = UserProfile()
        profile.user = user
        profile.group_profile = group
        return HttpResponse("First user created")
        return HttpResponse("User already exists")

def schedule_date_task(request):

    stories = Story.objects.all()
    current_date =

    for story in stories:
        time_delta = story.schedule_date - current_date
        if time_delta.days < 3:
            initiator =
            send_mail('End of story date', 'Please pay attention, there is %s days till end of story ' % time_delta, settings.DEFAULT_FROM_EMAIL,
                [], fail_silently=False)

def online_users(request):

    users = [obj.user for obj in UserChannel.objects.filter(connected=True, page_url = request.GET['path'])]

    json_users = [_user_to_json(user) for user in users ]

    data = simplejson.dumps(json_users)
    return HttpResponse(data)

def _user_to_json(user):
    json = {'user_id','email','username':user.username,'first_name':user.first_name,'last_name':user.last_name}
    return json