def officials (request):
    if request.method == 'GET':
        return render_to_response ('officials.html',
                                   {'menus' : get_user_menus (request.user,process_dm),
                                    'user' : request.user})
    else:
        return render_to_response ('error.html',
                                   {'error': 'No other method is supported',
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user' : request.user})
def adddep(request):
    if request.method=="GET":
        return render_to_response ('add_dep.html',
                                   {'trial' : AddDep (),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user' : request.user})
    elif request.method == "POST":
        form = AddDep(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect( reverse(department) )
        else:
            return render_to_response ('add_dep.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user'  : request.user})
def addcomp(request):
    if request.method=="GET":
        return render_to_response ('add_comp_type.html',
                                   {'trial' : AddComplaint (),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user' : request.user})
    elif request.method == "POST":
        form = AddComplaint(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect( reverse(complainttype) )
        else:
            return render_to_response ('add_comp_type.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user'  : request.user})
def editdep (request, depcode):
    if request.method == "POST":
        form = EditDep(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (department))
        else:
            return render_to_response ('edit_dep.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        dept = ComplaintDepartment.objects.get (code = depcode)
        return render_to_response ('edit_dep.html',
                                   {'trial' : EditDep (depobj = dept),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user'  : request.user})
def add_official (request):
    cmhuser_dm = CmhUser.objects.filter (user__approle__role = UserRoles.DM)
    if request.method == 'GET':
        if cmhuser_dm.count () == 0:
            return render_to_response ('error.html',
                                       {'error' : 'District Magistrate must be registered',
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
        elif cmhuser_dm.count () > 1:
            return render_to_response ('error.html',
                                       {'error' : 'Multiple DMs defined [%d]',
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
        else:
            departments = ComplaintDepartment.objects.all ()
            return render_to_response ('add_official.html',
                                          {'menus' : get_user_menus (request.user,process_dm),
                                           'user' : request.user,
                                           'form' : AddEditOfficial (departments = departments)})
    elif request.method == 'POST':
        if 'add_add_official' in request.POST:
            supervisors = None
            if 'pos_supervisors' in request.session:
                supervisors = json.loads (request.session ['pos_supervisors'])

            departments = ComplaintDepartment.objects.all ()
            form = AddEditOfficial (request.POST,
                                    departments = departments,
                                    supervisors = supervisors)

            if form.is_valid ():
                form.save ()
                return HttpResponseRedirect (reverse (officials))
            else:
                return render_to_response ('add_official.html',
                                           {'menus' : get_user_menus (request.user,process_dm),
                                            'user' : request.user,
                                            'form' : form})
        elif 'add_cancel_official' in request.POST:
            return HttpResponseRedirect (reverse (officials))
        else:
            return HttpResponseRedirect (reverse (officials))

    else:
        return HttpResponseRedirect (reverse (officials))
def add_district(request):
    if request.method =="GET":
        return render_to_response ('edit_district.html',
                                   {'trial' : AddDistrict (),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'flag'  : True,
                                    'user' : request.user})
    elif request.method == "POST":
        form = AddDistrict(request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (district))
        else:
            return render_to_response ('edit_district.html',
                                   {'trial' : form,
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'flag'  : True,
                                    'user' : request.user})
def editc (request, compcode, depcode):
    if request.method == "POST":
        form = EditComp(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (complainttype))
        else:
            return render_to_response ('edit_comp_type.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        ccode = "%s.%s" %(depcode,compcode)
        comp = ComplaintType.objects.get (code = ccode)
        return render_to_response ('edit_comp_type.html',
                                   {'trial' : EditComp (compobj = comp),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user'  : request.user})
def editblk (request, blkcode):
    if request.method == "POST":
        form = EditBlk(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (block))
        else:
            return render_to_response ('edit_block.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        bcode = DeployDistrict.DISTRICT.code + "." + blkcode
        blk = Block.objects.get (code = bcode)
        return render_to_response ('edit_block.html',
                                   {'trial' : EditBlk (blkobj = blk),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user'  : request.user})
def editgp (request, block, gpcode):
    if request.method == "POST":
        form = EditGp(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (gp))
        else:
            return render_to_response ('edit_gp.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        gpcode = DeployDistrict.DISTRICT.code + "." + block + "." + gpcode
        gramp = GramPanchayat.objects.get (code = gpcode)
        return render_to_response ('edit_gp.html',
                                   {'trial' : EditGp (gpobj = gramp),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user'  : request.user})
def editvill (request, block, gpcode, villcode):
    if request.method == "POST":
        form = EditVillage(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (village))

        else:
            return render_to_response ('edit_village.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        villcode = DeployDistrict.DISTRICT.code +"." + block + "." + gpcode + "." + villcode
        vilage = Village.objects.get(code = villcode)
        return render_to_response ('edit_village.html',
                                   {'trial' : EditVillage (villobj = vilage),
                                    'menus' : get_user_menus (request.user,process_dm),
                                    'user'  : request.user})
Exemple #11
0
def dologin (request):
    form = UserLoginForm ()
    if request.method == 'POST':
        form = UserLoginForm (request.POST)
        if form.is_valid ():
            login (request, form.valid_user)
            request.session.set_expiry (0)
            return HttpResponseRedirect (settings.LOGIN_REDIRECT_URL)
    return render_to_response ('login.html',
                               {'form': form,
                                'menus' : get_user_menus (request.user, dologin),
                                'user' : request.user})
def add_cso_user (request):
    if request.method == 'GET':
        return render_to_response ('add_cso_member.html',
                                   {'menus' : get_user_menus (request.user,add_cso_user),
                                    'user' : request.user,
                                    'form' : AddCSOMember ()})
    elif request.method == 'POST':
        form = AddCSOMember (request.POST)
        if 'add' in request.POST:
            if form.is_valid ():
                form.save ()
                return HttpResponseRedirect (reverse (csomembers))
            else:
                return render_to_response ('add_cso_member.html',
                                           {'menus' : get_user_menus (request.user,add_cso_user),
                                            'user' : request.user,
                                            'form' : form})
        else:
            return HttpResponseRedirect (reverse (csomembers))
    else:
        return HttpResponseRedirect ("/")
def edit_cso(request, csoid):
    if request.method == "POST":
        form = EditCso(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (csomembers))
        else:
            return render_to_response ('edit_cso.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        cso = CmhUser.objects.get (id = csoid)

        if (cso.get_user_role () != UserRoles.ROLE_CSO):
            raise Exception(_("Wrong data passed! The data passed doesnot belong to any cso Please go back and click again"))
        else:
            return render_to_response ('edit_cso.html',
                                       {'trial' : EditCso (csoobj = cso ),
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user'  : request.user})
def village (request) :
    dname = DeployDistrict.DISTRICT.name
    dcode = DeployDistrict.DISTRICT.get_code ()
    scode = DeployDistrict.DISTRICT.state.get_code ()
    sname = DeployDistrict.DISTRICT.state.name
    return render_to_response ('view_village.html',
                               {'disname'  : dname,
                                'discode'  : dcode,
                                'statecode': scode,
                                'statename': sname,
                                'menus'    : get_user_menus (request.user,process_dm),
                                'user'     : request.user})
def edit_off(request, offid):
    if request.method == "POST":
        form = EditOfficial(None, request.POST)
        if form.is_valid() :
            form.save()
            return HttpResponseRedirect (reverse (officials))
        else:
            return render_to_response ('edit_official.html',
                                       {'trial' : form,
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    else:
        off = CmhUser.objects.get (id = offid)

        if (off.get_user_role () != UserRoles.ROLE_OFFICIAL and
            off.get_user_role () != UserRoles.ROLE_DELEGATE):
            raise Exception(_("Wrong data passed! The data passed doesnot belong to any official Please go back and click again"))
        else:
            return render_to_response ('edit_official.html',
                                       {'trial' : EditOfficial (offobj = off ),
                                        'menus' : get_user_menus (request.user,process_dm),
                                        'user'  : request.user})
Exemple #16
0
def index (request):
    if request.method == 'GET':
        deps = set()
        [deps.add(complaint.department) for complaint in ComplaintType.objects.all()]
        departments = list(deps)
        request.session ['blkids']  = ""
        request.session ['villids'] = ""
        request.session ['gpids']   = ""
        request.session ['depids']  = ""
        init_lattd = DeployDistrict.DISTRICT.lattd
        init_longd = DeployDistrict.DISTRICT.longd
        return render_to_response ('index.html',
                                   {'menus' : get_user_menus (request.user,index),
                                    'user'  : request.user,
                                    'form'  : DateIndex(),
                                    'map'   : {'center_lat' : init_lattd,
                                               'center_long' : init_longd},
                                    'departments' : departments})
    else:
        return HttpResponseRedirect ('/')
def masters (request):
    # Ensure CmhUser model instance exists for all User's
    for user in User.objects.filter (cmhuser = None):
        cmhuser = CmhUser.objects.create (user = user)

    cmhusers = CmhUser.objects.all ()

    paginator = Paginator (cmhusers, 10)

    try:
        page = int (request.GET.get ('page', '1'))
    except ValueError:
        page = 1

    try:
        cmhusers = paginator.page (page)
    except (EmptyPage, InvalidPage):
        cmhusers = paginator.page (paginator.num_pages)

    return render_to_response ("masters.html",
                               {'menus' : get_user_menus (request.user,masters),
                                'cmhusers' : cmhusers,
                                'user' : request.user})
def department (request) :
    return render_to_response ('view_dep.html',
                               {'menus'    : get_user_menus (request.user,process_dm),
                                'user'     : request.user})
Exemple #19
0
def gotomyprofile (request):
    if request.method=="GET":
        cmhuser = request.user.cmhuser
        return render_to_response('profile.html',
                                {'obj' : cmhuser,
                                 'menus' : get_user_menus (request.user,gotomyprofile),
                                 'user' : request.user})
    elif request.method=="POST":
        if 'edit' in request.POST:
            cmhuser = request.user.cmhuser
            return render_to_response('edit.html',
                                      {'menus'  : get_user_menus (request.user,gotomyprofile),
                                       'user'   : request.user,
                                       'form'   : ProfileEditForm (),
                                       'obj'    : cmhuser})
        elif 'savechanges' in request.POST:
            form = ProfileEditForm (request.POST)
            if form.is_valid ():
                user    = request.user
                cmhuser = user.cmhuser

                user.first_name = request.POST ['name']
                user.save ()

                cmhuser.phone = request.POST['phone']
                cmhuser.save()

                return HttpResponseRedirect (reverse (gotomyprofile))
            else:
                cmhuser = request.user.cmhuser
                return render_to_response('edit.html',
                                          {'obj'   : form,
                                           'menus' : get_user_menus (request.user,gotomyprofile),
                                           'user'  : request.user})

        elif 'reset' in request.POST:
            return render_to_response ('reset_password.html',
                                       {'form' : PasswordUpdateForm (request.user),
                                        'menus': get_user_menus (request.user,gotomyprofile),
                                        'user'  : request.user}
                                        )
        elif 'set_password' in request.POST:
            try:
                form = PasswordUpdateForm (request.user,
                                           request.POST)
                if form.is_valid ():
                    form.save ()
                    return render_to_response ('password_reset_success.html',
                                               {'menus': get_user_menus (request.user,gotomyprofile),
                                                'user'  : request.user})

                else:
                    debug ("Form is not valid" + str (form.errors))
                    return render_to_response ('reset_password.html',
                                               {'form' : form,
                                                'menus': get_user_menus (request.user,gotomyprofile),
                                                'user'  : request.user})
            except:
                import traceback
                traceback.print_exc ()
        elif 'cancel' in request.POST:
            return HttpResponseRedirect (reverse (gotomyprofile))
def state (request) :
    stateobj=State.objects.all()
    return render_to_response ('view_state.html',
                               {'states':stateobj,
                                'menus' : get_user_menus (request.user,process_dm),
                                'user' : request.user})
def district (request) :
    distobj=District.objects.all()
    return render_to_response ('view_district.html',
                               {'districts':distobj,
                                'menus' : get_user_menus (request.user,process_dm),
                                'user' : request.user})
def process_dm (request):
    cmhuser_dm = CmhUser.objects.filter (user__approle__role = UserRoles.DM)
    if request.method == 'GET':
        if cmhuser_dm.count () == 0:
            return render_to_response ('create_dm.html',
                                       {'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user,
                                        'form' : RegisterDM ()})
        elif cmhuser_dm.count () == 1:
            return render_to_response ('view_dm.html',
                                       {'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user,
                                        'dm' : cmhuser_dm [0]})
        else:
            return render_to_response ('error_dm_count.html',
                                       {'menus' : get_user_menus (request.user,process_dm),
                                        'user' : request.user})
    elif request.method == 'POST':
        if 'register' in request.POST: # Registering a new DM
            form = RegisterDM (request.POST)
            if form.is_valid ():
                dm = form.save ()
                return render_to_response ('view_dm.html',
                                           {'menus' : get_user_menus (request.user,process_dm),
                                            'user' : request.user,
                                            'dm' : dm})
            else:
                return render_to_response ('create_dm.html',
                                           {'menus' : get_user_menus (request.user,process_dm),
                                            'user' : request.user,
                                            'form' : form})
        elif 'cancel' in request.POST: # Cancel DM registration
            return HttpResponseRedirect (reverse (masters))
        elif 'edit_dm' in request.POST: # Edit DM record
            form = DmId (request.POST)
            if form.is_valid ():
                dmid = form.cleaned_data ['dmid']
                try:
                    dm = CmhUser.objects.get (user__approle__role = UserRoles.DM,
                                              id = dmid)
                    formdata = {'dmid' : dm.id,
                                'username' : dm.user.username,
                                'name' : dm.user.get_full_name (),
                                'phone' : dm.phone}
                    form = EditDM (formdata)
                    return render_to_response ('edit_dm.html',
                                               {'menus':get_user_menus(request.user,process_dm),
                                                'user' : request.user,
                                                'form' : form})
                except CmhUser.DoesNotExist, CmhUser.MultipleObjectsReturned:
                    return HttpResponse (reverse (masters))
        elif 'edit_save' in request.POST:
            debug ("Saving a DM object")
            form = EditDM (request.POST)
            if form.is_valid ():
                form.save ()
                return HttpResponseRedirect (reverse (process_dm))
            else:
                debug ("Invalid form:" , form.errors)
                return render_to_response ('edit_dm.html',
                                           {'menus': get_user_menus(request.user,process_dm),
                                            'user' : request.user,
                                            'form' : form})
        elif 'edit_cancel' in request.POST:
            return HttpResponseRedirect (reverse (process_dm))
        else:
            return HttpResponseRedirect (reverse (masters))
def sms_logs_report(request):
    return render_to_response('report_generic.html', {'cols': sms_logs_column_properties, 'def_sort_column': 0, 'data_url': reverse(sms_logs_data), 'menus': get_user_menus(request.user, sms_logs_report)}, context_instance = RequestContext(request))
def my_issues(request):
    return render_to_response('report_generic.html', {'cols': all_issues_column_properties, 'def_sort_column': 2, 'data_url': reverse(my_issues_data), 'menus': get_user_menus(request.user, my_issues)}, context_instance = RequestContext(request))
def complainttype(request) :
    return render_to_response ('view_comp_type.html',
                               {'menus'    : get_user_menus (request.user,process_dm),
                                'user'     : request.user})
def csomembers (request):
    return render_to_response ("cso_master.html",
                               {'menus' : get_user_menus (request.user,csomembers),
                                'user' : request.user})