Esempio n. 1
0
def delete_action(request, action_slug):
    """Deletes the given Smart Grid Game Action."""
    _ = request
    action = smartgrid.get_action(action_slug)
    action.delete()
    response = HttpResponseRedirect("/sgg_designer/")
    return response
Esempio n. 2
0
def action_feedback(request, action_type, slug):
    """Handle feedback for an action."""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user
    profile = request.user.profile

    form = ActionFeedbackForm(request.POST)

    if form.is_valid():
        #print form.cleaned_data
        # should do something ??
        pass

    feedback, created = ActionFeedback.objects.get_or_create(action=action,
                                                             user=user)
    has_comment = False
    has_score = False
    if 'Score' in request.POST:
        feedback.rating = request.POST['Score']
        has_score = True
    else:
        feedback.rating = 0
    if 'comments' in request.POST:
        feedback.comment = request.POST['comments']
        if len(feedback.comment.strip()
               ) > 0:  # ignore pure whitespace comments
            has_comment = True
    else:
        feedback.comment = ""
    feedback.changed = datetime.datetime.now()
    if has_comment or has_score:
        feedback.save()  # only save if they provided any feedback
    else:
        if created:
            feedback.delete()  # remove the feedback
            created = False  # reset created for giving points

    if created:
        # Give the user points for providing feedback
        profile.add_points(score_mgr.feedback_points(),
                           datetime.datetime.today(),
                           "{0}: {1} (Provide feedback)"\
                            .format(action.type.capitalize(), action.title), action)
        if score_mgr.feedback_points() > 0:
            message = "Thank you for your feedback on {0}: {1} you've earned {2} points"\
            .format(action.type.capitalize(), action.title, score_mgr.feedback_points())
        else:
            message = "Thank you for your feedback on {0}: {1}"\
                .format(action.type.capitalize(), action.title)
        UserNotification.create_info_notification(user,
                                                  message,
                                                  display_alert=True,
                                                  content_object=action)
    # Take them back to the action page.
    return HttpResponseRedirect(
        reverse("activity_task", args=(
            action.type,
            action.slug,
        )))
Esempio n. 3
0
def drop_action(request, action_type, slug):
    """Handle the drop task request."""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user

    try:
        member = user.actionmember_set.get(action=action,
                                           approval_status="pending")
        member.delete()

        response = HttpResponseRedirect(
            reverse("activity_task", args=(
                action.type,
                action.slug,
            )))

        value = score_mgr.signup_points()
        notification = "%s dropped. you lose %d points." % (action.type, value)
        response.set_cookie("task_notify", notification)
        return response

    except ObjectDoesNotExist:
        pass

    messages.error = 'It appears that you are not participating in this action.'
    # Take them back to the action page.
    return HttpResponseRedirect(
        reverse("activity_task", args=(
            action.type,
            action.slug,
        )))
Esempio n. 4
0
def view_action(request, action_type, slug):
    """individual action page"""
    action = smartgrid.get_action(slug=slug)
    user = request.user
    team = user.get_profile().team
    view_objects = {}

    action = smartgrid.annotate_action_details(user, action)

    if not action.is_unlock:
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        response.set_cookie("task_unlock_condition", action.unlock_condition_text)
        return response

    completed_members = smartgrid.get_action_members(action)
    completed_count = completed_members.count()
    team_members = completed_members.select_related('user__profile').filter(
        user__profile__team=team)

    if action_type == "commitment":
        form = view_commitments.view(request, action)
    elif action_type == "activity":
        form = view_activities.view(request, action)

        # if there is embedded widget, get the supplied objects
        if action.embedded_widget:
            view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
            view_objects[action.embedded_widget] = importlib.import_module(
                view_module_name).supply(request, None)
            view_objects['embedded_widget_template'] = "widgets/" + \
                action.embedded_widget + "/templates/index.html"
    elif action.type in ("event", "excursion"):  # action.event:
        form = view_events.view(request, action)
        # calculate available seat
        action.available_seat = action.event.event_max_seat - completed_count
    elif action_type == "filler":
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        return response

    user_reminders = view_reminders.load_reminders(action, user)
    try:
        feedback = ActionFeedback.objects.get(user=user.pk, action=action.pk)
    except ObjectDoesNotExist:
        feedback = None

    if challenge_mgr.is_game_enabled("Quest Game Mechanics"):
        view_objects['quests'] = get_quests(user)

    return render_to_response("task.html", {
        "action": action,
        "form": form,
        "completed_count": completed_count,
        "team_members": team_members,
        "display_form": True if "display_form" in request.GET else False,
        "reminders": user_reminders,
        "view_objects": view_objects,
        "feedback_p": feedback,
        }, context_instance=RequestContext(request))
Esempio n. 5
0
def view_action(request, action_type, slug):
    """individual action page"""
    action = smartgrid.get_action(slug=slug)
    user = request.user
    team = user.profile.team
    view_objects = {}

    action = smartgrid.annotate_action_details(user, action)

    if not action.is_unlock:
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        response.set_cookie("task_unlock_condition",
                            action.unlock_condition_text)
        return response

    completed_members = smartgrid.get_action_members(action)
    completed_count = completed_members.count()
    team_members = completed_members.select_related('user__profile').filter(
        user__profile__team=team)

    if action_type == "commitment":
        form = view_commitments.view(request, action)
    elif action_type == "activity":
        form = view_activities.view(request, action)

        # if there is embedded widget, get the supplied objects
        if action.embedded_widget:
            view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
            view_objects[action.embedded_widget] = importlib.import_module(
                view_module_name).supply(request, None)
            view_objects['embedded_widget_template'] = "widgets/" + \
                action.embedded_widget + "/templates/index.html"
    elif action.type in ("event", "excursion"):  # action.event:
        form = view_events.view(request, action)
        # calculate available seat
        action.available_seat = action.event.event_max_seat - completed_count
    elif action_type == "filler":
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        return response

    user_reminders = view_reminders.load_reminders(action, user)
    try:
        feedback = ActionFeedback.objects.get(user=user.pk, action=action.pk)
    except ObjectDoesNotExist:
        feedback = None

    return render_to_response(
        "task.html", {
            "action": action,
            "form": form,
            "completed_count": completed_count,
            "team_members": team_members,
            "display_form": True if "display_form" in request.GET else False,
            "reminders": user_reminders,
            "view_objects": view_objects,
            "feedback_p": feedback,
        },
        context_instance=RequestContext(request))
Esempio n. 6
0
def add_action(request, action_type, slug):
    """Handle the Submission of the task."""

    action = smartgrid.get_action(slug=slug)
    if action_type == "commitment":
        return view_commitments.add(request, action.commitment)
    elif action_type == "activity":
        return view_activities.add(request, action.activity)
    else:       # event
        return view_events.add(request, action.event)
Esempio n. 7
0
def view_feedback(request, action_type, slug):
    """view the detailed feedback for the action."""
    _ = action_type
    action = smartgrid.get_action(slug)

    return render_to_response("feedback_details.html", {
        "action": action,
        "feedback": feedback_analysis.get_action_feedback(action),
        "scale": feedback_analysis.get_likert_scale_totals(action),
        }, context_instance=RequestContext(request))
Esempio n. 8
0
def add_action(request, action_type, slug):
    """Handle the Submission of the task."""

    action = smartgrid.get_action(slug=slug)
    if action_type == "commitment":
        return view_commitments.add(request, action.commitment)
    elif action_type == "activity":
        return view_activities.add(request, action.activity)
    else:  # event
        return view_events.add(request, action.event)
Esempio n. 9
0
def action_feedback(request, action_type, slug):
    """Handle feedback for an action."""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user
    profile = request.user.get_profile()

    form = ActionFeedbackForm(request.POST)

    if form.is_valid():
        #print form.cleaned_data
        # should do something ??
        pass

    feedback, created = ActionFeedback.objects.get_or_create(action=action, user=user)
    has_comment = False
    has_score = False
    if 'Score' in request.POST:
        feedback.rating = request.POST['Score']
        has_score = True
    else:
        feedback.rating = 0
    if 'comments' in request.POST:
        feedback.comment = request.POST['comments']
        if len(feedback.comment.strip()) > 0:  # ignore pure whitespace comments
            has_comment = True
    else:
        feedback.comment = ""
    feedback.changed = datetime.datetime.now()
    if has_comment or has_score:
        feedback.save()  # only save if they provided any feedback
    else:
        if created:
            feedback.delete()  # remove the feedback
            created = False  # reset created for giving points

    if created:
        # Give the user points for providing feedback
        profile.add_points(score_mgr.feedback_points(),
                           datetime.datetime.today(),
                           "{0}: {1} (Provide feedback)"\
                            .format(action.type.capitalize(), action.title), action)
        if score_mgr.feedback_points() > 0:
            message = "Thank you for your feedback on {0}: {1} you've earned {2} points"\
            .format(action.type.capitalize(), action.title, score_mgr.feedback_points())
        else:
            message = "Thank you for your feedback on {0}: {1}"\
                .format(action.type.capitalize(), action.title)
        UserNotification.create_info_notification(user, message,
                                                  display_alert=True,
                                                  content_object=action)
    # Take them back to the action page.
    return HttpResponseRedirect(reverse("activity_task", args=(action.type, action.slug,)))
Esempio n. 10
0
def view_feedback(request, action_type, slug):
    """view the detailed feedback for the action."""
    _ = action_type
    action = smartgrid.get_action(slug)

    return render_to_response(
        "feedback_details.html", {
            "action": action,
            "feedback": feedback_analysis.get_action_feedback(action),
            "scale": feedback_analysis.get_likert_scale_totals(action),
        },
        context_instance=RequestContext(request))
Esempio n. 11
0
def change_feedback(request, action_type, slug):
    """Allows the user to change their feedback for an action."""
    _ = action_type
    action = smartgrid.get_action(slug)
    user = request.user
    feedback = ActionFeedback.objects.get(action=action.pk, user=user.pk)

    return render_to_response("change_feedback.html", {
        "action": action,
        "feedback": feedback,
        "user": user
        }, context_instance=RequestContext(request))
Esempio n. 12
0
def change_feedback(request, action_type, slug):
    """Allows the user to change their feedback for an action."""
    _ = action_type
    action = smartgrid.get_action(slug)
    user = request.user
    feedback = ActionFeedback.objects.get(action=action.pk, user=user.pk)

    return render_to_response("change_feedback.html", {
        "action": action,
        "feedback": feedback,
        "user": user
    },
                              context_instance=RequestContext(request))
Esempio n. 13
0
def view_action(request, action_type, slug):
    """individual action page"""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user
    view_objects = {}

    action = smartgrid.annotate_action_details(user, action)

    return render_to_response("action.html", {
        "action": action,
        "display_form": True if "display_form" in request.GET else False,
        "view_objects": view_objects,
        }, context_instance=RequestContext(request))
Esempio n. 14
0
def view_action(request, action_type, slug):
    """individual action page"""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user
    view_objects = {}

    action = smartgrid.annotate_action_details(user, action)

    return render_to_response(
        "action.html", {
            "action": action,
            "display_form": True if "display_form" in request.GET else False,
            "view_objects": view_objects,
        },
        context_instance=RequestContext(request))
Esempio n. 15
0
def drop_action(request, action_type, slug):
    """Handle the drop task request."""
    _ = action_type
    action = smartgrid.get_action(slug=slug)
    user = request.user

    try:
        member = user.actionmember_set.get(action=action, approval_status="pending")
        member.delete()

        response = HttpResponseRedirect(
            reverse("activity_task", args=(action.type, action.slug,)))

        value = score_mgr.signup_points()
        notification = "%s dropped. you lose %d points." % (action.type, value)
        response.set_cookie("task_notify", notification)
        return response

    except ObjectDoesNotExist:
        pass

    messages.error = 'It appears that you are not participating in this action.'
    # Take them back to the action page.
    return HttpResponseRedirect(reverse("activity_task", args=(action.type, action.slug,)))
Esempio n. 16
0
def reminder(request, action_type, slug):
    """Handle the send reminder request."""
    _ = action_type
    if request.is_ajax():
        if request.method == "POST":
            profile = request.user.profile
            action = smartgrid.get_action(slug=slug)
            form = ReminderForm(request.POST)
            if form.is_valid():

                # Try and retrieve the reminders.
                try:
                    email_reminder = EmailReminder.objects.get(
                        user=request.user, action=action)
                    if form.cleaned_data["send_email"]:
                        email_reminder.email_address = form.cleaned_data[
                            "email"]
                        email_reminder.send_at = action.event.event_date - datetime.timedelta(
                            hours=int(form.cleaned_data["email_advance"]))
                        email_reminder.save()

                        profile.user.email = form.cleaned_data["email"]
                        profile.user.save()
                    else:
                        # If send_email is false, the user does not want the reminder anymore.
                        email_reminder.delete()

                except EmailReminder.DoesNotExist:
                    # Create a email reminder
                    if form.cleaned_data["send_email"]:
                        EmailReminder.objects.create(
                            user=request.user,
                            action=action,
                            email_address=form.cleaned_data["email"],
                            send_at=action.event.event_date -
                            datetime.timedelta(
                                hours=int(form.cleaned_data["email_advance"])))

                        profile.user.email = form.cleaned_data["email"]
                        profile.user.save()

                try:
                    text_reminder = TextReminder.objects.get(user=request.user,
                                                             action=action)
                    if form.cleaned_data["send_text"]:
                        text_reminder.text_number = form.cleaned_data[
                            "text_number"]
                        text_reminder.text_carrier = form.cleaned_data[
                            "text_carrier"]
                        text_reminder.send_at = action.event.event_date - datetime.timedelta(
                            hours=int(form.cleaned_data["text_advance"]))
                        text_reminder.save()

                        profile.contact_text = form.cleaned_data["text_number"]
                        profile.contact_carrier = form.cleaned_data[
                            "text_carrier"]
                        profile.save()

                    else:
                        text_reminder.delete()

                except TextReminder.DoesNotExist:
                    if form.cleaned_data["send_text"]:
                        TextReminder.objects.create(
                            user=request.user,
                            action=action,
                            text_number=form.cleaned_data["text_number"],
                            text_carrier=form.cleaned_data["text_carrier"],
                            send_at=action.event.event_date -
                            datetime.timedelta(
                                hours=int(form.cleaned_data["text_advance"])),
                        )

                        profile.contact_text = form.cleaned_data["text_number"]
                        profile.contact_carrier = form.cleaned_data[
                            "text_carrier"]
                        profile.save()

                return HttpResponse(json.dumps({"success": True}),
                                    mimetype="application/json")

            template = render_to_string("reminder_form.html", {
                "reminders": {
                    "form": form
                },
                "action": action,
            })

            return HttpResponse(json.dumps({
                "success": False,
                "form": template,
            }),
                                mimetype="application/json")
    raise Http404
Esempio n. 17
0
def reminder(request, action_type, slug):
    """Handle the send reminder request."""
    _ = action_type
    if request.is_ajax():
        if request.method == "POST":
            profile = request.user.get_profile()
            action = smartgrid.get_action(slug=slug)
            form = ReminderForm(request.POST)
            if form.is_valid():

                # Try and retrieve the reminders.
                try:
                    email_reminder = EmailReminder.objects.get(user=request.user, action=action)
                    if form.cleaned_data["send_email"]:
                        email_reminder.email_address = form.cleaned_data["email"]
                        email_reminder.send_at = action.event.event_date - datetime.timedelta(
                            hours=int(form.cleaned_data["email_advance"])
                        )
                        email_reminder.save()

                        profile.user.email = form.cleaned_data["email"]
                        profile.user.save()
                    else:
                        # If send_email is false, the user does not want the reminder anymore.
                        email_reminder.delete()

                except EmailReminder.DoesNotExist:
                    # Create a email reminder
                    if form.cleaned_data["send_email"]:
                        EmailReminder.objects.create(
                            user=request.user,
                            action=action,
                            email_address=form.cleaned_data["email"],
                            send_at=action.event.event_date
                            - datetime.timedelta(hours=int(form.cleaned_data["email_advance"])),
                        )

                        profile.user.email = form.cleaned_data["email"]
                        profile.user.save()

                try:
                    text_reminder = TextReminder.objects.get(user=request.user, action=action)
                    if form.cleaned_data["send_text"]:
                        text_reminder.text_number = form.cleaned_data["text_number"]
                        text_reminder.text_carrier = form.cleaned_data["text_carrier"]
                        text_reminder.send_at = action.event.event_date - datetime.timedelta(
                            hours=int(form.cleaned_data["text_advance"])
                        )
                        text_reminder.save()

                        profile.contact_text = form.cleaned_data["text_number"]
                        profile.contact_carrier = form.cleaned_data["text_carrier"]
                        profile.save()

                    else:
                        text_reminder.delete()

                except TextReminder.DoesNotExist:
                    if form.cleaned_data["send_text"]:
                        TextReminder.objects.create(
                            user=request.user,
                            action=action,
                            text_number=form.cleaned_data["text_number"],
                            text_carrier=form.cleaned_data["text_carrier"],
                            send_at=action.event.event_date
                            - datetime.timedelta(hours=int(form.cleaned_data["text_advance"])),
                        )

                        profile.contact_text = form.cleaned_data["text_number"]
                        profile.contact_carrier = form.cleaned_data["text_carrier"]
                        profile.save()

                return HttpResponse(json.dumps({"success": True}), mimetype="application/json")

            template = render_to_string("reminder_form.html", {"reminders": {"form": form}, "action": action})

            return HttpResponse(json.dumps({"success": False, "form": template}), mimetype="application/json")
    raise Http404