Exemplo n.º 1
0
 def search_action(self):
     entry = SearchRecord()
     form = SearchCreateForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         uuid = self.searchid
         keywords = form.data['keywords']
         entry.id = uuid
         entry.keywords = keywords
         entry.pfams = form.data['pfams']
         self.request.dbsession.add(entry)
         return HTTPFound(location=self.request.route_url(
             'results', slug=urlify(keywords), searchid=uuid))
     return dict()
Exemplo n.º 2
0
    def view_results(self):
        def convert_results_to_display(results):
            data = []
            if len(results) == 0:
                return None
            for res in results:
                print('#####')
                print(res.patent_title)
                data.append((res.patent_title, 'US' + str(res.patent_number),
                             res.patent_abstract))
            return data

        # gets search parameters from webform
        keywords, pfams = retrieve_search(self.request)
        # submits search to patentview
        response = search_patentview(keywords, verbose=True)
        # populates the search table with results
        r = pop_temp_search_table(self.request, response, self.searchid)

        # filter results against domain information
        results = query_and_filter_database(self.request, pfams=pfams)
        results = results.all()
        data = convert_results_to_display(results)

        if data:
            page = {'name': 'Results', 'creator': 'Jake', 'data': data}
        else:

            # TODO change this so it redirects to a standard "no results" page
            data = [(
                '', '',
                'There are no results for these search terms. Please try again.'
            )]
            page = {'name': 'Results', 'creator': 'Jake', 'data': data}
            return HTTPFound(location=self.request.route_url(
                'no-results', searchid=self.searchid, slug=urlify(keywords)))

        return dict(page=page)
Exemplo n.º 3
0
 def search_action(self):
     """
     This function creates a search id, record, and redirects to the results page.
     """
     # create search record
     entry = SearchRecord()
     form = SearchCreateForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         # create unique search id
         uuid = self.searchid
         # extract keyword arguments from the web form
         keywords = form.data['keywords']
         entry.id = uuid
         entry.keywords = keywords
         # extract the pfams from the web form
         if form.data['pfams']:
             entry.pfams = form.data['pfams']
         else:
             entry.pfams = 'PF07686'  # default pfam is the v-set
         self.request.dbsession.add(entry)  # populate the database entry
         return HTTPFound(location=self.request.route_url(
             'results', slug=urlify(keywords), searchid=uuid))
     return dict()
Exemplo n.º 4
0
 def slug(self):
     return urlify(self.username)
Exemplo n.º 5
0
def register_through_xhr(request):
    req_body = request.params
    first_name = req_body.get('firstName')
    last_name = req_body.get('lastName')
    username = req_body.get('username')
    password = request.params.get('password')
    email = req_body.get('email')
    phone = req_body.get('phone')
    sex = req_body.get('sex')
    birth_date = req_body.get('birthDate')
    birth_month = req_body.get('birthMonth')
    birth_year = req_body.get('birthYear')
    country = req_body.get('country')
    sub_unit = req_body.get('subUnit')

    profile_pic = req_body.get('profilePic', None)
    categories = req_body.get('categories', None)

    categories_list = categories.split(',')
    category_subs = []

    try:
        new_user = User()
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.email = email

        new_user.set_password(password)
        new_user.username = username
        new_user.phone_number = str(phone)
        new_user.sex = sex
        new_user.birth_date = int(birth_date)
        new_user.birth_month = birth_month
        new_user.birth_year = int(birth_year)
        new_user.country = int(country)
        new_user.sub_unit = int(sub_unit)

        if profile_pic != None:
            try:
                if profile_pic.file != None:
                    pic_file = profile_pic.file
                    pic_name = "{}".format(uuid.uuid4())
                    uploaded_pic = upload_profile_picture(pic_file, pic_name)
                    new_user.profile_picture = uploaded_pic['secure_url']
            except:
                print('we')

        request.dbsession.add(new_user)
        request.dbsession.flush()
        new_user.slug = urlify(new_user.full_name)

        for category in categories_list:
            new_sub = CategorySubscriber()
            new_sub.category_id = int(category)
            new_sub.user_id = new_user.id

            new_user.subscriptions.append(new_sub)
            #redis
            redis_category_subscription = CategorySubscription(int(category))
            redis_category_subscription.add_subscriber(new_user.id)

        transaction.commit()

    except Exception as e:
        request.response.status = '400'
        return {'status': e}
    else:
        request.response.status = '200'
        return {'success': 'success'}
def generate_blog_post_slug(mapper, connect, target):
    if not target.slug:
        target.slug = urlify(target.title)
 def url(self):
     return '/blog/{0}'.format(self.slug or urlify(self.title))
Exemplo n.º 8
0
def create_poll(request):
    body = request.params
    question = body.get('question', None)
    poser = request.user.id
    info = body.get('info', None)
    options = body.get('options', None)

    option_images = body.getall('optionImage')
    option_image_titles = body.getall('option')

    duration = body.get('timeDue', None)
    categories = body.get('categories', None)
    context_image = body.get('context-image', None)

    options_list = []
    poll_categories_list = []

    if categories:
        categories = categories.split(',')
    if options:
        options = options.split(',')

    new_poll = Poll()
    new_poll.poser = poser
    if not question:
        request.response.status = '500'
        return 00
    new_poll.question = question
    new_poll.info = info
    slug = urlify(question)
    #new_poll.slug = slug

    try:
        if context_image != None:
            image_file = context_image.file
            image_name = "{}".format(uuid.uuid4())
            uploaded_image = add_image_description(image_file, image_name)

            new_poll.info_image_link = uploaded_image['secure_url']
    except:
        print("noting")
    if duration:
        now = datetime.datetime.utcnow()
        year = now.year
        day = now.day + int(duration)
        month = now.month
        hour = now.hour
        minute = now.minute
        second = now.second
        microsecond = now.microsecond
        try:
            new_poll.end_time = datetime.datetime(year, month, day, hour,
                                                  minute, second, microsecond)
        except:
            day = 1
            month += 1
        finally:
            new_poll.end_time = datetime.datetime(year, month, day, hour,
                                                  minute, second, microsecond)

    if option_images != None or len(option_images) > 0:
        for i, option_image in enumerate(option_images):
            try:
                try:
                    image_file = option_image.file
                except:
                    request.response.status = '400'
                    return {'eorror': option_image}
                image_name = '{}'.format(uuid.uuid4())
                uploaded_image = add_image_description(image_file, image_name)
                uploaded_image_link = uploaded_image['secure_url']

                new_option = Option()
                new_option.title = option_image_titles[i]
                new_option.image_link = uploaded_image_link

                options_list.append(new_option)
            except Exception as e:
                request.response.status = '400'
                return {'status': e}

    if option_image_titles == []:
        for option in options:
            if option != '':
                new_option = Option()
                new_option.title = option
                options_list.append(new_option)

    new_poll.options = options_list
    request.dbsession.add(new_poll)
    request.dbsession.flush()

    for category in categories:
        new_poll_category = PollCategory()
        new_poll_category.poll_id = new_poll.id
        new_poll_category.category_id = int(category)

        category = request.dbsession.query(Category).filter(
            Category.id == int(category)).first()
        category.polls.append(new_poll_category)

        poll_categories_list.append(new_poll_category)

    #add to redis category

    new_poll.categories = poll_categories_list
    request.dbsession.add(*poll_categories_list)

    new_activity = ActivityService(request, 'poll', request.user, new_poll)
    new_activity.create_new_activity()
    new_activity = new_activity.get_activity()

    RedisCategoryTimelineStorage.add_to_many(categories, new_activity.id)

    transaction.commit()

    return {}
Exemplo n.º 9
0
	def slug(self):
		""" This function makes a readable URL. """
		return urlify(self.title)
Exemplo n.º 10
0
	def slug(self):
		return urlify(self.title)
Exemplo n.º 11
0
 def slug(self):
     return urlify(self.question)
Exemplo n.º 12
0
	def slug(self):
		return urlify(self.subject)
Exemplo n.º 13
0
	def slug(self):
		""" Create a human readable slug that makes it easy to read the URL. """
		return urlify(self.title)
Exemplo n.º 14
0
	def slug(self):
		""" Create a slug for the URL that the user should be able to read. """
		return urlify(self.subject)
Exemplo n.º 15
0
 def add_success(self, values):
     doc = Document(**values)
     name = urlify(doc.title)
     self.context[name] = doc
     return HTTPFound(self.request.resource_url(doc))
Exemplo n.º 16
0
 def add_success(self, values):
     image = PersistentImage(values['title'],
                             values['data']['fp'].read())
     name = urlify(image.title)
     self.context[name] = image
     return HTTPFound(self.request.resource_url(image))
Exemplo n.º 17
0
	def slug(self):
		""" There should be a nice readable URL slug when the user visits. """ 
		return urlify(self.username)
Exemplo n.º 18
0
 def slug(self):
     return urlify(self.title)
Exemplo n.º 19
0
	def slug(self):
		""" Create a human readable URL for when a user visits. """
		return urlify(self.title)