예제 #1
0
def _populate_database():
    get_user_model().objects.create_user(username='******', password='******')
    get_user_model().objects.create_superuser(username='******', password='******')
    image_name = 'test-image.jpg'
    image_bytes = None

    with open(CURRENT_DIR + '/' + image_name, 'rb') as image:
        image_bytes = image.read()

    resource = Resource(
        external_id='recpbs29kfas9i',
        url='https://test.test/resource.pdf'
    )
    resource.image.save(image_name, ContentFile(image_bytes), save=True)
    resource.save()

    for external_id in ('recZxlcM61qaDoOkc', 'recYK5ljTyL3b18J3', 'recvSDrARAcmKogbD'):
        practice = Practice(
            external_id=external_id,
            main_resource=resource,
        )
        practice.image.save(image_name, ContentFile(image_bytes), save=True)
        practice.save()

    for category_id in ('rec82929kfas9i', 'rec0098afaooka', 'recppasf09aii'):
        category = Category(
            external_id=category_id,
            practice_external_ids=['recZxlcM61qaDoOkc']
        )
        category.image.save(image_name, ContentFile(image_bytes), save=True)
        category.save()
        category.practices.add(Practice.objects.filter(external_id='recZxlcM61qaDoOkc').first())
예제 #2
0
파일: tests.py 프로젝트: kxing/Geddit
    def tearDown(self):
        Reservation.delete_reservation(self.reservation1)
        self.user.remove_reservation(self.reservation2)

        Item.delete_item(self.item1)
        Item.delete_item(self.item2)
        Item.delete_item(self.item3)

        User.delete_user(self.user)
        Category.delete_category(self.category)
예제 #3
0
파일: tests.py 프로젝트: kxing/Geddit
 def tearDown(self):
     # delete the items
     Item.delete_item(self.item1)
     Item.delete_item(self.item2)
     # delete the categories
     Category.delete_category(self.category1)
     Category.delete_category(self.category2)
     # delete the users
     User.delete_user(self.buyer)
     User.delete_user(self.seller)
예제 #4
0
파일: views_lib.py 프로젝트: kxing/Geddit
def base_params(request):
    return { \
        'categories': Category.get_all_categories(), \
        'SITE_ROOT': SITE_ROOT, \
        'user': get_current_user(request), \
        'message': request.GET.get('message', None), \
    }
예제 #5
0
파일: views.py 프로젝트: kxing/Geddit
def buy_page(request):
    render_params = base_params(request)
    render_params[NAV_PAGE] = BUY

    category = None
    if 'category' in request.GET:
        category = Category.get_category(request.GET['category'])

    search_query = request.GET.get('search_query', None)
    id = request.GET.get('id', None)
    page = (int)(request.GET.get('page', 0))

    matching_items = Item.get_filtered_items(category, search_query, id)

    if page * BUY_PAGE_ITEMS_PER_PAGE > len(matching_items):
      page = 0

    render_params['items'] = matching_items[page * 10 : (page + 1) * 10]
    render_params['category'] = category
    render_params['search_query'] = search_query
    render_params['id'] = id
    render_params['page'] = page
    render_params['pages'] = 1 + (len(matching_items) - 1) / BUY_PAGE_ITEMS_PER_PAGE

    return render(request, 'buy/buy.html', render_params, \
            context_instance=RequestContext(request))
예제 #6
0
파일: tests.py 프로젝트: kxing/Geddit
 def setUp(self):
     # create the users
     self.buyer = User.create_user(self.BUYER_USERNAME, \
             self.BUYER_FIRST_NAME, self.BUYER_LAST_NAME, \
             self.BUYER_EMAIL, self.BUYER_CELL_PHONE,
             self.BUYER_LOCATION)
     self.seller = User.create_user(self.SELLER_USERNAME, \
             self.SELLER_FIRST_NAME, self.SELLER_LAST_NAME, \
             self.SELLER_EMAIL, self.SELLER_CELL_PHONE,
             self.SELLER_LOCATION)
     # create the categories
     self.category1 = Category.create_category(self.CATEGORY_1)
     self.category2 = Category.create_category(self.CATEGORY_2)
     # create the items
     self.item1 = Item.create_item(self.seller, self.ITEM_1_NAME, \
             self.ITEM_1_DESCRIPTION, self.category1, self.ITEM_1_PRICE)
     self.item2 = Item.create_item(self.seller, self.ITEM_2_NAME, \
             self.ITEM_2_DESCRIPTION, self.category2, self.ITEM_2_PRICE)
예제 #7
0
파일: tests.py 프로젝트: kxing/Geddit
    def setUp(self):
        # create the user
        self.user = User.create_user(self.USERNAME, self.FIRST_NAME, \
                self.LAST_NAME, self.EMAIL, self.PHONE, self.LOCATION)

        # create the categories
        self.textbooks = Category.create_category(self.TEXTBOOK_CATEGORY)
        self.videos = Category.create_category(self.VIDEOS_CATEGORY)
        self.girs = Category.create_category(self.GIRS_CATEGORY)

        # create the items
        self.textbook_3091_1 = Item.create_item(self.user, self.TEXTBOOK_NAME, \
                self.TEXTBOOK_DESCRIPTION, self.textbooks, self.TEXTBOOK_PRICE)
        self.textbook_3091_2 = self.user.add_item(self.TEXTBOOK_NAME, \
                self.TEXTBOOK_DESCRIPTION, self.textbooks, self.TEXTBOOK_PRICE)
        self.video_5111 = self.user.add_item(self.VIDEOS_NAME, \
                self.VIDEOS_DESCRIPTION, self.videos, self.VIDEOS_PRICE)
        self.cheat_sheets = self.user.add_item(self.CHEAT_SHEET_NAME, \
                self.CHEAT_SHEET_DESCRIPTION, self.girs, self.CHEAT_SHEET_PRICE)
예제 #8
0
파일: tests.py 프로젝트: kxing/Geddit
    def test_categories(self):
        '''
        Tests to make sure that categories can be queried
        and that the attributes are correct.
        '''
        # find the category and check it
        c = Category.get_category(self.CATEGORY_NAME)
        self.assertEqual(c, self.category)
        self.assertEqual(c.name, self.CATEGORY_NAME)

        # repeat for category 2
        c2 = Category.get_category(self.CATEGORY2_NAME)
        self.assertEqual(c2, self.category2)
        self.assertEqual(c2.name, self.CATEGORY2_NAME)

        # test to make sure that the list of all categories is sorted
        all_categories = Category.get_all_categories()
        self.assertEqual(all_categories[0], self.category2)
        self.assertEqual(all_categories[1], self.category) 
예제 #9
0
파일: tests.py 프로젝트: kxing/Geddit
 def setUp(self):
     self.category = Category.create_category(self.GIRS_CATEGORY)
     self.user = User.create_user(self.USERNAME, self.FIRST_NAME, self.LAST_NAME, \
             self.EMAIL, self.PHONE, self.LOCATION)
     self.item1 = Item.create_item(self.user, self.PHYSICS_NAME, \
             self.PHYSICS_DESCRIPTION, self.category, self.PHYSICS_PRICE_1)
     self.item2 = Item.create_item(self.user, self.PHYSICS_NAME, \
             self.PHYSICS_DESCRIPTION, self.category, self.PHYSICS_PRICE_2)
     self.item3 = Item.create_item(self.user, self.VIDEO_NAME, \
             self.VIDEO_DESCRIPTION, self.category, self.VIDEO_PRICE)
     self.reservation1 = Reservation.create_reservation(self.user, \
             self.SEARCH_QUERY1, self.MAX_PRICE)
     self.reservation2 = self.user.add_reservation(self.SEARCH_QUERY2, self.MAX_PRICE)
예제 #10
0
파일: views.py 프로젝트: sarine/Geddit
def buy_page(request):
    render_params = base_params(request)

    category = None
    if 'category' in request.GET:
        category = Category.get_category(request.GET['category'])

    search_query = request.GET.get('search_query', None)
    id = request.GET.get('id', None)

    render_params['items'] = Item.get_filtered_items(category, search_query, id)

    return render(request, 'buy.html', render_params, \
            context_instance=RequestContext(request))
예제 #11
0
 def _import_categories(self, categories):
     """
     Import categories and build mapping of category id (model identifier from export) to (possibly created)
     database category object.
     """
     categories_to_create = []
     for identifier, category in categories.items():
         try:
             db_category = Category.objects.get(model_identifier=identifier)
         except Category.DoesNotExist:
             db_category = Category(model_identifier=identifier, name=category["name"],
                                    description=category["description"], color=category["color"])
             categories_to_create.append(db_category)
         self._mappings.category_mapping[identifier] = db_category
     Category.objects.bulk_create(categories_to_create)
     self.statistics.categories_created = len(categories_to_create)
예제 #12
0
파일: tests.py 프로젝트: kxing/Geddit
    def tearDown(self):
        # delete the items
        Item.delete_item(self.textbook_3091_1)
        Item.delete_item(self.textbook_3091_2)
        Item.delete_item(self.video_5111)
        Item.delete_item(self.cheat_sheets)

        # delete the categories
        Category.delete_category(self.textbooks)
        Category.delete_category(self.videos)
        Category.delete_category(self.girs)

        # delete the user
        User.delete_user(self.user)
예제 #13
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True)
        parser.add_argument('color', required=False)
        try:
            data = parser.parse_args()
            #maybe add a check to prevent the same exact category from being added twice for one user
            new_cat = Category(owner=get_jwt_identity(),
                               name=data['name'],
                               color=data['color'])
            db.session.add(new_cat)
            db.session.commit()

            output = {
                "id": new_cat.id,
                "name": new_cat.name,
                "color": new_cat.color
            }
            return json.dumps(output), 200

        except Exception:
            raise Exception
예제 #14
0
    def update():
        """
        We completely replace whatever we have in the DB for
        the new information. Eventually we may want to only replace
        the changed ones.

        If there are errors, an array of them will be returned.
        """
        errors = []
        practices_base = settings.AIRTABLE_PRACTICES_BASE

        json_practices = _get_airtable_data('Pratiques?view=Grid%20view', practices_base)
        errors += validate_practices(json_practices)

        json_practice_types = _get_airtable_data('Types%20de%20pratique?view=Grid%20view', practices_base)
        errors += validate_practice_types(json_practice_types)

        json_weeds = _get_airtable_data('Adventices?view=Grid%20view', practices_base)
        errors += validate_weeds(json_weeds)

        json_pests = _get_airtable_data('Ravageurs?view=Grid%20view', practices_base)
        errors += validate_pests(json_pests)

        json_cultures = _get_airtable_data('Cultures?view=Grid%20view', practices_base)
        errors += validate_cultures(json_cultures)

        json_glyphosate = _get_airtable_data('Glyphosate?view=Grid%20view', practices_base)
        errors += validate_glyphosate_uses(json_glyphosate)

        json_resources = _get_airtable_data('Liens?view=Grid%20view', practices_base)
        errors += validate_resources(json_resources)

        json_resource_images = _get_airtable_data('logos?view=Grid%20view', practices_base)
        errors += validate_resource_images(json_resource_images)

        json_categories = _get_airtable_data('Categories?view=Grid%20view', practices_base)
        errors += validate_categories(json_categories)

        json_weed_practices = _get_airtable_data('Pratiques%2FAdventices?view=Grid%20view', practices_base)
        errors += validate_weed_practices(json_weed_practices)

        json_pest_practices = _get_airtable_data('Pratiques%2FRavageurs?view=Grid%20view', practices_base)
        errors += validate_pest_practices(json_pest_practices)

        json_culture_practices = _get_airtable_data('Pratiques%2FCultures?view=Grid%20view', practices_base)
        errors += validate_culture_practices(json_culture_practices)

        json_departments_practices = _get_airtable_data('Pratiques%2FDepartements?view=Grid%20view', practices_base)
        errors += validate_department_practices(json_departments_practices)

        json_departments = _get_airtable_data('Departements?view=Grid%20view', practices_base)
        errors += validate_departments(json_departments)

        json_glyphosate_practices = _get_airtable_data('Pratiques%2FGlyphosate?view=Grid%20view', practices_base)
        errors += validate_glyphosate_practices(json_glyphosate_practices)

        json_practice_groups = _get_airtable_data('Familles?view=Grid%20view', practices_base)
        errors += validate_practice_groups(json_practice_groups)

        json_mechanisms = _get_airtable_data('Marges%20de%20manoeuvre?view=Grid%20view', practices_base)
        errors += validate_mechanisms(json_mechanisms)

        has_fatal_errors = any(x.fatal for x in errors)
        if has_fatal_errors:
            return errors

        mechanisms = [Mechanism.create_from_airtable(x) for x in json_mechanisms]
        Mechanism.objects.all().delete()
        for mechanism in mechanisms:
            mechanism.save()

        categories = [Category.create_from_airtable(x) for x in json_categories]
        Category.objects.all().delete()
        for category in categories:
            category.save()

        json_resource_images.sort(key=lambda x: len(x['fields'].get('URL_principal')), reverse=True)
        resources = [Resource.create_from_airtable(x, json_resource_images) for x in json_resources]
        Resource.objects.all().delete()
        for resource in resources:
            resource.save()

        practice_groups = [PracticeGroup.create_from_airtable(x) for x in json_practice_groups]
        PracticeGroup.objects.all().delete()
        for practice_group in practice_groups:
            practice_group.save()

        practice_types = [PracticeType.create_from_airtable(x) for x in json_practice_types]
        PracticeType.objects.all().delete()
        for practice_type in practice_types:
            practice_type.save()

        weeds = [Weed.create_from_airtable(x) for x in json_weeds]
        Weed.objects.all().delete()
        for weed in weeds:
            weed.save()

        pests = [Pest.create_from_airtable(x) for x in json_pests]
        Pest.objects.all().delete()
        for pest in pests:
            pest.save()

        accepted_sectors = ['Grande culture']
        cultures = [SimulatorCulture.create_from_airtable(x) for x in json_cultures if x['fields'].get('Filière') in accepted_sectors]
        SimulatorCulture.objects.all().delete()
        for culture in cultures:
            culture.save()

        practices = [Practice.create_from_airtable(x, json_culture_practices, json_departments_practices,
                                                   json_departments, json_glyphosate, json_glyphosate_practices,
                                                   mechanisms, resources, json_practice_types, json_weeds,
                                                   json_weed_practices, json_pests, json_pest_practices) for x in json_practices]
        Practice.objects.all().delete()
        for practice in practices:
            practice.save()

        _link_practices_with_groups(practices, practice_groups)
        _link_practices_with_resources(practices, resources)
        _link_practices_with_types(practices, practice_types)
        _link_practices_with_categories(practices, categories)

        return errors
예제 #15
0
파일: tests.py 프로젝트: kxing/Geddit
 def tearDown(self):
     # delete the category
     Category.delete_category(self.category)
     Category.delete_category(self.category2)
예제 #16
0
파일: tests.py 프로젝트: kxing/Geddit
 def setUp(self):
     # create a category
     self.category = Category.create_category(self.CATEGORY_NAME)
     self.category2 = Category.create_category(self.CATEGORY2_NAME)
예제 #17
0
# Make location
baker = Location.create_location('Baker Hall', '42.35666', '-71.09582')
bexely = Location.create_location('Bexley Hall', '42.35852604285305', '-71.09368236574556')
burton_conner = Location.create_location('Burton-Conner House', '42.35607', '-71.09811')
east_campus = Location.create_location('East Campus', '42.36026', '-71.08880')
macgregor = Location.create_location('MacGregeor House', '42.35543', '-71.09981')
maseeh = Location.create_location('Maseeh Hall', '42.35764801061463', '-71.09338732275393')
mccormick = Location.create_location('McCormick Hall', '42.35731', '-71.09454')
new_house = Location.create_location('New House', '42.35543', '-71.10023')
next_house = Location.create_location('Next House', '42.354714540813504', '-71.10203476461794')
random_hall = Location.create_location('Random Hall', '42.36191', '-71.09821')
senior = Location.create_location('Senior House', '42.36007', '-71.08689')
simmons = Location.create_location('Simmons Hall', '42.35733', '-71.10105')

# Add in categories
girs = Category.create_category('GIRs')
furniture = Category.create_category('Furniture')
clothing = Category.create_category('Clothing')
santorum = Category.create_category('Rainbow-colored Santorum Posters')

kerry = User.create_user('kxing', 'Kerry', 'Xing', '*****@*****.**', '(123)456-7890', next_house)
paul = User.create_user('pwh', 'Paul', 'Hemberger', '*****@*****.**', '(234)567-8901', maseeh)
sean = User.create_user('scockey', 'Sean', 'Cockey', '*****@*****.**', '(345)678-9012', maseeh)
sarine = User.create_user('sarine', 'Sarine', 'Shahmirian', '*****@*****.**', '(456)789-0123', bexely)

kerry.add_item('5.111 Textbook', 'In great condition.', girs, '30.99')
time.sleep(1.0)
kerry.add_item('Wooden Chair', 'Slightly worn.', furniture, '24.97')
time.sleep(1.0)
kerry.add_item('Santorum Poster', 'Really want to get rid of this...', santorum, '0.01')
time.sleep(1.0)
예제 #18
0
파일: views_lib.py 프로젝트: sarine/Geddit
def base_params(request):
    return { \
        'categories': Category.get_all_categories(), \
        'SITE_ROOT': SITE_ROOT, \
        'user': get_current_user(request), \
    }
예제 #19
0
            ret.append(q.slug)
        return ret
    # If the workflow does not exist, we inform the user
    except ObjectDoesNotExist:
        return "Workflow with slug '" + workflowslug + "'  does not exist"


# Get or create categories category 1 and category 2
for i in range(1, 3):
    print "Creating category " + str(i) + "..."
    try:
        # Try to find the category
        c = Category.objects.get(name="category " + str(i))
    except ObjectDoesNotExist:
        # If it does not exist, we create it
        c = Category(name="category " + str(i))
        c.save()

# Get or create workflows with names workflow xy, x in {1,2} and y in {1,2,3} and relate them to category x
for i in range(1, 4):
    for j in range(1, 3):
        print "Creating workflow " + str(j) + str(i) + "..."
        try:
            # Try to find the workflow
            w = Workflow.objects.get(name="workflow " + str(j) + str(i))
            # Relate with category j
            w.category.add(Category.objects.get(name="category " + str(j)))
        except ObjectDoesNotExist:
            # If the workflow does not exist, we create it
            w = Workflow(name="workflow " + str(j) + str(i),
                         json=Command.getJson(populate))
 def addCategory(self, baseName):
     # create categories
     self.createObjects(baseName, 5)
     for item in self.data[baseName]:
         object = Category(name=item, tooltip="tooltip_" + item)
         object.save()
예제 #21
0
# Make location
baker = Location.create_location('Baker Hall', '42.35666', '-71.09582')
bexely = Location.create_location('Bexley Hall', '42.35852604285305', '-71.09368236574556')
burton_conner = Location.create_location('Burton-Conner House', '42.35607', '-71.09811')
east_campus = Location.create_location('East Campus', '42.36026', '-71.08880')
macgregor = Location.create_location('MacGregeor House', '42.35543', '-71.09981')
maseeh = Location.create_location('Maseeh Hall', '42.35764801061463', '-71.09338732275393')
mccormick = Location.create_location('McCormick Hall', '42.35731', '-71.09454')
new_house = Location.create_location('New House', '42.35543', '-71.10023')
next_house = Location.create_location('Next House', '42.354714540813504', '-71.10203476461794')
random_hall = Location.create_location('Random Hall', '42.36191', '-71.09821')
senior = Location.create_location('Senior House', '42.36007', '-71.08689')
simmons = Location.create_location('Simmons Hall', '42.35733', '-71.10105')

# Add in categories
appliances = Category.create_category('Appliances')
books = Category.create_category('Books')
clothing = Category.create_category('Clothing and Accessories')
circuit_parts = Category.create_category('Circuit Parts')
computers = Category.create_category('Computers and Accessories')
course_notes = Category.create_category('Course Notes')
dvds = Category.create_category('DVDs')
electronics = Category.create_category('Electronics')
furniture = Category.create_category('Furniture')
games = Category.create_category('Games and Toys')
kitchen_supplies = Category.create_category('Kitchen Supplies')
miscellaneous = Category.create_category('Miscellaneous')
posters = Category.create_category('Posters')
school_supplies = Category.create_category('School Supplies')
teal_clickers = Category.create_category('TEAL Clickers')
textbooks = Category.create_category('Textbooks')