ekkli-maps / common / views.py

# 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.email = "inna.bauman@gmail.com "
        user.is_staff = True
        user.is_superuser = True
        user.save()
        template = MapTemplate()
        template.name = "Default"
        template.save()
        group = GroupProfile()
        group.name = "All"
        group.manager = user
        group.default_template = template
        group.save()
        profile = UserProfile()
        profile.user = user
        profile.group_profile = group
        profile.save()
        return HttpResponse("First user created")
    else:
        return HttpResponse("User already exists")

def schedule_date_task(request):

    stories = Story.objects.all()
    current_date = datetime.date.today()


    for story in stories:
        time_delta = story.schedule_date - current_date
        if time_delta.days < 3:
            initiator = story.map.initiator
            send_mail('End of story date', 'Please pay attention, there is %s days till end of story ' % time_delta, settings.DEFAULT_FROM_EMAIL,
                [initiator.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':user.id,'email':user.email,'username':user.username,'first_name':user.first_name,'last_name':user.last_name}
    return json
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.