Esempio n. 1
0
def get_status():
    status = Status.objects.first()
    if status is None:
        status = Status(status="Nope")
        status.save()

    return status
Esempio n. 2
0
def something_processed():
    return Something(
        id="test",
        user=User(id="u1", name="test_user"),
        status=Status(ts=EVENT_TS, type=StatusType.PROCESSED),
        history=[Status(ts=EVENT_TS, type=StatusType.SUBMITTED)]
    )
Esempio n. 3
0
def something_with_status_submitted_example():
    return Something(
        id="test",
        user=User(id="u1", name="test_user"),
        status=Status(ts=EVENT_TS, type=StatusType.SUBMITTED),
        history=[Status(ts=EVENT_TS, type=StatusType.NEW)]
    )
Esempio n. 4
0
 def add_status_fromCrawler(self,
                            authorDic,
                            statusToMerge,
                            commentsIds=None):
     status_id = statusToMerge.status_id
     usersimple = self.get_simpleUser(authorDic)
     status_exist = self.find_status_exist(status_id)
     user_id = usersimple.get('user_id')
     if user_id:
         statusURL = "http://api.weibo.com/2/statuses/go?uid=" + str(
             user_id) + "&id=" + (str(status_id))
     else:
         statusURL = statusToMerge.statusurl
     pic_url_list = statusToMerge.pic_urls
     pic_url_dic_list = []
     for pic_url in pic_url_list:
         pic_url_dic = {'thumbnail_pic': pic_url}
         pic_url_dic_list.append(pic_url_dic)
     if not status_exist:
         newStatus = Status(status_id=status_id,
                            text=statusToMerge.text,
                            created_at=statusToMerge.date,
                            geo=statusToMerge.geo,
                            source=statusToMerge.source,
                            reposts_count=statusToMerge.repost_count,
                            comments_count=statusToMerge.comments_count,
                            attitudes_count=statusToMerge.attitude_count,
                            user_simple=usersimple,
                            comments=commentsIds,
                            pic_urls=pic_url_dic_list,
                            scrapedTimeStamp=statusToMerge.timestamp,
                            statusurl=statusURL,
                            keywords=statusToMerge.keywords)
         newStatus.save()
Esempio n. 5
0
def updatestatus(phone, newstatus):  
    #create and update instance 
    # .put() the instance
  user = getuserfromphone(phone)
  statusupdate = Status(user)
  statusupdate.statusmsg = newstatus
  statusupdate.statustime = datetime.now()
  return True
Esempio n. 6
0
def something_with_status_processed_example():
    return Something(id="test",
                     user=User(id="u1", name="test_user"),
                     status=Status(ts=datetime.now(),
                                   type=StatusType.PROCESSED),
                     history=[
                         Status(ts=datetime.now(), type=StatusType.NEW),
                         Status(ts=datetime.now(), type=StatusType.SUBMITTED)
                     ])
Esempio n. 7
0
    def import_statuses(self, status_csv):
        statuses = []
        lines = status_csv.split('\n')
        for line in lines:
            if len(line.strip()) > 0:
                fields = line.split(';')
                status = Status()
                status.order = int(fields[0])
                status.name = fields[1].strip()
                status.put()
                statuses.append(status)

        return statuses;
Esempio n. 8
0
    def post(self):
        if self.request.get('store') != '1':
            self.redirect('/members')
            return

        try:
            member = Member()
            member.name = self.get_var('name')
            member.address = self.get_var('address')
            member.zipcode = self.get_var('zip')
            member.city = self.get_var('city')
            member.country = Country.get(self.get_var('country'))
            member.email = self.get_var('email', optional=True)
            member.mobile = self.get_var('mobile', optional=True)
            member.home = self.get_var('home', optional=True)
            member.work = self.get_var('work', optional=True)
            member.membertype = MemberType.get(self.get_var('type'))
            member.notes = self.get_var('comment', optional=True)
            member.status = Status.get(self.get_var('status'))
            member.number = dbutils.create_new_member_no()
            member.member_since = datetime.date.today()
            member.generate_access_code()
            mcount = self.get_var('magazine_count', optional=True)
            member.magazine_count = int(mcount) if mcount else 1
            member.put()
            self.redirect('/members/%s/edit' % member.key())
            return
        except MissingField:
            # TODO: Redirect
            template = JINJA_ENVIRONMENT.get_template(
                'templates/members/new_member.html')
            countries = Country.all().order('order').fetch(LIMIT)
            statuses = Status.all().order('order').fetch(LIMIT)
            types = MemberType.all().order('order').fetch(LIMIT)
            data = {}
            for name in [
                    'name', 'address', 'zip', 'country', 'email', 'mobile',
                    'home', 'work', 'type', 'comment', 'status'
            ]:
                data[name] = self.request.get(name)

            params = {
                'countries': countries,
                'statuses': statuses,
                'types': types,
                'data': data
            }
            self.response.write(template.render(params))
            return

        self.redirect('/members')
Esempio n. 9
0
def guide_accept_voyage():
    trip_id = session['trip_id']

    status = Status()
    status.trip_id = trip_id
    status.datetime_accepted = datetime.datetime.now()

    # Add the user object to the database
    db_session.add(status)

    # Save the user in the database
    db_session.commit()

    # Confirm
    return render_template("guide_commence_voyage.html")
Esempio n. 10
0
    def get(self, status_id):
        template = JINJA_ENVIRONMENT.get_template(
            'templates/statuses/detail.html')

        status = Status.get(status_id)
        data = {'status': status}
        self.response.write(template.render(data))
Esempio n. 11
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template(
            'templates/members/member_list.html')
        countries = Country.all().order('order').fetch(LIMIT)
        statuses = Status.all().order('order').fetch(LIMIT)
        types = MemberType.all().order('order').fetch(LIMIT)

        # TODO: Make sensible
        query_string = ''
        current_search = self.request.get('search')
        query_string += current_search

        current_status = self.request.get('status')
        if current_status != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'status:' + current_status

        current_type = self.request.get('type')
        if current_type != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'type:' + current_type

        current_country = self.request.get('country')
        if current_country and current_country != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'country:' + current_country

        index = search.Index(name='members')
        result = index.search(query=search.Query(
            query_string, options=search.QueryOptions(limit=LIMIT)))

        members = list()
        for document in result.results:
            members.append(Member.search_member_from_document(document))

        members = sorted(members, key=lambda x: x.number)

        current_status_name = current_status
        current_type_name = current_type

        total = memcache.get('member_count')
        if not total:
            total = 0

        data = {
            'countries': countries,
            'statuses': statuses,
            'types': types,
            'members': members,
            'current_status': current_status,
            'current_type': current_type,
            'current_search': current_search,
            'found': result.number_found,
            'shown': len(members),
            'total': total
        }
        self.response.write(template.render(data))
Esempio n. 12
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('templates/statuses/list.html')

        statuses = Status.all().order('order').fetch(100)

        data = { 'statuses' : statuses, 'counter': DataStoreCounter() }
        self.response.write(template.render(data))
async def update_status_history(payload: Something,
                                context: EventContext) -> Something:
    if payload.status:
        payload.history.append(payload.status)
    payload.status = Status(ts=datetime.now(tz=timezone.utc),
                            type=StatusType.LOADED)
    return payload
Esempio n. 14
0
    def post(self):
        if self.request.get('store') != '1':
            self.redirect('/members')
            return

        try:
            member = Member()
            member.name = self.get_var('name')
            member.address = self.get_var('address')
            member.zipcode = self.get_var('zip')
            member.city = self.get_var('city')
            member.country = Country.get(self.get_var('country'))
            member.email = self.get_var('email', optional=True)
            member.mobile = self.get_var('mobile', optional=True)
            member.home = self.get_var('home', optional=True)
            member.work = self.get_var('work', optional=True)
            member.membertype = MemberType.get(self.get_var('type'))
            member.notes = self.get_var('comment', optional=True)
            member.status = Status.get(self.get_var('status'))
            member.number = dbutils.create_new_member_no()
            member.member_since = datetime.date.today()
            member.generate_access_code()
            mcount = self.get_var('magazine_count', optional=True)
            member.magazine_count = int(mcount) if mcount else 1
            member.put()
            self.redirect('/members/%s/edit' % member.key())
            return
        except MissingField:
            # TODO: Redirect
            template = JINJA_ENVIRONMENT.get_template('templates/members/new_member.html')
            countries = Country.all().order('order').fetch(LIMIT)
            statuses = Status.all().order('order').fetch(LIMIT)
            types = MemberType.all().order('order').fetch(LIMIT)
            data = { }
            for name in [ 'name', 'address', 'zip', 'country', 'email', 'mobile', 'home', 'work', 'type', 'comment', 'status']:
                data[name] = self.request.get(name)

            params = {
                'countries': countries,
                'statuses': statuses,
                'types': types,
                'data': data
            }
            self.response.write(template.render(params))
            return

        self.redirect('/members')
Esempio n. 15
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template(
            'templates/statuses/list.html')

        statuses = Status.all().order('order').fetch(100)

        data = {'statuses': statuses, 'counter': DataStoreCounter()}
        self.response.write(template.render(data))
Esempio n. 16
0
def create_status():
    print('Existing statuses:')
    options_list(Status)
    name = input("\nEnter new status: ")
    status = Status(name=name)
    session.add(status)
    session.commit()
    print('created!\n')
Esempio n. 17
0
    def get(self):
        template = JINJA_ENVIRONMENT.get_template('templates/members/member_list.html')
        countries = Country.all().order('order').fetch(LIMIT)
        statuses = Status.all().order('order').fetch(LIMIT)
        types = MemberType.all().order('order').fetch(LIMIT)

        # TODO: Make sensible
        query_string = ''
        current_search = self.request.get('search')
        query_string +=  current_search

        current_status = self.request.get('status')
        if current_status != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'status:' + current_status

        current_type = self.request.get('type')
        if current_type != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'type:'+ current_type

        current_country = self.request.get('country')
        if current_country and current_country != '':
            if query_string != '':
                query_string += ' AND '
            query_string += 'country:' + current_country

        index = search.Index(name='members')
        result = index.search(query=search.Query(query_string, options=search.QueryOptions(limit=LIMIT)))

        members = list()
        for document in result.results:
            members.append(Member.search_member_from_document(document))

        members = sorted(members, key=lambda x: x.number)

        current_status_name = current_status
        current_type_name = current_type

        total = memcache.get('member_count')
        if not total:
            total = 0

        data = {
            'countries': countries,
            'statuses': statuses,
            'types': types,
            'members': members,
            'current_status': current_status,
            'current_type': current_type,
            'current_search': current_search,
            'found': result.number_found,
            'shown': len(members),
            'total': total
        }
        self.response.write(template.render(data))
Esempio n. 18
0
    def post(self, status_id):
        if self.request.get('cancel') == '1':
            return self.redirect('/statuses')

        status = Status.get(status_id)
        status.name = self.request.get('statusname')
        status.order = int(self.request.get('order'))
        status.put()
        return self.redirect('/statuses')
Esempio n. 19
0
    def post(self, status_id):
        if self.request.get('cancel') == '1':
            return self.redirect('/statuses')

        status = Status.get(status_id)
        status.name = self.request.get('statusname')
        status.order = int(self.request.get('order'))
        status.put()
        return self.redirect('/statuses')
Esempio n. 20
0
def stream_event(payload: Something, context: EventContext) -> Something:
    logger.info(context,
                "streaming event",
                extra=extra(something_id=payload.id))
    if payload.status:
        payload.history.append(payload.status)
    payload.status = Status(ts=datetime.now(tz=timezone.utc),
                            type=StatusType.SUBMITTED)
    return payload
Esempio n. 21
0
def create_status(checkout_status):
    """Create and return checkout status"""

    checkout_status = Status(checkout_status=checkout_status)

    db.session.add(checkout_status)
    db.session.commit()

    return checkout_status
Esempio n. 22
0
 def get(self):
     template = JINJA_ENVIRONMENT.get_template('templates/members/new_member.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'data': None
     }
     self.response.write(template.render(data))
async def test_query_item(app_config, sample_file_id):  # noqa: F811
    status = Status(datetime.now(tz=timezone.utc), StatusType.LOADED)
    result, pp_result, res = await execute_event(
        app_config=app_config,
        event_name='query_something_extended',
        payload=status,
        postprocess=True,
        item_id=sample_file_id)
    assert isinstance(result, Something)
    assert result == pp_result
    assert result.id == sample_file_id
    assert result.status == status
Esempio n. 24
0
def load_statuses():
    """Load statuses from status_data to database."""

    for line in open("seed_data/status_data"):
        line = line.rstrip()
        status_name = line

        status = Status(status_name=status_name)

        db.session.add(status)

    db.session.commit()
async def test_query_item_not_found(app_config):  # noqa: F811
    status = Status(datetime.now(tz=timezone.utc), StatusType.LOADED)
    item_id = str(uuid.uuid4())
    result, pp_result, res = await execute_event(
        app_config=app_config,
        event_name='query_something_extended',
        payload=status,
        postprocess=True,
        item_id=item_id)
    assert res.status == 404
    assert result == pp_result
    assert result == SomethingNotFound(
        path=f'/tmp/simple_example.{APP_VERSION}.fs.data_path', id=item_id)
async def fork_something(payload: Something, context: EventContext) -> Spawn[Union[FirstPart, SecondPart]]:
    """
    Produces 2 variants from payload to be processed in parallel
    """
    logger.info(context, "producing 2 variants of payload", extra=extra(something_id=payload.id))
    if payload.status:
        payload.history.append(payload.status)
    payload.status = Status(
        ts=datetime.now(tz=timezone.utc),
        type=StatusType.SUBMITTED
    )
    yield FirstPart(payload)
    yield SecondPart(payload)
Esempio n. 27
0
 def get(self):
     template = JINJA_ENVIRONMENT.get_template(
         'templates/members/new_member.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'data': None
     }
     self.response.write(template.render(data))
Esempio n. 28
0
 def add_status_fromAPI(self, statusDic, commentsIds=None):
     status_id = statusDic.get('id')
     created_at = self.format_created_at(statusDic.get('created_at'),
                                         "%a %b %d %H:%M:%S %Y")
     retrieveTimestamp = time.time()
     usersimple = self.get_simple_user(statusDic)
     status_exist = self.find_status_exist(status_id)
     user_id = usersimple.get('user_id')
     if user_id:
         statusURL = "http://api.weibo.com/2/statuses/go?uid=" + str(
             user_id) + "&id=" + (str(status_id))
     if not status_exist:
         newStatus = Status(
             status_id=statusDic.get('id'),
             text=statusDic.get('text'),
             created_at=created_at,
             geo=statusDic.get('geo'),
             source=statusDic.get('source'),
             reposts_count=statusDic.get('reposts_count'),
             comments_count=statusDic.get('comments_count'),
             attitudes_count=statusDic.get('attitudes_count'),
             user_simple=usersimple,
             comments=commentsIds,
             userType=statusDic.get('userType'),
             pic_urls=statusDic.get('pic_urls'),
             isLongText=statusDic.get('isLongText'),
             bmiddle_pic=statusDic.get('bmiddle_pic'),
             original_pic=statusDic.get('original_pic'),
             thumbnail_pic=statusDic.get('thumbnail_pic'),
             textLength=statusDic.get('textLength'),
             retrievedTimestamp=retrieveTimestamp,
             statusurl=statusURL,
             keywords=statusDic.get('key_words'))
         if statusDic.get('retweeted_status'):
             newStatus.retweeted_status_id = statusDic.get(
                 'retweeted_status').get('id')
         newStatus.save()
Esempio n. 29
0
def update_status(payload: Something, context: EventContext) -> Something:
    """
    Updates status of payload to PROCESSED and puts previous status in history.

    :param payload: Something, object
    :param context: EventContext
    """
    logger.info(context,
                "updating something status",
                extra=extra(something_id=payload.id))

    if payload.status:
        payload.history.append(payload.status)
    payload.status = Status(ts=datetime.now(), type=StatusType.PROCESSED)
    return payload
Esempio n. 30
0
async def spawn_many_events(payload: Something,
                            context: EventContext) -> Spawn[Something]:
    """
    Produces 3 events to be published to stream
    """
    logger.info(context,
                "spawning event 3 times",
                extra=extra(something_id=payload.id))
    if payload.status:
        payload.history.append(payload.status)
    for i in range(3):
        payload.status = Status(ts=datetime.now(tz=timezone.utc),
                                type=StatusType.SUBMITTED)
        payload.id = str(i)
        yield payload
Esempio n. 31
0
def process_site(interval, url, Session):
    """Processes the website and adds to the database"""

    while True:
        HTTP_status_code = url_check(url)
        timestamp = datetime.now()

        new_record = Status(HTTP_status_code=HTTP_status_code,
                            url=url,
                            timestamp=timestamp)
        session = Session()
        session.add(new_record)
        session.commit()

        print HTTP_status_code
        print url
        print timestamp
        time.sleep(interval)
Esempio n. 32
0
    def import_statuses(self, status_csv):
        statuses = []
        lines = status_csv.split('\n')
        for line in lines:
            if len(line.strip()) > 0:
                fields = line.split(';')
                status = Status()
                status.order = int(fields[0])
                status.name = fields[1].strip()
                status.put()
                statuses.append(status)

        return statuses
Esempio n. 33
0
 def get(self, member_id):
     template = JINJA_ENVIRONMENT.get_template('templates/members/member_detail.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     member = Member.get(member_id)
     dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     self.add_missing_dues(dues, max(config.FIRST_YEAR_WITH_DUES, member.member_since.year), current_year + config.DUES_AHEAD)
     dues = sorted(dues, key=lambda item: item.year, reverse=True)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'member': member,
         'dues': dues,
         'current_year': current_year
     }
     self.response.write(template.render(data))
Esempio n. 34
0
 def get(self, member_id):
     template = JINJA_ENVIRONMENT.get_template(
         'templates/members/member_detail.html')
     countries = Country.all().order('order').fetch(LIMIT)
     statuses = Status.all().order('order').fetch(LIMIT)
     types = MemberType.all().order('order').fetch(LIMIT)
     member = Member.get(member_id)
     dues = MembershipDues.all().ancestor(member).fetch(25)
     current_year = datetime.datetime.now().year
     self.add_missing_dues(
         dues, max(config.FIRST_YEAR_WITH_DUES, member.member_since.year),
         current_year + config.DUES_AHEAD)
     dues = sorted(dues, key=lambda item: item.year, reverse=True)
     data = {
         'countries': countries,
         'statuses': statuses,
         'types': types,
         'member': member,
         'dues': dues,
         'current_year': current_year
     }
     self.response.write(template.render(data))
Esempio n. 35
0
    def post(self):
        template = JINJA_ENVIRONMENT.get_template(
            'templates/loader/loader.html')

        content = self.request.get('type')

        countries = []
        if content == 'countries.csv':
            countries = self.import_countries(self.request.get('data'))

        statuses = []
        if content == 'status.csv':
            statuses = self.import_statuses(self.request.get('data'))

        types = []
        if content == 'types.csv':
            types = self.import_types(self.request.get('data'))

        if content == 'member.csv':
            self.statuslist = Status.all().fetch(100)
            self.typelist = MemberType.all().fetch(100)
            self.countrylist = Country.all().fetch(100)
            self.import_members(self.request.get('data'))

        if content == 'model_ranges.csv':
            self.import_model_range(self.request.get('data'))

        if content == 'car_models.csv':
            self.import_car_models(self.request.get('data'))

        if content == 'cars.csv':
            self.import_member_cars(self.request.get('data'))

        if content == 'users.csv':
            self.import_users(self.request.get('data'))

        self.response.write(template.render())
Esempio n. 36
0
    def post(self):
        template = JINJA_ENVIRONMENT.get_template('templates/loader/loader.html')

        content = self.request.get('type')

        countries = []
        if content == 'countries.csv':
            countries = self.import_countries(self.request.get('data'))

        statuses = []
        if content == 'status.csv':
            statuses = self.import_statuses(self.request.get('data'))

        types = []
        if content == 'types.csv':
            types = self.import_types(self.request.get('data'))

        if content == 'member.csv':
            self.statuslist = Status.all().fetch(100)
            self.typelist = MemberType.all().fetch(100)
            self.countrylist = Country.all().fetch(100)
            self.import_members(self.request.get('data'))

        if content == 'model_ranges.csv':
            self.import_model_range(self.request.get('data'))

        if content == 'car_models.csv':
            self.import_car_models(self.request.get('data'))

        if content == 'cars.csv':
            self.import_member_cars(self.request.get('data'))

        if content == 'users.csv':
            self.import_users(self.request.get('data'))

        self.response.write(template.render())
Esempio n. 37
0
def load_status():
    """ load status options into the database """

    # remove any existing rows in status table
    Status.query.delete()

    # get the status json from the API
    status_json = requests.get(
        "https://api.ravelry.com/" + "projects/project_statuses.json",
        auth=(os.environ['RAVELRY_ACCESS_KEY'],
              os.environ['RAVELRY_PERSONAL_KEY'])).json()

    statuses = status_json['project_statuses']

    # Add each status option to the db
    for status in statuses:
        status_id = status['id']
        status = status['name']

        status_opp = Status(status_id=status_id, status=status)

        db.session.add(status_opp)

    db.session.commit()
Esempio n. 38
0
    def post(self):
        complete = []
        incomplete = []
        values = {}

        # Holy crap this is ugly. There has to be a better way.

        name = self.request.get('name')
        if not name or name.strip() == '' or name.strip().startswith('http'):
            incomplete.append('name')
        else:
            values['name'] = name
            complete.append('name')

        address = self.request.get('address')
        # Spammers put URLs in the address field so we reject those right away
        if not address or address.strip() == '' or address.strip().startswith(
                'http'):
            incomplete.append('address')
        else:
            values['address'] = address
            complete.append('address')

        zipcode = self.request.get('zip')
        if (not zipcode or zipcode.strip() == '') or len(zipcode.strip()) < 4:
            incomplete.append('zip')
        else:
            values['zip'] = zipcode
            complete.append('zip')

        city = self.request.get('city')
        if not city or city.strip() == '':
            incomplete.append('city')
        else:
            values['city'] = city
            complete.append('city')

        if 'zip' in incomplete or 'city' in incomplete:
            incomplete.append('zipcity')

        country_key = self.request.get('country').strip()
        country = Country.get(country_key)

        countries = Country.all().order('order').fetch(100)

        if not country or not country_key or country_key.strip() == '':
            incomplete.append('country')
            # retrieve countries since we're going to need them
        else:
            values['country'] = country.name
            complete.append('country')

        email = self.request.get('email')
        if not email or email.strip() == '' or not mail.is_email_valid(email):
            incomplete.append('email')
        else:
            values['email'] = email
            complete.append('email')

        mobile = self.request.get('mobile')
        if mobile and mobile.strip() == '':
            mobile = None
        values['mobile'] = mobile

        home = self.request.get('home')
        if home and home.strip() == '':
            home = None
        values['home'] = home

        work = self.request.get('work')
        if work and work.strip() == '':
            work = None
        values['work'] = work

        member_type = self.request.get('type')
        if not member_type or member_type.strip() == '':
            member_type = '1'

        types = MemberType.all().fetch(100)

        mtype = None

        # TODO: Custom settings? Constants at least.
        if member_type == '1':
            mtype = next(t for t in types if t.name == DEFAULT_MEMBER_NAME)
        else:
            mtype = next(t for t in types
                         if t.name == DEFAULT_SUPPORT_MEMBER_NAME)

        values['type'] = mtype.name
        comment = self.request.get('comment')
        complete.append('comment')
        values['comment'] = comment

        error_message = ''

        # Check if member exists;
        existing = Member.all().filter('email', email).fetch(1)

        if len(existing) > 0:
            incomplete.append('email')
            error_message = 'Det er allerede registrert noen i medlemsregisteret med denne epostadressen!'
            # TODO: Error message

        if len(incomplete) > 0:
            # missing field, redirect to signup page again
            template = JINJA_ENVIRONMENT.get_template(
                'templates/selfservice/signup.html')
            return self.response.write(
                template.render({
                    'countries': countries,
                    'incomplete': incomplete,
                    'complete': complete,
                    'error_message': error_message,
                    'values': values
                }))

        # invariant: fields are OK, create new member, send mail,
        # create payment history on member.
        template = JINJA_ENVIRONMENT.get_template(
            'templates/selfservice/signup_receipt.html')
        data = {'values': values, 'profile_url': PROFILE_URL}

        statuses = Status.all().fetch(100)

        # TODO: Handle existing members signing up again

        new_member = Member()

        new_member.name = name
        new_member.address = address
        new_member.zipcode = zipcode
        new_member.city = city
        new_member.notes = comment
        new_member.country = country
        new_member.membertype = mtype

        status = next(s for s in statuses if s.name == SIGNUP_STATUS_NAME)
        new_member.status = status

        new_member.number = dbutils.create_new_member_no()

        new_member.email = email
        new_member.member_since = datetime.date.today()
        if mobile:
            new_member.phone = mobile
        if work:
            new_member.phone_work = work
        if home:
            new_member.phone_home = home
        new_member.generate_access_code()
        new_member.member_since = datetime.date.today()
        new_member.member_type = mtype
        new_member.put()
        new_member.update_index()

        self.send_welcome_mail(new_member)
        self.send_notification_mails(new_member)

        # TODO: Invalidate counts for categories
        # Handle mutations on members gracefully

        return self.response.write(template.render(data))
Esempio n. 39
0
    def post(self):
        complete = []
        incomplete = []
        values = {}

        # Holy crap this is ugly. There has to be a better way.

        name = self.request.get('name')
        if not name or name.strip() == '':
            incomplete.append('name')
        else:
            values['name'] = name
            complete.append('name')


        address = self.request.get('address')
        if not address or address.strip() == '':
            incomplete.append('address')
        else:
            values['address'] = address
            complete.append('address')


        zipcode = self.request.get('zip')
        if (not zipcode or zipcode.strip() == '') or len(zipcode.strip()) < 4:
            incomplete.append('zip')
        else:
            values['zip'] = zipcode
            complete.append('zip')


        city = self.request.get('city')
        if not city or city.strip() == '':
            incomplete.append('city')
        else:
            values['city'] = city
            complete.append('city')

        if 'zip' in incomplete or 'city' in incomplete:
            incomplete.append('zipcity')


        country_key = self.request.get('country').strip()
        country = Country.get(country_key)

        countries = Country.all().order('order').fetch(100)

        if not country or not country_key or country_key.strip() == '':
            incomplete.append('country')
            # retrieve countries since we're going to need them
        else:
            values['country'] = country.name
            complete.append('country')

        email = self.request.get('email')
        if not email or email.strip() == '' or not mail.is_email_valid(email):
            incomplete.append('email')
        else:
            values['email'] = email
            complete.append('email')

        mobile = self.request.get('mobile')
        if mobile and mobile.strip() == '':
            mobile = None
        values['mobile'] = mobile

        home = self.request.get('home')
        if home and home.strip() == '':
            home = None
        values['home'] = home

        work = self.request.get('work')
        if work and work.strip() == '':
            work = None
        values['work'] = work

        member_type = self.request.get('type')
        if not member_type or member_type.strip() == '':
            member_type = '1'

        types = MemberType.all().fetch(100)

        mtype = None

        # TODO: Custom settings? Constants at least.
        if member_type == '1':
            mtype = next(t for t in types if t.name == DEFAULT_MEMBER_NAME)
        else:
            mtype = next(t for t in types if t.name == DEFAULT_SUPPORT_MEMBER_NAME)

        values['type'] = mtype.name
        comment = self.request.get('comment')
        complete.append('comment')
        values['comment'] = comment

        error_message = ''

        # Check if member exists;
        existing = Member.all().filter('email', email).fetch(1)

        if len(existing) > 0:
            incomplete.append('email')
            error_message = 'Det er allerede registrert noen i medlemsregisteret med denne epostadressen!'
            # TODO: Error message

        if len(incomplete) > 0:
            # missing field, redirect to signup page again
            template = JINJA_ENVIRONMENT.get_template('templates/selfservice/signup.html')
            return self.response.write(template.render({
                'countries': countries,
                'incomplete': incomplete,
                'complete': complete,
                'error_message': error_message,
                'values': values }))

        # invariant: fields are OK, create new member, send mail,
        # create payment history on member.
        template = JINJA_ENVIRONMENT.get_template('templates/selfservice/signup_receipt.html')
        data = {
            'values': values,
            'profile_url': PROFILE_URL
        }

        statuses = Status.all().fetch(100)

        # TODO: Handle existing members signing up again

        new_member = Member()

        new_member.name = name
        new_member.address = address
        new_member.zipcode = zipcode
        new_member.city = city
        new_member.notes = comment
        new_member.country = country
        new_member.membertype = mtype

        status = next(s for s in statuses if s.name == SIGNUP_STATUS_NAME)
        new_member.status = status

        new_member.number = dbutils.create_new_member_no()

        new_member.email = email
        new_member.member_since = datetime.date.today()
        if mobile:
            new_member.phone = mobile
        if work:
            new_member.phone_work = work
        if home:
            new_member.phone_home = home
        new_member.generate_access_code()
        new_member.member_since = datetime.date.today()
        new_member.member_type = mtype
        new_member.put()

        self.send_welcome_mail(new_member)
        self.send_notification_mails(new_member)

        # TODO: Invalidate counts for categories
        # Handle mutations on members gracefully

        return self.response.write(template.render(data))
Esempio n. 40
0
 def get_status(self, status_name):
     for status in Status.all().fetch(50):
         if status.name == status_name:
             return status
     return None
Esempio n. 41
0
def task_status_restore(items):
    for item in items:
        status = Status(key_name=item['statusId'])
        status.order = item['order']
        status.name = item['name']
        status.put()
Esempio n. 42
0
    def post(self, member_id):

        if self.request.get('cancel') == '1':
            return self.redirect('/members')

        if self.request.get('operation') == 'delete_car':
            car = Car.get(self.request.get('car_key'))
            if car:
                car.delete()
            return self.redirect('/members/' + member_id + '/edit')

        member = Member.get(member_id)

        if self.request.get('operation') == 'new_car':
            car = Car()
            car.member = member
            car.model = dbutils.get_default_model()
            car.registration = ''
            car.year = 0
            car.notes = ''
            car.serial_no = ''
            car.put()
            return self.redirect('/members/' + member_id + '/car/' + str(car.key()) + '/edit' )

        member.name = self.request.get('name')
        member.address = self.request.get('address')
        member.zipcode = self.request.get('zip')
        member.city = self.request.get('city')
        member.country = Country.get(self.request.get('country'))
        phone = self.request.get('mobile').strip()
        if phone != '':
            member.phone = db.PhoneNumber(phone)
        else:
            member.phone = None
        email = self.request.get('email').strip()
        if email != '':
            member.email = db.Email(email)
        else:
            member.email = None
        home = self.request.get('fixed').strip()
        if home != '':
            member.phone_home = db.PhoneNumber(home)
        else:
            member.phone_home = None
        work = self.request.get('work').strip()
        if work != '':
            member.phone_work = db.PhoneNumber(work)
        else:
            member.phone_work = None
        member.membertype = MemberType.get(self.request.get('type'))
        member.status = Status.get(self.request.get('status'))
        member.notes = self.request.get('note')

        if self.request.get('access_code') == '':
            member.generate_access_code()

        if self.request.get('magazine_count') != '':
            try:
                member.magazine_count = int(self.request.get('magazine_count'))
            except ValueError:
                pass

        member.put()
        member.update_index()

        # save membership dues
        self.save_dues(member)


        return self.redirect('/members')
Esempio n. 43
0
 def get_status(self, status_name):
     for status in Status.all().fetch(50):
         if status.name == status_name:
             return status
     return None
Esempio n. 44
0
    def get(self, status_id):
        template = JINJA_ENVIRONMENT.get_template('templates/statuses/detail.html')

        status = Status.get(status_id);
        data = { 'status': status }
        self.response.write(template.render(data))
Esempio n. 45
0
    def post(self, member_id):

        if self.request.get('cancel') == '1':
            return self.redirect('/members')

        if self.request.get('operation') == 'delete_car':
            car = Car.get(self.request.get('car_key'))
            if car:
                car.delete()
            return self.redirect('/members/' + member_id + '/edit')

        member = Member.get(member_id)

        if self.request.get('operation') == 'new_car':
            car = Car()
            car.member = member
            car.model = dbutils.get_default_model()
            car.registration = ''
            car.year = 0
            car.notes = ''
            car.serial_no = ''
            car.put()
            return self.redirect('/members/' + member_id + '/car/' +
                                 str(car.key()) + '/edit')

        member.name = self.request.get('name')
        member.address = self.request.get('address')
        member.zipcode = self.request.get('zip')
        member.city = self.request.get('city')
        member.country = Country.get(self.request.get('country'))
        phone = self.request.get('mobile').strip()
        if phone != '':
            member.phone = db.PhoneNumber(phone)
        else:
            member.phone = None
        email = self.request.get('email').strip()
        if email != '':
            member.email = db.Email(email)
        else:
            member.email = None
        home = self.request.get('fixed').strip()
        if home != '':
            member.phone_home = db.PhoneNumber(home)
        else:
            member.phone_home = None
        work = self.request.get('work').strip()
        if work != '':
            member.phone_work = db.PhoneNumber(work)
        else:
            member.phone_work = None
        member.membertype = MemberType.get(self.request.get('type'))
        member.status = Status.get(self.request.get('status'))
        member.notes = self.request.get('note')

        if self.request.get('access_code') == '':
            member.generate_access_code()

        if self.request.get('magazine_count') != '':
            try:
                member.magazine_count = int(self.request.get('magazine_count'))
            except ValueError:
                pass

        member.put()
        member.update_index()

        # save membership dues
        self.save_dues(member)

        return self.redirect('/members')