Пример #1
0
    def handle(self, *args, **options):
        if options['days_to_add'] and options['location_id']:
            print options['days_to_add']
            print options['location_id']

            location = Location.objects.get(id=options['location_id'][0])
            needs = location.need_set.all()
            topic_titles = []
            for need in needs:
                if need.topic.title not in topic_titles:
                    topic_titles.append(need.topic.title)

            for item in topic_titles:
                topic = Topics.objects.filter(title=item)[:1]
                needs_needs = Need.objects.filter(topic__title=item)
                for needy in needs_needs:
                    to_time = str(needy.time_period_to)
                    from_time = str(needy.time_period_from)
                    date = parse(to_time)
                    date_new_from = parse(from_time)

                    for i in range(int(options['days_to_add'][0])):
                        newtime_to = date_new_to + datetime.timedelta(days=i)
                        newtime_from = date_new_from + datetime.timedelta(days=i)
                        from_the_time = TimePeriods(date_time=newtime_from)
                        from_the_time.save()
                        to_the_time = TimePeriods(date_time=newtime_to)
                        to_the_time.save()
                        new_row = Need(topic=topic[0])
                        new_row.location = location
                        new_row.slots = needy.slots

                        new_row.time_period_to = to_the_time
                        new_row.time_period_from = from_the_time
                        new_row.save()
Пример #2
0
def generate_blueprint(request):
    if request.method == 'POST' and request.is_ajax():
        locations = json.loads(request.POST.get('locations'))
        for location_id in locations:
            location = Location.objects.get(pk=location_id)
            blueprint = BluePrintCreator.objects.get(location=location)
            message = []
            for need in blueprint.needs.all():
                time_from = parse(request.POST.get('date') + " " + need.from_time, ignoretz=True, fuzzy=True)
                time_to = parse(request.POST.get('date') + " " + need.to_time, ignoretz=True, fuzzy=True)
                if Need.objects.filter(topic=need.topic, location=location, time_period_from__date_time=str(time_from),
                                       time_period_to__date_time=str(time_to)).count() > 0:
                    message.append('Ist bereits vorhanden')
                else:
                    time_to_link = TimePeriods(date_time=time_to)
                    time_to_link.save()
                    time_from_link = TimePeriods(date_time=time_from)
                    time_from_link.save()
                    new_need = Need(
                        topic=need.topic,
                        location=location,
                        time_period_from=time_from_link,
                        time_period_to=time_to_link,
                        slots=need.slots
                    )
                    new_need.save()
                    message.append('Ist angelegt worden!')

            return HttpResponse(json.dumps({"data": message}), content_type="application/json")