def comment_edit(request, activity_id, answer_id, comment_id, template="admin/comments/edit.html"): ok = verify(request) if ok != None: return ok answer = get_object_or_404(Answer, pk=int(answer_id)) try: activity = PlayerActivity.objects.untranslated().get(pk=int(activity_id)) except PlayerActivity.DoesNotExist: raise Http404 ("PlayerActivity with id %s does not exist" % activity_id) try: comment = Comment.objects.untranslated().get(pk=int(comment_id)) except Comment.DoesNotExist: raise Http404 ("Comment with id %s does not exist" % comment_id) #TODO: if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): # return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) form = AdminCommentForm(instance=comment, data=request.POST or None) if request.method == "POST" and form.is_valid(): comment_fun(form, request, is_new=False) return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) context = { 'activity': activity, 'answer': answer, 'comment_form': form, 'comment': comment, } return render_to_response(template, RequestContext(request, context))
def manage(request, activity_id, template="admin/manage_answers.html"): ok = verify(request) if ok != None: return ok try: activity = PlayerActivity.objects.untranslated().get(pk=int(activity_id)) except PlayerActivity.DoesNotExist: raise Http404 ("PlayerActivity with id %s does not exist" % activity_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) data = {} for answer in Answer.objects.filter(activity=activity): comments_data = {} for lang_code, _lang_name in settings.LANGUAGES: comments_data['%s_comments' % lang_code] = answer.comments.language(lang_code) # 'en-us' variable does not work in html template because of '-' comments_data['en_comments'] = answer.comments.language('en-us') data[answer] = comments_data comment_form = AdminCommentForm(data=request.POST or None) if request.method == "POST" and comment_form.is_valid(): comment_fun(comment_form, request) return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) context = { 'data' : data, 'activity': activity, 'comment_form': comment_form } return render_to_response(template, RequestContext(request, context))
def manage(request, instance_id, template="admin/manage_values.html"): ok = verify(request) if ok != None: return ok try: instance = Instance.objects.untranslated().get(pk=int(instance_id)) except Instance.DoesNotExist: raise Http404("Instance with id %s does not exist" % instance_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect( reverse("admin:manage-values", args=[instance_id])) data = {} for value in Value.objects.untranslated().filter(instance=instance): #Value.objects.untranslated().filter(instance=instance) data[value] = { 'value_translations': value.translations.all(), #'value_translations': trans_for_value(value), } context = { 'data': data, 'instance': instance, } return render_to_response(template, RequestContext(request, context))
def value(request, instance_id, value_id=None, template="admin/trans_value_edit_new.html"): is_new = False ok = verify(request) if ok != None: return ok log.debug("value_id: %s" % value_id) log.debug("instance_id: %s" % instance_id) try: instance = Instance.objects.untranslated().get(pk=int(instance_id)) except Instance.DoesNotExist: raise Http404("Instance with id %s does not exist" % instance_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect( reverse("admin:manage-values", args=[instance_id])) if value_id is not None and value_id != 'None': try: value = Value.objects.untranslated().get(pk=int(value_id)) except Value.DoesNotExist: raise Http404("value with id %s does not exist" % value_id) else: value = Value.objects.create(instance=instance, commit=False) is_new = True errors = {} form = ValueForm(instance=value, languages=instance.languages.all(), data=request.POST or None) if request.method == "POST": if form.is_valid(): try: value = form.save(commit=True) except Exception, err: #transaction.rollback() log.error("error while saving value: %s" % str(err)) errors.update({ "Updating value": "Server error took place. Please contact the admin." }) else: #transaction.commit() return HttpResponseRedirect( reverse("admin:manage-values", args=[instance_id])) else: for f in form.inner_trans_forms: if f.errors: errors.update(f.errors) if form.errors: errors.update(form.errors)
def instance(request, instance_id=None, template="admin/trans_instance_edit.html"): is_new = False ok = verify(request) if ok != None: return ok if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect(reverse("admin-base")) #FIXME # what is with this instance_id? # why is it 'None' coming from `new instance` form? if instance_id is not None and instance_id != 'None': try: inst = Instance.objects.untranslated().get(pk=instance_id) except Instance.DoesNotExist: raise Http404 ("instance with id %s does not exist" % instance_id) languages = inst.languages.all() else: inst = Instance.objects.create(start_date=datetime.datetime.now(), commit=False) is_new = True languages = Language.objects.all() init_coords = [] if inst.location: markers = simplejson.loads("%s" % inst.location)["markers"] x = 0 for coor in markers if markers != None else []: coor = coor["coordinates"] init_coords.append( [x, coor[0], coor[1]] ) x = x + 1 errors = {} instance_form = InstanceForm(instance=inst, languages=languages, data=request.POST or None) if request.method == "POST": if instance_form.is_valid(): try: instance = instance_form.save() instance.location = instance_form.cleaned_data["map"] instance.save() except Exception, err: #transaction.rollback() log.error("error while saving instance: %s" % str(err)) errors.update({"Updating instance": "Server error took place. Please contact the admin."}) else: #transaction.commit() return HttpResponseRedirect(reverse("admin:admin-base")) else: for f in instance_form.inner_trans_forms: if f.errors: errors.update(f.errors) if instance_form.errors: errors.update(instance_form.errors)
def mission(request, instance_id, mission_id=None, template="admin/trans_mission_edit_new.html"): is_new = False ok = verify(request) if ok != None: return ok try: instance = Instance.objects.untranslated().get(pk=int(instance_id)) except Instance.DoesNotExist: raise Http404("Instance with id %s does not exist" % instance_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect( reverse("admin:manage-missions", args=[instance_id])) if mission_id is not None and mission_id != 'None': try: mission = Mission.objects.untranslated().get(pk=int(mission_id)) except Mission.DoesNotExist: raise Http404("Mission with id %s does not exist" % mission_id) else: mission = Mission(instance=instance) is_new = True errors = {} form = MissionForm(instance=mission, languages=instance.languages.all(), data=request.POST or None) if request.method == "POST": if form.is_valid(): try: mission = form.save(commit=True) return HttpResponseRedirect( reverse("admin:manage-missions", args=[instance_id])) except Exception, err: #transaction.rollback() print "error while saving mission: %s" % str(err) log.error("error while saving mission: %s" % str(err)) errors.update({ "Updating mission": "Server error took place. Please contact the admin." }) else: for f in form.inner_trans_forms: if f.errors: errors.update(f.errors) if form.errors: errors.update(form.errors)
def delete(request, instance_id, template="admin/trans_instance_del.html"): log.debug('deleting instance %s' % instance_id) is_new = False ok = verify(request) if ok != None: return ok try: inst = Instance.objects.untranslated().get(pk=instance_id) except Instance.DoesNotExist: raise Http404 ("instance with id %s does not exist" % instance_id) if request.method == "POST" and request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Confirm Delete?": inst.delete() return HttpResponseRedirect(reverse("admin:admin-base")) context = { 'inst': inst, } log.debug('rendering %s' % template ) return render_to_response(template, RequestContext(request, context))
def manage(request, instance_id, template="admin/manage_missions.html"): ok = verify(request) if ok != None: return ok #TODO: Make the instances only be drawn from instances that the user supervises try: instance = Instance.objects.untranslated().get(pk=int(instance_id)) except Instance.DoesNotExist: raise Http404("Instance with id %s does not exist" % instance_id) data = [] for mission in Mission.objects.untranslated().filter( instance=instance).order_by('start_date'): data.append((mission, mission.translations.all())) context = { 'data': data, 'instance': instance, } return render_to_response(template, RequestContext(request, context))
def manage(request, template="admin/manage_game.html"): ok = verify(request) if ok != None: return ok #TODO: Make the instances only be drawn from instances that the user supervises if request.user.is_superuser: instances_all = Instance.objects.untranslated().all().order_by("start_date") else: instances_all = Instance.objects.untranslated().filter(curators=request.user).order_by("start_date") instances_data = {} for instance in instances_all: #Value.objects.untranslated().filter(instance=instance) instances_data[instance] = { 'instance_translations': instance.translations.all(), #'instance_translations': trans_for_instance(instance), } context = { 'instances_data' : instances_data, } return render_to_response(template, RequestContext(request, context))
def answer(request, activity_id, answer_id=None, template="admin/trans_answer_edit.html"): is_new = False ok = verify(request) if ok != None: return ok try: activity = PlayerActivity.objects.untranslated().get(pk=int(activity_id)) except PlayerActivity.DoesNotExist: raise Http404 ("PlayerActivity with id %s does not exist" % activity_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) if answer_id is not None and answer_id != 'None': answer = get_object_or_404(Answer, pk=int(answer_id)) else: answer = Answer(activity=activity) is_new = True errors = {} form = AnswerForm(instance=answer, data=request.POST or None) if request.method == "POST": if form.is_valid(): try: answer = form.save(commit=False) answer.activity = activity answer.save() return HttpResponseRedirect(reverse("admin:manage-answers", args=[activity_id])) except Exception, err: #transaction.rollback() print "error while saving answer: %s" % str(err) log.error("error while saving answer: %s" % str(err)) errors.update({"Updating mission": "Server error took place. Please contact the admin."}) else: if form.errors: errors.update(form.errors)
def manage(request, mission_id, template="admin/manage_activities.html"): ok = verify(request) if ok != None: return ok try: mission = Mission.objects.untranslated().get(pk=int(mission_id)) except Mission.DoesNotExist: raise Http404("Mission with id %s does not exist" % mission_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect( reverse("admin:manage-activities", args=[mission_id])) data = {} for activity in PlayerActivity.objects.untranslated().filter( mission=mission): data[activity] = { 'activity_translations': activity.translations.all(), } context = {'data': data, 'instance': mission.instance, 'mission': mission} return render_to_response(template, RequestContext(request, context))
def activity(request, mission_id, activity_id=None, template="admin/trans_activity_edit_new.html"): is_new = False ok = verify(request) if ok != None: return ok try: mission = Mission.objects.untranslated().get(pk=int(mission_id)) except Mission.DoesNotExist: raise Http404("Mission with id %s does not exist" % mission_id) if (request.POST.has_key("submit_btn") and request.POST["submit_btn"] == "Cancel"): return HttpResponseRedirect( reverse("admin:manage-activities", args=[mission_id])) if activity_id is not None and activity_id != 'None': try: activity = PlayerActivity.objects.untranslated().get( pk=int(activity_id)) except Activity.DoesNotExist: raise Http404("Player Activity with id %s does not exist" % activity_id) else: activity = PlayerActivity.objects.create( creationUser=request.user, mission=mission, type=PlayerActivityType.objects.get(type='single_response'), commit=False) is_new = True errors = {} form = ActivityForm(instance=activity, languages=mission.instance.languages.all(), data=request.POST or None) if request.method == "POST": if form.is_valid(): try: activity = form.save(commit=False) except Exception, err: #transaction.rollback() print "error while saving activity: %s" % str(err) log.error("error while saving activity: %s" % str(err)) errors.update({ "Updating activity": "Server error took place. Please contact the admin." }) else: #transaction.commit() return HttpResponseRedirect( reverse("admin:manage-activities", args=[mission_id])) else: for f in form.inner_trans_forms: if f.errors: errors.update(f.errors) if form.errors: errors.update(form.errors)