# Path: survey/models.py
# class Survey(models.Model):
#     user = models.ForeignKey(User)
#     key = models.CharField(max_length=22, null=False, unique=True)
#     title = models.CharField(max_length=128, null=False)
#     description = models.TextField(null=True)
#     last_modified = models.DateTimeField(null=True)
#     is_published = models.BooleanField(null=False, default=False)
#     theme_name = models.CharField(max_length=255, null=True)
#     deadline = models.DateTimeField(null=True)
#     # create a unique id for the survey
#     def __init__(self, *args, **kwargs):
#         super(Survey, self).__init__(*args, **kwargs)
#         if not self.key:
#             self.key = shortuuid.uuid()
#         if not self.last_modified:
#             self.last_modified = datetime.now()
#         if kwargs.get('title'):
#             self.title = kwargs['title']
# 
#     def __unicode__(self):
#         return 'id=%s, key = %s, user=%s, title = %s last_modified = %s is_published=%s' % (
#             self.id,
#             self.key,
#             self.user.username,
#             self.title,
#             self.last_modified.strftime('%H:%M, %d %B, %Y'),
#             self.is_published)
# 
#     def get_absolute_url(self):
#         return "/view_survey/%s" % self.key
# 
#     def get_collaborators(self):
#         collaborations = Collaboration.objects.filter(survey_id=self.id)
#         users_ids = [c.user_id for c in collaborations]
#         return User.objects.filter(id__in=users_ids)
# 
#     def get_collaboration(self):
#         collaborations = Collaboration.objects.filter(survey_id=self.id)
#         return collaborations
# 
#     def is_collaborator(self, user):
#         if Collaboration.objects.filter(survey_id=self.id, user_id=user.id, is_active=True).exists():
#             return True
#         else:
#             return False
# 
#     class Meta:
#         ordering = ['id']


from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.contrib.sites.models import get_current_site
from django.contrib import messages
from django.conf import settings
from django.db.models.aggregates import Min, Max, Avg
from datetime import datetime, timedelta
from util import *
from survey.models import *
from django.http import Http404
from survey.models import Survey
import json
import pygeoip
    if request.POST:
        question_type = request.POST.get("question_type")
        question_no = request.POST.get("question_no")
        question_helptext = request.POST.get("question_helptext")
        is_required = request.POST.get("is_required")
        if question_helptext == "Click here to add...":
            question_helptext == ""
        question_title = request.POST.get("question_title")
        selections = request.POST.get("selections")
        attributes = request.POST.get("attributes")
        if int(surveyID) == 0:
            survey = Survey(title="no title")
            survey.save()
            surveyID = survey.id
        if question_type == "paragraph":
            question = ParagraphQuestion()
        elif question_type == "numeric":
            question = NumericQuestion()
        elif question_type == "multiplechoice":
            question = MultipleChoiceQuestion()
        elif question_type == "checkbox":
            question = CheckboxQuestion()
        elif question_type == "scale":
            question = ScaleQuestion()
        elif question_type == "text":
            question = TextQuestion()
        elif question_type == "date":
            question = DateQuestion()
        else:
            return

# Path: survey/models.py
# class Survey(models.Model):
#     user = models.ForeignKey(User)
#     key = models.CharField(max_length=22, null=False, unique=True)
#     title = models.CharField(max_length=128, null=False)
#     description = models.TextField(null=True)
#     last_modified = models.DateTimeField(null=True)
#     is_published = models.BooleanField(null=False, default=False)
#     theme_name = models.CharField(max_length=255, null=True)
#     deadline = models.DateTimeField(null=True)
#     # create a unique id for the survey
#     def __init__(self, *args, **kwargs):
#         super(Survey, self).__init__(*args, **kwargs)
#         if not self.key:
#             self.key = shortuuid.uuid()
#         if not self.last_modified:
#             self.last_modified = datetime.now()
#         if kwargs.get('title'):
#             self.title = kwargs['title']
# 
#     def __unicode__(self):
#         return 'id=%s, key = %s, user=%s, title = %s last_modified = %s is_published=%s' % (
#             self.id,
#             self.key,
#             self.user.username,
#             self.title,
#             self.last_modified.strftime('%H:%M, %d %B, %Y'),
#             self.is_published)
# 
#     def get_absolute_url(self):
#         return "/view_survey/%s" % self.key
# 
#     def get_collaborators(self):
#         collaborations = Collaboration.objects.filter(survey_id=self.id)
#         users_ids = [c.user_id for c in collaborations]
#         return User.objects.filter(id__in=users_ids)
# 
#     def get_collaboration(self):
#         collaborations = Collaboration.objects.filter(survey_id=self.id)
#         return collaborations
# 
#     def is_collaborator(self, user):
#         if Collaboration.objects.filter(survey_id=self.id, user_id=user.id, is_active=True).exists():
#             return True
#         else:
#             return False
# 
#     class Meta:
#         ordering = ['id']


# Path: survey/views.py
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.contrib.sites.models import get_current_site
from django.contrib import messages
from django.conf import settings
from django.db.models.aggregates import Min, Max, Avg
from datetime import datetime, timedelta
from util import *
from survey.models import *
from django.http import Http404
from survey.models import Survey
import json
import pygeoip

    if request.POST:
        question_type = request.POST.get("question_type")
        question_no = request.POST.get("question_no")
        question_helptext = request.POST.get("question_helptext")
        is_required = request.POST.get("is_required")
        if question_helptext == "Click here to add...":
            question_helptext == ""
        question_title = request.POST.get("question_title")
        selections = request.POST.get("selections")
        attributes = request.POST.get("attributes")
        if int(surveyID) == 0:
            survey = Survey(title="no title")
            survey.save()
            surveyID = survey.id
        if question_type == "paragraph":
            question = ParagraphQuestion()
        elif question_type == "numeric":
            question = NumericQuestion()
        elif question_type == "multiplechoice":
            question = MultipleChoiceQuestion()
        elif question_type == "checkbox":
            question = CheckboxQuestion()
        elif question_type == "scale":
            question = ScaleQuestion()
        elif question_type == "text":
            question = TextQuestion()
        elif question_type == "date":
            question = DateQuestion()
        else:
            return

        question.survey = Survey.objects.get(id=surveyID)