Ejemplo n.º 1
0
    def import_events(self, reader, options):
        self.stdout.write(self.style.SUCCESS("Importing events"))

        events_page = EventIndexPage.objects.get()
        for row in reader:
            # bulk_create doesn't call save() method
            try:
                if row["illustration"]:
                    illustration = Image.objects.get(title=row["illustration"])
                else:
                    illustration = None
                e = Event(
                    title=row["post_title"],
                    short_overview=row["overview"],
                    description=row["post_content"],
                    date_and_time=datetime.fromtimestamp(
                        int(row["datetime"]),
                        pytz.timezone("Europe/Bratislava")),
                    location=(Location.objects.get(
                        title=row["location"].strip().lower())),
                    video_url=self.video_url(row["youtube_link"]),
                    # ticket_url=row["tickets_button_url"],
                    category=Category.objects.get(title=row["topic"]),
                    icon=illustration,
                    speakers=Speaker.objects.filter(
                        wordpress_id__in=row["speakers"].
                        split(",") if row["speakers"] else []).all(),
                )
                events_page.add_child(instance=e)
                e.save_revision().publish()
                self.stdout.write(f"{e.pk},{e.event_id},{row['ID']},{e.title}")
            except ObjectDoesNotExist as e:
                raise

        self.stdout.write(self.style.SUCCESS("Events imported"))
Ejemplo n.º 2
0
 def add_event(code):
     #todo: import this function from isa_website/views
     new_event = Event(api_url=api_url,
                       event_start=start_time,
                       title=api_object['name']['html'],
                       event_url=api_object['url'],
                       event_code=code)
     new_event.save()
Ejemplo n.º 3
0
def main():
	credentials = get_credentials()
	http = credentials.authorize(httplib2.Http())
	service = discovery.build('calendar', 'v3', http=http)

	now = datetime.datetime.utcnow() # 'Z' indicates UTC time

	page_token = None
	
	if now.hour > 0 and now.hour < 5:
		now = now - datetime.timedelta(hours=24)
	time_min = now - datetime.timedelta(hours=now.hour) # Hack to get the start time at start of the day
	time_min = time_min.isoformat() + 'Z'
	time_max = now + datetime.timedelta(days=14)
	time_max = time_max.isoformat() + 'Z'
	timeZone = 'America/New_York'

	eventDict = {}
	Event.objects.all().delete()
	while True:
		events = service.events().list(calendarId='primary', 
									   pageToken=page_token,
									   orderBy='startTime',
									   singleEvents=True,
   									   timeMin=time_min,
 	   								   timeMax=time_max,
									   timeZone=timeZone).execute()

		for event in events['items']:
			starttime = event.get('start').get('dateTime')
			endtime = event.get('end').get('dateTime')
			if starttime is None or endtime is None:
				continue
			date = parse(starttime).date()

			event = Event(event_id=event.get('id'),
						  date=date,
						  starttime=starttime,
						  endtime=endtime)
			event.save()

		page_token = events.get('nextPageToken')
		if not page_token:
			break


	if not events:
		print('No upcoming events found.')
Ejemplo n.º 4
0
    def import_events(self, options):
        self.stdout.write(self.style.SUCCESS("Import events started"))

        bhd = FestivalPage.objects.order_by("pk").all()[0]
        khd = FestivalPage.objects.order_by("pk").all()[1]
        parent = EventIndexPage.objects.get()

        path = os.path.join(options["csv_dir"], "events.csv")
        with open(path, "r", newline="") as file:
            reader = csv.DictReader(file)

            for i, row in enumerate(reader, start=1):
                parent.add_child(instance=Event(
                    event_id=row["event_id"],
                    title=row["title"],
                    category=Category.objects.get(title=row["category"]),
                    date_and_time=datetime.fromisoformat(row["date_and_time"]),
                    location=Location.objects.get(title=row["location"]),
                    video_url=row["video_url"],
                    ticket_url=row["ticket_url"],
                    show_on_festivalpage=row["show_on_festivalpage"],
                    icon=self.icon(row["icon"]),
                    related_festival=bhd if row["related_festival"] ==
                    "bhd" else khd,
                    speakers=Speaker.objects.filter(
                        speaker_id__in=row["speakers"].
                        split(",") if row["speakers"] else []),
                    wordpress_url=row["wordpress_url"],
                    short_overview=row["short_overview"],
                    description=row["description"],
                ))

        self.stdout.write(
            self.style.SUCCESS(f"Import events finished - {i} events"))
Ejemplo n.º 5
0
def add_event(request):
    # TODO: Modify to store timezone
    _event = json.loads(request.GET.get("event"))
    category, created = Category.objects.get_or_create(
        name=_event.get("category"))
    print(_event["calendarId"])
    task_authorization = TaskAuthorization.objects.get(
        charge_code=_event["calendarId"])
    temp = {
        "id": _event["id"],
        "title": _event["title"],
        "isAllDay": _event["isAllDay"],
        "start":
        datetime.fromisoformat(_event["start"]["_date"].replace("Z", "")),
        "end": datetime.fromisoformat(_event["end"]["_date"].replace("Z", "")),
        "category": category,
        "dueDateClass": _event["dueDateClass"],
        # "task_authorization": task_authorization,
        # "charge_code": _event[""],
        # "location":_event["location"],
        # "notes": _event[""],
    }

    temp["delta_time"] = (temp["end"] -
                          temp["start"]).total_seconds() / 60 / 60.

    task_authorization.hours_spent += temp["delta_time"]
    task_authorization.hours_remaining -= temp["delta_time"]
    task_authorization.hours_percentage = (
        task_authorization.hours_spent /
        task_authorization.hours_allocated) * 100.0

    temp["task_authorization"] = task_authorization

    task_authorization.save()

    if request.user.is_authenticated:
        temp["user"] = request.user

    event = Event(**temp)

    print(f"Create Event ({request.user}): {_event['id']}")
    event.save()

    return JsonResponse({"response": "Recieved"})
Ejemplo n.º 6
0
def edit_article(request, article_id=0):
    if request.method == 'POST':
        form = EditArticleForm(request.POST, request.FILES)

        if form.is_valid():

            author = request.user.author
            date = timezone.now()
            title = form.cleaned_data['title']
            is_beta = form.cleaned_data['is_beta']
            text = form.cleaned_data['text']
            category = form.cleaned_data['category']
            image = form.cleaned_data['image']

            if article_id == 0:
            	e = Event(name=title, pub_date=date, category=category, image=None)

            	a = Article(event=e, author=author, is_beta=is_beta, text=text)
            else:
            	a = get_object_or_404(Article, pk=article_id)
            	if image is None:
            		image = a.event.image
            	e = a.event
                if author != a.author and author not in a.modifiers.all():
            	   a.modifiers.add(author)
            	a.is_beta = is_beta
            	a.text = text
            	e.name = title
            	e.pub_date = date
            	e.category = category
            	e.image = image
            	a.event = e

            e.save()
            a.save()



            return HttpResponseRedirect(a.get_absolute_url())
    else:
    	if article_id == 0:
        	form = EditArticleForm()
        else:
        	a = get_object_or_404(Article, pk=article_id)
    		form = EditArticleForm(initial={'title':a.event.name,
    										'image':a.event.image,
    										'category':a.event.category,
    										'is_beta':a.is_beta,
    										'text':a.text})
    if article_id == 0:
    	send_to = '/article/new/'
    else :
    	send_to = '/article/edit/' + article_id + '/'
    
    return render(request, 'article/edit.html', locals())
Ejemplo n.º 7
0
def edit_article(request, article_id=0):
    if request.method == 'POST':
        form = EditArticleForm(request.POST, request.FILES)
        formset=formset_factory( EditPartForm )( request.POST )

        if form.is_valid():

            author = request.user.member
            date = timezone.now()
            title = form.cleaned_data['title']
            is_beta = form.cleaned_data['is_beta']
            category = form.cleaned_data['category']
            image = form.cleaned_data['image']
            is_pinned = form.cleaned_data['is_pinned']
            introduction = form.cleaned_data['introduction']

            if article_id == 0:
            	e = Event(name=title, pub_date=date, category=category, image=image, is_pinned=is_pinned)
                e.save()
            	a = Article(event=e, author=author, is_beta=is_beta, introduction=introduction)
                a.save()
                if formset.is_valid():
                    for p in formset:
                        text = p.cleaned_data['text']
                        title= p.cleaned_data['title']
                        part=Part(text=text, title=title, article=a)
                        part.save()
                idx = a.pk
            else:
            	a = get_object_or_404(Article, pk=article_id)
            	if image is None:
            		image = a.event.image
            	e = a.event
                a.introduction = introduction
            	a.is_beta = is_beta
                e.is_pinned =  is_pinned
            	e.name = title
            	e.pub_date = date
            	e.category = category
            	e.image = image
            	a.event = e

                if formset.is_valid():
                    for p in a.parts.all():
                        p.delete()
                    for p in formset:
                        a.parts.create(title=p.cleaned_data['title'], text=p.cleaned_data['text'])

                e.save()
                a.save()

            return HttpResponseRedirect(a.get_absolute_url())
    else:
    	if article_id == 0:
            form = EditArticleForm()
            parts = formset_factory(EditPartForm, extra=1)()
        else:
            a = get_object_or_404(Article, pk=article_id)
            p_list = []
            no_parts = True
            for i in a.parts.all():
                p_list.append({'title': i.title,'text':i.text})
                no_parts = False
            if no_parts:
                parts = formset_factory(EditPartForm, extra=0)(initial=p_list)
            else:
                parts = formset_factory(EditPartForm, extra=0)(initial=p_list)
            form = EditArticleForm(initial={'title':a.event.name,
    										'image':a.event.image,
    										'category':a.event.category,
    										'is_beta':a.is_beta,
                                            'introduction':a.introduction,})
    if article_id == 0:
    	send_to = '/article/new/'
    else :
    	send_to = '/article/' + article_id + '/edit/'
    
    return render(request, 'article/edit.html', locals())