Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate Resources from being created #303

Closed
pricem opened this issue Mar 26, 2012 · 5 comments
Closed

Prevent duplicate Resources from being created #303

pricem opened this issue Mar 26, 2012 · 5 comments

Comments

@pricem
Copy link
Contributor

pricem commented Mar 26, 2012

Stanford ESP had a problem with Ajax scheduling that turned out to be caused by multiple Resource objects existing for a given (room name, timeslot ID) combination. This should be prevented, and also probably enforced by a unique_together constraint.

@btidor
Copy link
Contributor

btidor commented Feb 17, 2016

Per #2036, name and event (?) should also be unique_together

@lenaqr
Copy link

lenaqr commented Feb 17, 2016

Yeah, event and timeslot ID are the same thing.

@willgearty
Copy link
Member

@willgearty
Copy link
Member

willgearty commented May 17, 2023

Making these fields "unique_together" would break the current implementation of floating resources, which allows for duplicates (#2840):

def duplicates(self):
res_list = Resource.objects.filter(name=self.name, event = self.event)
return res_list

@willgearty
Copy link
Member

willgearty commented Nov 3, 2023

It is not currently possible to create two classrooms with the same name with the normal classroom UI. When trying to add a new classroom with the same name, the code below uses the existing classroom and updates it instead:

if orig_room_number == "":
orig_room_number = self.cleaned_data['room_number']
initial_rooms = program.getClassrooms().filter(name=orig_room_number).distinct()
initial_furnishings = {}
for r in initial_rooms:
initial_furnishings[r] = list(r.associated_resources())
timeslots = Event.objects.filter(id__in=[int(id_str) for id_str in self.cleaned_data['times_available']])
rooms_to_keep = list(initial_rooms.filter(event__in=timeslots))
rooms_to_delete = list(initial_rooms.exclude(event__in=timeslots))
new_timeslots = timeslots.exclude(id__in=[x.event_id for x in rooms_to_keep])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants