示例#1
0
    def handle(self, *args, **options):
        if not len(args):
            user = User.objects(username='******').first() or User(
                username='******').save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password('password')
            location = Location.objects(type='district').first() or Location(
                name='Kampala', type='district').save()
            profile = UserProfile.objects(phone='N/A').first() or UserProfile(
                phone='N/A',
                name='Admin',
                location=location,
                email='*****@*****.**').save()
            profile.user = user
            profile.save()
        else:
            user = User.objects(username=args[0]).first() or User(
                username=args[0]).save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password(args[1])
            location = Location.objects(name=args[4]).first() or Location(
                name=args[4], type='district').save()
            profile = UserProfile.objects(
                phone=args[5]).first() or UserProfile(
                    phone=args[5],
                    name=args[3],
                    location=location,
                    email=args[2]).save().save()
            profile.user = user
            profile.save()

        self.stdout.write('Successfully created superuser')
示例#2
0
 def find_location_match(cls, location_name, **kwargs):
     for location in Location.objects(**kwargs):
         ratio = Levenshtein.ratio(
             str(location.name).lower(),
             str(location_name).lower())
         if ratio >= settings.LOCATION_MATCH_LEVEL:
             return location
示例#3
0
 def set_locations(self):
     if self.location_name:
         location = Location.objects.filter(
             name__iexact=self.location_name).first()
         if location:
             return location.children()
     return Location.objects(parent=None)
示例#4
0
 def _insert_location(self, request):
     data = request.DATA
     params = {}
     for i, dt in enumerate(data):
         sub_name = dt.get('subcounty', None)
         dist_name = dt.get('district', None)
         try:
             if sub_name and dist_name:
                 parent = Location.objects(name=dist_name, type='district').first()
                 params = dict(name=sub_name, type='subcounty', parent=parent)
                 self.discard_loc_aliases(request.DATA[i])
             elif dist_name:
                 params = dict(name=dist_name, type='district')
                 self.discard_loc_aliases(request.DATA[i])
             elif sub_name:
                 params = dict(name=sub_name, type='subcounty')
                 self.discard_loc_aliases(request.DATA[i])
             else:
                 # print 'no district and subcounty specified for record: %s' % request.DATA[i]
                 continue
             request.DATA[i]['location'] = Location.objects.get(**params)
         except Exception as e:
             # print '%s: something wrong with district name [%s] or subcounty name [%s] \
             # specified for record' % (e.__class__.__name__, dist_name, sub_name)
             continue
     return request
示例#5
0
 def _filter_params(self, req):
     location = req.GET.get('location')
     params = {}
     locations = []
     if location and not self._undefined(location):
         locs = location.split(',')
         for loc in locs:
             locations += Location.objects(**dict(id=loc)).first().children(include_self=True)
         params = {'location__in': locations}
     return params
示例#6
0
    def handle(self, *args, **options):
        if not len(args):
            user = User.objects(username='******').first() or User(username='******').save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password('password')
            location = Location.objects(type='district').first() or Location(name='Kampala', type='district').save()
            profile = UserProfile.objects(phone='N/A').first() or UserProfile(phone='N/A', name='Admin', location=location, email='*****@*****.**').save()
            profile.user = user
            profile.save()
        else:
            user = User.objects(username=args[0]).first() or User(username=args[0]).save()
            user.group = Group.objects(name='Administrator').first()
            user.set_password(args[1])
            location = Location.objects(name=args[4]).first() or Location(name=args[4], type='district').save()
            profile = UserProfile.objects(phone=args[5]).first() or UserProfile(phone=args[5], name=args[3], location=location, email=args[2]).save().save()
            profile.user = user
            profile.save()

        self.stdout.write('Successfully created superuser')
示例#7
0
 def number_of_participants(self):
     locations = self.target_locations
     users = 0
     for loc in locations:
         locObj = Location.objects(id=loc).first()
         if locObj.parent == None:
             locs = locObj.full_tree()
             for l in locs:
                 users += len(UserProfile.objects(location=l).distinct('phone'))
         else:
             users += len(UserProfile.objects(location=locObj).distinct('phone'))
     return users
示例#8
0
 def number_of_participants(self):
     locations = self.target_locations
     users = 0
     for loc in locations:
         locObj = Location.objects(id=loc).first()
         if locObj.parent == None:
             locs = locObj.full_tree()
             for l in locs:
                 users += len(
                     UserProfile.objects(location=l).distinct('phone'))
         else:
             users += len(
                 UserProfile.objects(location=locObj).distinct('phone'))
     return users
示例#9
0
    def get_queryset(self):
        queryset = self._non_location_queried_messages()
        location_queried = self.request.GET.get('location', None)

        if not location_queried:
            if self.request.user.has_perm('dms.can_view_messages') and \
                    not self.request.user.has_perm('dms.can_manage_messages'):
                user_profile = UserProfile.objects(user=self.request.user).first()
                if user_profile:
                    location_queried = user_profile.location.id

        if location_queried:
            location = Location.objects(id=location_queried).first()
            queryset = RapidProMessage.from_(location, _queryset=queryset)

        disaster_type = self.request.GET.get('disaster_type', None)
        if disaster_type:
            queryset = self.query_by_disaster_type(disaster_type, queryset)

        return queryset.order_by('-received_at')
示例#10
0
    def get_queryset(self):
        queryset = self._non_location_queried_messages()
        location_queried = self.request.GET.get('location', None)

        if not location_queried:
            if self.request.user.has_perm('dms.can_view_messages') and \
                    not self.request.user.has_perm('dms.can_manage_messages'):
                user_profile = UserProfile.objects(
                    user=self.request.user).first()
                if user_profile:
                    location_queried = user_profile.location.id

        if location_queried:
            location = Location.objects(id=location_queried).first()
            queryset = RapidProMessage.from_(location, _queryset=queryset)

        disaster_type = self.request.GET.get('disaster_type', None)
        if disaster_type:
            queryset = self.query_by_disaster_type(disaster_type, queryset)

        return queryset.order_by('-received_at')
示例#11
0
 def find_location_match(cls, location_name, **kwargs):
     for location in Location.objects(**kwargs):
         ratio = Levenshtein.ratio(str(location.name).lower(), str(location_name).lower())
         if ratio >= settings.LOCATION_MATCH_LEVEL:
             return location
 def get_location(self, kwargs):
     location_name = kwargs.get('subcounty') or kwargs.get('district') or kwargs.get('location')
     if location_name:
         return Location.objects(name__iexact=location_name.lower()).first()
示例#13
0
 def get_location(self, kwargs):
     location_name = kwargs.get('subcounty') or kwargs.get(
         'district') or kwargs.get('location')
     if location_name:
         return Location.objects(name__iexact=location_name.lower()).first()
示例#14
0
 def get_location(self, obj):
     locations = Location.objects(id__in=obj.target_locations)
     if locations.filter(type='subcounty'):
         return locations
     districts_children = [district.children() for district in locations]
     return flatten(districts_children)
示例#15
0
 def get_location(self, obj):
     locations = Location.objects(id__in=obj.target_locations)
     if locations.filter(type='subcounty'):
         return locations
     districts_children = [district.children() for district in locations]
     return flatten(districts_children)
示例#16
0
 def set_locations(self):
     if self.location_name:
         location = Location.objects.filter(name__iexact=self.location_name).first()
         if location:
             return location.children()
     return Location.objects(parent=None)