示例#1
0
def json_to_venue(item):

    venue = Venue()

    value_mapping = {
        'name': ['name', 'name'],
        'name_jp': ['name', 'name_sub'],
        'gurunavi_id': ['id'],
        'gurunavi_url': ['url'],
        'longitude': ['location', 'longitude'],
        'latitude': ['location', 'latitude'],
        # 'budget': ['budget'],
        'address': ['contacts', 'address'],
        'phone': ['contacts', 'tel'],
        'description': ['sales_points', 'pr_short'],
        'opening_times': ['business_hour'],
    }

    try:
        venue.budget = float(item['budget'])
    except ValueError:
        venue.budget = 0

    for key in value_mapping:
        try:
            assign_value(item, venue, key, value_mapping[key])
        except KeyError as e:
            print('Could not get key: ' + key + ': ' + str(value_mapping[key]))
            setattr(venue, key, '')

    return venue
示例#2
0
 def create_venue(self, user):
     new_venue = Venue(name=self.cleaned_data['name'],
                       main_calendar=self.cleaned_data['main_calendar'],
                       creator=user,
                       customer=user.userprofile.customer)
     new_venue.save()
     return new_venue
示例#3
0
    def import_venues(self):
        self.venues = {}

        for venue in self.root.findall('venue'):
            v = Venue(tournament=self.tournament, name=venue.text, priority=venue.get('priority', 0))
            v.save()
            self.venues[venue.get('id')] = v
示例#4
0
 def setUp(self):
     # load all the songs into the DB
     for i in songs:
         foo = Song(name=i[0])
         foo.save()
     # must also add a venue
     foo = Venue(name='test', city='test', state=4, country=0)
     foo.save()
示例#5
0
def confirm_venues(request, t):
    venue_names = request.POST.getlist('venue_names')
    venue_priorities = request.POST.getlist('venue_priorities')
    venue_categories = request.POST.getlist('venue_categories')
    category_displays = request.POST.getlist('category_displays')
    venue_shares = request.POST.getlist('venue_shares')

    for i, key in enumerate(venue_names):
        venue_tournament = t
        if venue_shares[i] == "yes":
            venue_tournament = None

        priority = venue_priorities[i]
        if not priority or not float(priority).is_integer():
            messages.warning(
                request, "Venue %s could not be saved because \
                it did not have a valid priority number" % venue_names[i])
            continue

        venue = Venue(name=venue_names[i],
                      priority=venue_priorities[i],
                      tournament=venue_tournament)
        venue.save()

        if venue_categories[i]:
            display = VenueCategory.DISPLAY_NONE
            try:
                if category_displays[i] == "prefix":
                    display = VenueCategory.DISPLAY_PREFIX
                elif category_displays[i] == "suffix":
                    display = VenueCategory.DISPLAY_SUFFIX
            except IndexError:
                pass

            try:
                venue_category = VenueCategory.objects.get(
                    name=venue_categories[i])
            except VenueCategory.DoesNotExist:
                venue_category = VenueCategory(name=venue_categories[i],
                                               display_in_venue_name=display)
                venue_category.save()

            venue_category.venues.add(venue)
            venue_category.save()

    messages.success(request, "%s Venues have been added" % len(venue_names))
    return render(request, 'old_importer/data_index.html')
示例#6
0
def addNewVenue(request):
    """This rather long function is just to test all the data that arrives."""
    if (request.method != 'POST'):
        return (HttpResponse(status=404))
    # we will assume that the data is in the request
    country = request.POST['country']
    state = request.POST['state']
    city = request.POST['city']
    venue = request.POST['venue']
    longitude = request.POST['longitude']
    latitude = request.POST['latitude']
    # there are a few things to do here. First we check that the country is valid
    country = getCountryCode(country)
    if (country == None):
        # return an error
        json_data = json.dumps({'country': 'This country does not exist'})
        return (HttpResponse(json_data,
                             content_type='application/json',
                             status=404))
    if (country == 0):
        # we must check the state
        state = getStateCode(state)
        if (state == None):
            json_data = json.dumps({'state': 'This state does not exist'})
            return (HttpResponse(json_data,
                                 content_type='application/json',
                                 status=404))
    else:
        state = -1
    # The city and venue are just text, we can ignore them
    # longitude and latitude are the same, just numbers, but we should check that both exist or not
    # the following statement is the nearest to a XOR I could get
    if (bool(longitude == '') ^ bool(latitude == '')):
        json_data = json.dumps({
            'longitude':
            'Both values must be numbers or be empty',
            'latitude':
            'Both values must be numbers or be empty'
        })
        return (HttpResponse(json_data,
                             content_type='application/json',
                             status=404))
    # let's just add the venue
    if (longitude == ''):
        new_venue = Venue(country=country, state=state, city=city, name=venue)
    else:
        new_venue = Venue(country=country,
                          state=state,
                          city=city,
                          name=venue,
                          longitude=longitude,
                          latitude=latitude)
    new_venue.save()
    # the js code will need to re-populate the drop-downs. It already has the state and the country, so we
    # create the 2 other lists, give the index and return this data
    query = Venue.objects.filter(country=country).filter(state=state)
    cities = set([x.city for x in query])
    venues = set([x.name for x in query.filter(city=city)])
    json_data = json.dumps({
        'country': getCountryName(country),
        'state': getStateName(state),
        'cities': [x for x in cities],
        'city_index': city,
        'venues': [x for x in venues],
        'venue_index': venue
    })
    return (HttpResponse(json_data,
                         content_type='application/json',
                         status=200))
示例#7
0
"""
Run this script in django shell to import venues as model instances
"""
import pandas as pd
from venues.models import Venue, Category

df = pd.read_excel('venues/venues.xlsx')

for index, row in df.iterrows():
    name = row['name']
    latitude = float(row['latitude'])
    longitude = float(row['longitude'])
    address = row['address']
    url = str(row['url'])
    try:
        category = Category.objects.get(name=row['category'])
        venue = Venue(category=category,
                      name=name,
                      latitude=latitude,
                      longitude=longitude,
                      address=address,
                      url=url)
        venue.save()
    except Exception:
        print(name, row['category'])
示例#8
0
def new_default_venue(customer):
    venue = Venue(name=_("default"), creator=customer.user, customer=customer)
    venue.save()
    return venue