예제 #1
0
파일: models.py 프로젝트: brudil/falmer
    def update_from_msl(self, content):
        image = get_group_image_url(content['logo_url'])

        self.msl_group_id = content['id']
        self.description = content['description']
        self.group.description = content['description']
        self.group.name = content['name']
        self.group.slug = get_slug(content['link'])
        self.link = content['link']
        self.group.link = content['link']
        self.logo_url = image or ''
        category, created_category = MSLStudentGroupCategory.objects.get_or_create(
            name=content['category'])
        self.category = category

        local_remote_image = RemoteImage.try_image(image, SOURCE_GROUP_LOGO)

        if local_remote_image is not None:
            self.logo = local_remote_image
            self.group.logo = local_remote_image
        else:
            self.logo = None
            self.group.logo = None

        self.group.save()

        self.save()
예제 #2
0
파일: models.py 프로젝트: brudil/falmer
    def create_from_msl(content):
        group = StudentGroup.objects.create(name=content['name'],
                                            slug=get_slug(content['link']))

        category, created_category = MSLStudentGroupCategory.objects.get_or_create(
            name=content['category'])
        image = get_group_image_url(content['logo_url'])

        msl_group = MSLStudentGroup(
            group=group,
            msl_group_id=content['id'],
            link=content['link'],
            description=content['description'],
            logo_url=image or '',
            category=category,
        )

        local_remote_image = RemoteImage.try_image(image, SOURCE_GROUP_LOGO)

        if local_remote_image is not None:
            msl_group.logo = local_remote_image

        msl_group.save()

        return msl_group
예제 #3
0
    def create_from_msl(api_content):
        with transaction.atomic():
            title = api_content['Title']
            start_time = arrow.get(api_content['StartDate']).replace(
                tzinfo=tz.gettz('Europe/London')).datetime
            end_time = arrow.get(api_content['EndDate']).replace(
                tzinfo=tz.gettz('Europe/London')).datetime

            event_url = api_content['Url']

            if event_url.startswith(
                    'https://www.sussexstudent.com/ents/event'):
                event_url = ''

            ticket_type = Event.MSL if api_content['HasTickets'] else Event.NA
            ticket_data = event_url if api_content['HasTickets'] else ''

            event = Event(title=title,
                          start_time=start_time,
                          end_time=end_time,
                          location_display=api_content['Location'],
                          short_description=api_content['Description'],
                          kicker=api_content['Organisation'],
                          url=event_url,
                          body=api_content['Body'],
                          student_group=StudentGroup.get_by_msl_id(
                              api_content['OrganisationId']),
                          ticket_type=ticket_type,
                          ticket_data=ticket_data)

            local_remote_image = RemoteImage.try_image(api_content['ImageUrl'],
                                                       SOURCE_EVENT_FEATURE)

            if local_remote_image is not None:
                event.featured_image = local_remote_image

            event.save()

            msl_event = MSLEvent(
                event=event,
                title=title,
                start_time=start_time,
                end_time=end_time,
                msl_event_id=api_content['Id'],
                has_tickets=api_content['HasTickets'],
                org_id=api_content['OrganisationId'],
                org_name=api_content['Organisation'],
                image_url=api_content['ImageUrl'],
                url=api_content['Url'],
                location=api_content['Location'],
                body_html=api_content['Body'],
                description=api_content['Description'],
            )

            msl_event.save()
            return msl_event
예제 #4
0
파일: models.py 프로젝트: brudil/falmer
    def update_from_msl(self, api_content):
        title = api_content['Title']
        location = api_content['Location']
        start_time = arrow.get(api_content['StartDate']).replace(tzinfo=tz.gettz('Europe/London')).datetime
        end_time = arrow.get(api_content['EndDate']).replace(tzinfo=tz.gettz('Europe/London')).datetime
        # TODO: implement change checking before saving/setting

        if not self.disable_sync:
            event_url = api_content['Url']

            if event_url.startswith('https://www.sussexstudent.com/ents/event'):
                event_url = ''

            ticket_type = Event.MSL if api_content['HasTickets'] else Event.NA
            ticket_data = api_content['Url'] if api_content['HasTickets'] else ''

            self.event.title = title
            self.event.start_time = start_time
            self.event.end_time = end_time
            self.event.location_display = location
            self.event.short_description = api_content['Description']
            self.event.kicker = api_content['Organisation']
            self.event.url = event_url
            self.event.body = api_content['Body']
            self.event.student_group = StudentGroup.get_by_msl_id(api_content['OrganisationId'])
            self.event.ticket_type = ticket_type
            self.event.ticket_data = ticket_data

            local_remote_image = RemoteImage.try_image(api_content['ImageUrl'], SOURCE_EVENT_FEATURE)

            if local_remote_image is not None:
                self.event.featured_image = local_remote_image

            try:
                venue_map = AutoLocationDisplayToVenue.objects.get(location=location)
                self.event.venue = venue_map.venue
            except AutoLocationDisplayToVenue.DoesNotExist:
                self.event.venue = None

            self.event.save()

        self.title = title
        self.start_time = start_time
        self.end_time = end_time
        self.msl_event_id = api_content['Id']
        self.has_tickets = api_content['HasTickets']
        self.org_id = api_content['OrganisationId']
        self.org_name = api_content['Organisation']
        self.image_url = api_content['ImageUrl']
        self.url = api_content['Url']
        self.location = api_content['Location']
        self.body_html = api_content['Body']
        self.description = api_content['Description']
        self.save()