Beispiel #1
0
    def update_user(self):
        cnds = self.navb.conditions()
        message = ''
        user = None
        #print "IDS: ",self.navb.kw, self.navb.kw.get('id') , self.navb.kw.get('pk')
        if self.navb.kw.get('id') or self.navb.kw.get('pk'):
            mkw = "%s" % self.navb.kw.get('id') or self.navb.kw.get('pk')
            cnds = {"indexcol = %s": mkw}
            user = Enduser.get_users(cnds)[0]

        if self.navb.kw.get("pk") and self.navb.kw.get(
                'nid') and self.navb.kw.get('telephone_moh'):
            cnds = {"indexcol = %s": self.navb.kw.get("pk")}
            indexcol = self.navb.kw.get('pk')
            nid = self.navb.kw.get('nid')
            phone = self.navb.kw.get('telephone_moh')
            formdata = {
                "indexcol": indexcol,
                "telephone": phone,
                "national_id": nid,
                "email": self.navb.kw.get('email'),
                "surname": self.navb.kw.get('surname'),
                "given_name": self.navb.kw.get('given_name'),
                "sex_pk": self.navb.kw.get('sex'),
                "role_pk": self.navb.kw.get('role'),
                "education_level_pk": self.navb.kw.get('edu_level'),
                "date_of_birth": self.navb.make_time(self.navb.kw.get('dob')),
                "join_date": self.navb.make_time(self.navb.kw.get('djoin')),
                "language_pk": self.navb.kw.get('language'),
                "nation_pk": self.navb.kw.get('user_nation'),
                "province_pk": self.navb.kw.get('user_province'),
                "district_pk": self.navb.kw.get('user_district'),
                "referral_facility_pk": self.navb.kw.get('user_hospital'),
                "facility_pk": self.navb.kw.get('user_facility'),
                "location_level_pk": self.navb.kw.get('user_area_level'),
                "sector_pk": self.navb.kw.get('user_sector'),
                "cell_pk": self.navb.kw.get('user_cell'),
                "village_pk": self.navb.kw.get('user_village'),
                "is_active": True,
                "is_correct": True
            }

            #print "\nFORM: ", formdata, "\n"
            message, user = Enduser.update_user(formdata)
            if user: user = Enduser.get_users(cnds)[0]
            self.navb.kw = {"id": self.navb.kw.get("pk")}

        sectors = self.navb.auth.auth_filter_locations("sec", user.district_pk)
        cells = self.navb.auth.auth_filter_locations("cel", user.sector_pk)
        villages = self.navb.auth.auth_filter_locations("vil", user.cell_pk)
        genders = Enduser.get_genders()
        roles = Enduser.get_roles()
        langs = Enduser.get_languages()
        education_levels = Enduser.get_education_levels()
        area_levels = Enduser.get_location_levels()
        #print user.__dict__
        return [
            sectors, cells, villages, genders, roles, education_levels,
            area_levels, langs, message, user
        ]
Beispiel #2
0
 def get_users(self):
     cnds = self.navb.conditions()
     if self.navb.kw.get('q'):
         mkw = "%%%s%%" % self.navb.kw.get('q')
         cnds = {"telephone LIKE %s OR national_id LIKE %s": (mkw, mkw)}
         print cnds
         return Enduser.get_users(cnds)
     return []
Beispiel #3
0
 def activate(self):
     cnds = self.navb.conditions()
     message = ''
     user = None
     action = self.navb.kw.get('action')
     try:
         status = True
         if action.strip() == 'deactivate': status = False
         user = Enduser.get_users({'indexcol = %s':
                                   self.navb.kw.get('id')})[0]
         data = {
             'telephone': user.telephone,
             'national_id': user.national_id,
             'is_active': status
         }
         ## TODO
         ## CHECK ALL USERS WITH TELEPHONE
         message, user = Enduser.update_user_info(data)
         if status == False:
             message = "User %s successfully deactivated." % user.surname
         else:
             message = "User %s successfully activated." % user.surname
     except Exception, e:
         pass