Exemplo n.º 1
0
 def locations(self):
     locations = []
     for location_id in self.location_ids:
         location = cache.get(LOCATION_CACHE_KEY % location_id, False)
         if not location:
             location = Location.get_location_or_unknown(id=location_id)
             cache.set(LOCATION_CACHE_KEY % location_id, location, LOCATION_CACHE_TIME)
         locations.append(location)
     return locations
Exemplo n.º 2
0
def create_website_event(request):
    if request.method == 'POST':
        form = WebsiteEventForm(request.POST)
        if form.is_valid():
            website = form.cleaned_data['website']
            first_detection = form.cleaned_data['first_detection']
            event_type = form.cleaned_data['event_type']
            location = Location.retrieve_location(form.cleaned_data['location'].split(', ')[0])

            logging.info(location)

            event = Event()
            event.active = True
            if first_detection:
                event.first_detection_utc = first_detection
            else:
                event.first_detection_utc = datetime.datetime.now()
            event.last_detection_utc  = datetime.datetime.now()
            event.target = website
            event.target_type = TargetType.Website
            if event_type:
                # 'censor', 'throttling', 'offline'
                if event_type == 'censor':
                    event.event_type = EventType.Censor
                elif event_type == 'throttling':
                    event.event_type = EventType.Throttling
                else:
                    event.event_type = EventType.Offline
            else:
                event.event_type = EventType.Offline

            logging.info(location)

            if location!=None:
                event.location_ids.append(location.id)
                event.location_names.append(location.fullname)
                event.location_country_names.append(location.country_name)
                event.location_country_codes.append(location.country_code)
                event.lats.append(location.lat)
                event.lons.append(location.lon)
                event.isps.append('')

            event.save()
            NotificationSystem.publishEvent(event)

            return HttpResponse(json.dumps(dict(status='OK',
                       msg='Website event added successfully!',
                       errors=None)))
        else:
            return HttpResponse(json.dumps(dict(status='FAILED',
                    msg='Failed to add event.',
                    errors=form.errors)))
    
    form = WebsiteEventForm()
    return render_to_response('gui/create_website_event.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 3
0
 def location(self):
     if self.location_id is not None:
         return Location.get_location_or_unknown(id=self.location_id)
Exemplo n.º 4
0
 def location(self):
     return Location.get_location_or_unknown(self.location_id)
Exemplo n.º 5
0
 def location(self):
     """The location of the reporting node"""
     return Location.get_location_or_unknown(self.location_id)
Exemplo n.º 6
0
 def location(self):
     if not self.location_id:
         return None
     else:
         return Location.get_location_or_unknown(id=self.location_id)