Ejemplo n.º 1
0
def confirm_venues(request, t):
    print(request.POST)
    venue_names = request.POST.getlist('venue_names')
    venue_priorities = request.POST.getlist('venue_priorities')
    venue_groups = request.POST.getlist('venue_groups')
    venue_shares = request.POST.getlist('venue_shares')
    for i, key in enumerate(venue_names):
        if venue_groups[i]:
            try:
                venue_group = VenueGroup.objects.get(short_name=venue_groups[i])
            except VenueGroup.DoesNotExist:
                try:
                    venue_group = VenueGroup.objects.get(name=venue_groups[i])
                except VenueGroup.DoesNotExist:
                    venue_group = VenueGroup(name=venue_groups[i],
                        short_name=venue_groups[i][:15]).save()
        else:
            venue_group = None

        if venue_shares[i] == "yes":
            venue_tournament = None
        else:
            venue_tournament = t

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

    confirmed = {"kind": "Venues", "quantity": len(venue_names)}
    return render(request, 'confirmed_data.html', dict(confirmed=confirmed))
Ejemplo n.º 2
0
def confirm_venues(request, t):
    print(request.POST)
    venue_names = request.POST.getlist('venue_names')
    venue_priorities = request.POST.getlist('venue_priorities')
    venue_groups = request.POST.getlist('venue_groups')
    venue_shares = request.POST.getlist('venue_shares')
    for i, key in enumerate(venue_names):
        if venue_groups[i]:
            try:
                venue_group = VenueGroup.objects.get(short_name=venue_groups[i])
            except VenueGroup.DoesNotExist:
                try:
                    venue_group = VenueGroup.objects.get(name=venue_groups[i])
                except VenueGroup.DoesNotExist:
                    venue_group = VenueGroup(name=venue_groups[i],
                                             short_name=venue_groups[i][:15]).save()
        else:
            venue_group = None

        if venue_shares[i] == "yes":
            venue_tournament = None
        else:
            venue_tournament = t

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

    messages.success(request, "%s Venues have been added" % len(venue_names))
    return render(request, 'data_index.html')
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def new_default_venue(customer):
    venue = Venue(
        name=_("default"),
        creator=customer.user,
        customer=customer
    )
    venue.save()
    return venue
Ejemplo n.º 8
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
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
    def setUp(self):
        super(BaseDebateTestCase, self).setUp()
        # add test models
        self.t = Tournament(slug="tournament")
        self.t.save()
        for i in range(4):
            ins = Institution(code="INS%s"%i, name="Institution %s"%i)
            ins.save()
            for j in range(3):
                team = Team(tournament=self.t, institution=ins, reference="Team%s%s" % (i,j))
                team.save()
                for k in range(2):
                    speaker = Speaker(team=team, name="Speaker%s%s%s" % (i,j,k))
                    speaker.save()
            for j in range(2):
                adj = Adjudicator(tournament=self.t, institution=ins, name="Adjudicator%s%s" %
                                  (i,j), test_score=0)
                adj.save()

        for i in range(8):
            venue = Venue(name="Venue %s" % i)
            venue.priority = i
            venue.save()

            venue = Venue(name="IVenue %s" % i)
            venue.priority = i
            venue.save()
Ejemplo n.º 11
0
 def update_venue_timestamps(
     self, venue: Venue, update_time: datetime.datetime = None
 ) -> None:
     """Update the venue last checked and last updated times"""
     LOG.debug(
         "Setting check time for %s to %s and update time for to %s",
         venue,
         self.check_timestamp,
         update_time,
     )
     venue.tap_list_last_check_time = self.check_timestamp
     if update_time:
         venue.tap_list_last_update_time = update_time
     venue.save()
Ejemplo n.º 12
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')
Ejemplo n.º 13
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()
Ejemplo n.º 14
0
def confirm_venues(request, t):
    venue_names = request.POST.getlist('venue_names')
    venue_priorities = request.POST.getlist('venue_priorities')
    venue_groups = request.POST.getlist('venue_groups')
    for i, key in enumerate(venue_names):
        if venue_groups[i]:
            venue_group = VenueGroup.objects.get_or_create(
                name=venue_groups[i], short_name=venue_groups[i][:15])
        else:
            venue_group = None
        try:
            venue = Venue(name=venue_names[i],
                          priority=venue_priorities[i],
                          group=venue_group,
                          tournament=t)
            venue.save()
        except:
            pass

    confirmed = {"kind": "Venues", "quantity": len(venue_names)}
    return render(request, 'confirmed_data.html', dict(confirmed=confirmed))
Ejemplo n.º 15
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))
Ejemplo n.º 16
0
def new_default_venue(customer):
    venue = Venue(name=_("default"), creator=customer.user, customer=customer)
    venue.save()
    return venue
Ejemplo n.º 17
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'])