Пример #1
0
    def get(self):
        is_json = self.content_type("application/json")
        postal = self.get_argument("postal", json=is_json)
        lookup = self.get_argument("lookup", None, json=is_json)

        address = Address(postal, None, lookup)
        address.geocode()

        self.write_json(address.obj(public=bool(self.current_user)))
Пример #2
0
def new_user_reg():

    email = request.form.get("email")
    password = request.form.get("password")
    password_ver = request.form.get("password_ver")
    firstname = request.form.get("firstname")
    surname = request.form.get("surname")
    address1 = request.form.get("address1")
    address2 = request.form.get("address2")
    city = request.form.get("city")
    state = request.form.get("state")
    zipcode = int(request.form.get("zipcode")) if request.form.get("zipcode") else None
    country = request.form.get("country")
    phone = int(request.form.get("phone")) if request.form.get("phone") else None
    
#Verification if user already exists
    existing = User.query.filter_by(email=email).first()

    if existing:
        flash("This email already exists,Please select another one!")
        return redirect(url_for("new_user_reg")) #redirect back to sign up page
    elif password != password_ver:
        flash("Your password do not match")
        return redirect(url_for("new_user_reg")) #redirect back to sign up page
    else:
        new_user = User(email=email, firstname = firstname, surname = surname)#make the new_user object
        new_user.set_password(password)

        # Queue it up to be put into the database
        model.session.add(new_user)

        # create a variable to use for input into the addresses table and geocoding
        a = Address(    email = email, 
                        address1 = address1, 
                        address2 = address2,
                        city = city,
                        state = state,
                        zipcode = zipcode,
                        country = country,
                        phone = phone)
        #get LagLng from google api for address input by user in this session
        a.geocode()
        # append address info including latlng of the new user to the adresses table
        new_user.addresses.append(a)

        # Now we've got all the stuff the database wants to put in the addresses table,
        # we can add and commit everything to the database.
        model.session.commit()

        login_user(new_user)
        
        return redirect(url_for("view_order", duck=request.args.get("duck")))
Пример #3
0
    def post(self, event_id_string):
        event = self._get_event(event_id_string)

        postal, source, lookup, manual_longitude, manual_latitude, \
            public = \
            BaseAddressHandler._get_arguments(self)

        address = Address(postal, source, lookup,
                              manual_longitude=manual_longitude,
                              manual_latitude=manual_latitude,
                              moderation_user=self.current_user,
                              public=public,
                              )
        address.geocode()
        event.address_list.append(address)
        self.orm.commit()
        self.redirect(self.next or event.url)
Пример #4
0
def insert_fast(
        data, orm,
        public=None, tag_names=None, dry_run=None, address_exclusive=None,
        search=True, org_id_whitelist=None
):
    user = orm.query(User).filter_by(user_id=-1).one()
    tag_names = tag_names or []

    tags = []
    for tag_name in tag_names:
        tag = Orgtag.get(
            orm,
            tag_name,
            moderation_user=user,
            public=public,
        )
        tags.append(tag)

    context = {
        "refresh": False,
        "user": user
    }
    for chunk in data:
        # pylint: disable=maybe-no-member
        has_address = None
        LOG.info("\n%s\n", chunk["name"])
        org = select_org(orm, chunk["name"], context, search)

        if (
                org is False or
                (org_id_whitelist and
                 ((not org) or (org.org_id not in org_id_whitelist)))
        ):
            LOG.info("Skipping org: %s", org and org.org_id)
            orm.rollback()
            continue

        if not org:
            LOG.warning("\nCreating org %s\n", chunk["name"])
            org = Org(chunk["name"], moderation_user=user, public=public,)
            orm.add(org)
            # Querying org address list on a new org would trigger a commit
            has_address = False
        else:
            has_address = bool(org.address_list)

        if tags:
            org.orgtag_list = list(set(tags + org.orgtag_list))

        if "tag" in chunk:
            for tag_name in chunk["tag"]:
                tag = Orgtag.get(
                    orm, tag_name,
                    moderation_user=user, public=public,
                )
                if tag not in org.orgtag_list:
                    org.orgtag_list.append(tag)

        if "address" in chunk and not (address_exclusive and has_address):
            for address_data in chunk["address"]:
                if address_data["postal"] in \
                        [address.postal for address in org.address_list]:
                    continue
                address = Address(
                    address_data["postal"], address_data["source"],
                    moderation_user=user, public=None,
                    )
                address.geocode()
                LOG.debug(address)
                orm.add(address)
                org.address_list.append(address)

        if "contact" in chunk:
            for contact_data in chunk["contact"]:
                text = sanitise_name(contact_data["text"])
                match = False
                for contact in org.contact_list:
                    if (
                            contact.text == text and
                            contact.medium.name == contact_data["medium"]
                    ):
                        match = True
                        break
                if match:
                    continue

                try:
                    medium = orm.query(Medium) \
                        .filter_by(name=contact_data["medium"]) \
                        .one()
                except NoResultFound:
                    LOG.warning("%s: No such medium", contact_data["medium"])
                    continue

                contact = Contact(
                    medium, text,
                    source=contact_data["source"],
                    moderation_user=user, public=None,
                )
                LOG.debug(contact)
                orm.add(contact)
                org.contact_list.append(contact)

        if "note" in chunk:
            for note_data in chunk["note"]:
                if note_data["text"] in [note.text for note in org.note_list]:
                    continue
                note = Note(
                    note_data["text"], note_data["source"],
                    moderation_user=user, public=None,
                    )
                LOG.debug(note)
                orm.add(note)
                org.note_list.append(note)

        if not (orm.new or orm.dirty or orm.deleted):
            LOG.info("Nothing to commit.")
            continue

        if dry_run is True:
            LOG.warning("rolling back")
            orm.rollback()
            continue

        LOG.info("Committing.")
        orm.commit()