Beispiel #1
0
 def post(self):
     req = self.request
     data = populate_user()
     if not data['logged_in']:
         return self.redirect('/')
     user_id = data['nickname']
     stream_name = req.get('name')
     stream_tags = req.get('tags').split(',')
     stream_cover = req.get('cover') or DEFAULT_COVER
     stream_add_subscribers_email_list = req.get('email_list').split(',')
     stream_email_body = req.get('email_body')
     if not stream_name or Stream.get_by_id(stream_name):
         data['msg'] = 'Sorry! Stream already exists/Name empty.'
         template = JINJA_ENVIRONMENT.get_template('error.html')
         return self.response.write(template.render(data))
     stream = Stream(id=stream_name,
                     tags=stream_tags,
                     cover_url=stream_cover).put()
     user = User.get_by_id(user_id)
     user.owned_ids.append(stream)
     user.put()
     # on successful insert, send email
     if (Stream.get_by_id(stream_name)):
         send_subscribtion_invite_email(stream_add_subscribers_email_list,
                                        stream_email_body, stream_name,
                                        self.request.url)
     return self.redirect('/manage')
Beispiel #2
0
    def post(self):
        # We set the same parent key on the 'Greeting' to ensure each
        # Greeting is in the same entity group. Queries across the
        # single entity group will be consistent. However, the write
        # rate to a single entity group should be limited to
        # ~1/second.
        name = self.request.get('name')
        stream = Stream(name=name,
                        created_by_user_id=users.get_current_user().user_id())
        stream.put()

        self.response.out.write("ok")
Beispiel #3
0
 def post(self):
     user = users.get_current_user()
     if not user:
         self.login_page()
     else:
         name = self.request.get('name')
         message = self.request.get('message')
         key = ndb.Key('Stream', name)
         stream = key.get()
         if stream:
             self.template(
                 'views/error.html',
                 error='Error: you tried to create a new stream ' +
                 'whose name is the same as an existing ' +
                 'stream; operation did not complete')
         else:
             subscribers = filter(
                 lambda s: s != '',
                 map(
                     unicode.lower,
                     map(unicode.strip,
                         self.request.get('subscribers').split(','))))
             message = self.request.get('message')
             tags = filter(
                 lambda t: t != '',
                 map(unicode.strip,
                     self.request.get('tags').split(',')))
             cover_image_url = self.request.get('cover_image_url')
             cover_image_url = cover_image_url if cover_image_url \
                 else 'http://placehold.it/190x190.png'
             stream = Stream(id=name,
                             name=name,
                             owner=user.email().lower(),
                             subscribers=subscribers,
                             tags=tags,
                             cover_image_url=cover_image_url,
                             images=[])
             body = ('You are now subscribed to the %s stream:\n' +
                     'http://mh33338-connexus.appspot.com/view?' +
                     'stream_name=%s&increment=1\n%s' % (name, message))
             sender_address = 'Matthew Halpern <*****@*****.**>'
             subject = '[mh33338-conexus] Subscription to %s Stream' % name
             stream.put()
             for subscriber in subscribers:
                 mail.send_mail(sender_address, subscriber, subject, body)
             self.redirect('/manage')
Beispiel #4
0
def create_stream(pigeon_id, name, cover_url, sub_list, tag_list):
    pigeon_key = ndb.Key(Pigeon, pigeon_id)
    stream = Stream()
    stream.key = ndb.Key(Stream, name, parent=pigeon_key)
    stream.name = name
    stream.cover_url = cover_url
    stream.tags = tag_list
    stream.put()
    for pid in sub_list:
        if pid != pigeon_id:
            if not pigeon_exists(pid):
                create_pigeon(pid)
            suber_key = ndb.Key(Pigeon, pid)
            sub = Subscription()
            sub.Pigeon_key = suber_key
            sub.Stream_key = stream.key
            sub.put()
    return
Beispiel #5
0
    product = clean(record.get('product'))
    hash = clean(record.get('hash'))
    ip = clean(record.get('ip'))
    org = clean(record.get('org'))
    data = clean(record.get('data'))
    port = clean(record.get('port'))
    transport = clean(record.get('transport'))
    isp = clean(record.get('isp'))
    timestamp = clean(record.get('timestamp'))
    ip_str = clean(record.get('ip_str'))

    s = Stream(product=product,
               hash=hash,
               ip=ip,
               org=org,
               data=data,
               port=port,
               transport=transport,
               isp=isp,
               timestamp=timestamp,
               ip_str=ip_str)

    session.add(s)

    try:
        session.commit()
    except Exception as e:
        logging.exception(e)
        continue

    # location
    location = clean(record.get('location'))
Beispiel #6
0
def event_details(request, event_id=None):
    # Set a detail/attribute
    if request.method == "POST":
        try:
            event = Event.objects.get(pk=event_id)
            data = json.loads(request.read())

            payload = {
                "event_id": event.id,
                "details": [],
            }

            for detail in data["details"]:
                details_type = detail["details_type"]
                key = detail["name"]
                value = detail["value"]
                mode = detail["mode"]

                if details_type == "attribute":
                    attributes = Attribute.objects.filter(event=event, key=key)
                    if not attributes or mode == "append":
                        attribute = Attribute(event=event, key=key, value=value)
                        attribute.save()
                    elif mode == "set":
                        for attribute in attributes[1:]:
                            attribute.delete()
                        attribute = attributes[0]
                        attribute.value = value
                        attribute.save()

                elif details_type == "stream":
                    stream = Stream.objects.filter(event=event, name=key)
                    if stream:
                        stream = stream.get()
                        stream_text = value
                        if mode == "append":
                            stream_text = stream.text + stream_text
                        stream.text = stream_text
                    else:
                        stream = Stream(event=event, name=key, text=value)
                    stream.save()

                payload["details"].append(detail)

            publish("event_details", "update", payload, event_id=event.id)
            return json_response({"msg": ""})

        except IntegrityError as err:
            return json_response({"msg": str(err)}, "error", 400)
        except DatabaseError as err:
            return json_response({"msg": str(err)}, "error", 500)


    # Get Details for an event
    if request.method == "GET":
        try:
            data = {}
            event = Event.objects.get(pk=event_id)
            data["event_id"] = event.id
            data["attributes"] = event.attributes()
            data["streams"] = [stream.to_dict() for stream in event.streams()]
            return json_response(data)
        except Event.DoesNotExist as err:
            return json_response({"msg": str(err)}, "error", 404)