Пример #1
0
    def __init__(self, request):
        from _database.models import Event
        from django.http import JsonResponse
        from django.template.loader import get_template
        from _website.models import Request

        str_date = request.GET.get('date', None)
        str_time = request.GET.get('time', None)
        str_duration = request.GET.get('duration', None)
        if str_date and str_time and str_duration:
            from _database.models import Helper

            overlapping_events = Event.objects.JSON__overlapping_events(
                Helper().INT__UNIX_from_date_and_time_STR(str_date, str_time),
                Helper().INT__duration_minutes(str_duration),
                request.GET.get('space', None),
            )

            self.value = JsonResponse({
                'int_overlapping_events':
                len(overlapping_events['overlapping_events']),
                'html':
                get_template(
                    'components/body/event_new/form_elements/overlapping_events.html'
                ).render({
                    'language': Request(request).language,
                    'overlapping_events': overlapping_events
                })
            })
        else:
            self.value = JsonResponse({
                'error':
                'Variables missing - date, time and duration needed.'
            })
Пример #2
0
 def save(self, *args, **kwargs):
     from _database.models import Helper
     import urllib.parse
     self = Helper().RESULT__updateTime(self)
     self.str_slug = urllib.parse.quote(
         'machine/' + self.str_name_en_US.lower().replace(' ', '-').replace(
             '/', '').replace('@', 'at').replace('&', 'and'))
     super(Machine, self).save(*args, **kwargs)
Пример #3
0
 def create(self, json_content):
     from _database.models import Helper
     try:
         obj = Consensus.objects.get(
             str_name_en_US=json_content['str_name_en_US'])
         for key, value in json_content.items():
             setattr(obj, key, value)
         obj = Helper().RESULT__updateTime(obj)
         obj.save()
         print('Updated "' + obj.str_name_en_US + '"')
     except Consensus.DoesNotExist:
         obj = Consensus(**json_content)
         obj = Helper().RESULT__updateTime(obj)
         obj.save()
         print('Created "' + obj.str_name_en_US + '"')
Пример #4
0
    def save(self, *args, **kwargs):
        from _database.models import Helper
        import urllib.parse
        from googletrans import Translator
        translator = Translator()

        if self.str_name_en_US:
            self.str_name_en_US = translator.translate(
                self.str_name_en_US, 'en').text
            if not self.str_name_he_IL:
                self.str_name_he_IL = translator.translate(
                    self.str_name_en_US, 'he').text

        self = Helper().RESULT__updateTime(self)
        super(Project, self).save(*args, **kwargs)
Пример #5
0
    def save(self, *args, **kwargs):
        from _database.models import Helper

        self = Helper().RESULT__updateTime(self)
        if not self.text_date:
            self.text_date = str(self.date)

        super(MeetingNote, self).save(*args, **kwargs)

        if not self.text_main_topics:
            self.text_main_topics = self.get_main_topics()

        if self.text_notes and not self.text_keywords:
            self.text_keywords = self.STR__get_keywords()
        else:
            self.start()

        super(MeetingNote, self).save(*args, **kwargs)
Пример #6
0
    def save(self, *args, **kwargs):
        # try:
        Log().print('event.save()')
        import urllib.parse
        from _database.models import Helper, Space, Person
        import bleach
        from _setup.models import Config
        import re
        from dateutil.parser import parse

        Log().print('--> auto change event to online if space closed when the event is happening')
        if self.str_location and not Config('EVENTS.ALLOW_IN_SPACE_EVENTS').value and Config('EVENTS.ALLOW_ONLINE_EVENTS').value:
            if Config('PHYSICAL_SPACE.TEMPORARY_LANDINGPAGE_HEADER.UP_TO_DATE').value:
                up_to_date = parse(
                    Config('PHYSICAL_SPACE.TEMPORARY_LANDINGPAGE_HEADER.UP_TO_DATE').value+' 00:00:00 +00:00')
                if self.datetime_start < up_to_date:
                    self.str_location = None
                    self.boolean_online_meetup = True

            else:
                self.str_location = None
                self.boolean_online_meetup = True

        Log().print('--> clean from scripts')
        if self.str_name_en_US:
            self.str_name_en_US = bleach.clean(self.str_name_en_US)
        if self.text_description_en_US:
            if not self.url_meetup_event:
                self.text_description_en_US = bleach.clean(
                    self.text_description_en_US)
        if self.text_description_he_IL:
            self.text_description_he_IL = bleach.clean(
                self.text_description_he_IL)
        if self.str_location:
            self.str_location = bleach.clean(
                self.str_location).replace('&lt;br&gt;', '<br>')
        if self.str_series_repeat_how_often:
            self.str_series_repeat_how_often = bleach.clean(
                self.str_series_repeat_how_often)
        if self.text_series_timing:
            self.text_series_timing = bleach.clean(self.text_series_timing)
        if self.str_crowd_size:
            self.str_crowd_size = bleach.clean(self.str_crowd_size)
        if self.str_welcomer:
            self.str_welcomer = bleach.clean(self.str_welcomer)
        if self.str_timezone:
            self.str_timezone = bleach.clean(self.str_timezone)

        self = Helper().RESULT__updateTime(self)
        if not self.str_slug:
            self.str_slug = 'event/'+(str(self.datetime_start.date(
            ))+'-' if self.datetime_start else '')+re.sub('[\W_]+', '', self.str_name_en_US.lower())
            counter = 0
            while Event.objects.filter(str_slug=self.str_slug).exists() == True:
                counter += 1
                self.str_slug = 'event/'+(str(self.datetime_start.date())+'-' if self.datetime_start else '')+re.sub(
                    '[\W_]+', '', self.str_name_en_US.lower())+str(counter)

        Log().print('--> Save lat/lon if not exist yet')
        if self.str_location and not self.float_lat:
            self.str_location, self.float_lat, self.float_lon = get_lat_lon_and_location(
                self.str_location)

        super(Event, self).save(*args, **kwargs)

        Log().print('--> Save hosts')
        if not self.many_hosts.exists():
            EVENTS_HOSTS_OVERWRITE = Config(
                'EVENTS.EVENTS_HOSTS_OVERWRITE').value
            # search in predefined event hosts in YOURHACKERSPACE
            for event_name in EVENTS_HOSTS_OVERWRITE:
                if event_name in self.str_name_en_US:
                    for host_name in EVENTS_HOSTS_OVERWRITE[event_name]:
                        host = Person.objects.QUERYSET__by_name(host_name)
                        if host:
                            self.many_hosts.add(host)
Пример #7
0
    def __init__(self, request=None):
        from _apis.models import Notify
        from _database.models import Helper, Event, Space, Guilde, Person
        from _setup.models import Config
        from _setup.models import Secret
        from django.http import JsonResponse

        DOMAIN = Config('WEBSITE.DOMAIN').value

        int_UNIXtime_event_start = Helper().INT__UNIX_from_date_and_time_STR(
            request.POST.get('date', None), request.POST.get('time', None))
        int_minutes_duration = Helper().INT__duration_minutes(
            request.POST.get('duration', None))

        try:
            if request.FILES[
                    'images[0]'].content_type == 'image/jpeg' or request.FILES[
                        'images[0]'].content_type == 'image/png':
                image = request.FILES['images[0]']
            else:
                image = None
        except:
            image = None

        uploaded_photo_url = request.POST.get('photo', None)

        new_event = Event(
            boolean_approved=request.user.is_authenticated,
            str_name_en_US=request.POST.get('name_english', None),
            str_name_he_IL=request.POST.get('name_hebrew', None),
            int_UNIXtime_event_start=int_UNIXtime_event_start,
            int_minutes_duration=int_minutes_duration,
            int_UNIXtime_event_end=int_UNIXtime_event_start +
            (60 * int_minutes_duration),
            url_featured_photo=uploaded_photo_url
            if 'https' in uploaded_photo_url else None,
            image_featured_photo=image,
            text_description_en_US=request.POST.get('description_english',
                                                    None),
            text_description_he_IL=request.POST.get('description_hebrew',
                                                    None),
            one_space=Space.objects.QUERYSET__by_name(
                request.POST.get('space', None)),
            one_guilde=Guilde.objects.QUERYSET__by_name(
                request.POST.get('guilde', None)),
            str_crowd_size=request.POST.get('expected_crowd', None),
            str_welcomer=request.POST.get('event_welcomer', None),
            boolean_looking_for_volunteers=True if request.POST.get(
                'volunteers', None) == 'yes' else False)
        if request.POST.get('location', None):
            if request.POST.get('location',
                                None) != Config('BASICS.NAME').value:
                if request.POST.get('location', None).lower() == 'online':
                    new_event.boolean_online_meetup = True
                else:
                    new_event.str_location = request.POST.get('location', None)

        if request.POST.get('repeating', None):
            # if repeating, mark as such and auto generate new upcoming events with "update_database" command
            str_repeating_how_often = request.POST.get('repeating', None)
            str_repeating_up_to = request.POST.get('repeating_up_to', None)

            if str_repeating_how_often and str_repeating_how_often != '':
                new_event.int_series_startUNIX = new_event.int_UNIXtime_event_start
                new_event.str_series_repeat_how_often = str_repeating_how_often

            if str_repeating_up_to and str_repeating_up_to != '':
                new_event.int_series_endUNIX = Helper(
                ).INT__UNIX_from_date_and_time_STR(
                    str_repeating_up_to, request.POST.get('time', None))

        new_event.save()

        hosts = request.POST.get('hosts', None)
        if hosts:
            if hosts.startswith(','):
                hosts = hosts[1:]
            hosts = hosts.split(',')
            for host in hosts:
                new_event.many_hosts.add(Person.objects.by_url_discourse(host))

        # if loggedin user: share event to other platforms (Meetup, Discourse, etc.)
        if request.user.is_authenticated:
            new_event.create_discourse_event()
            new_event.create_meetup_event()

        # else (if event created via live website) inform via slack about new event and give community chance to delete it or confirm it
        elif 'HTTP_HOST' in request.META and request.META[
                'HTTP_HOST'] == DOMAIN:
            Notify().send(
                'A website visitor created a new event via our website.\n' +
                'If no one deletes it within the next 24 hours, it will be automatically published and appears in our website search'
                + (', meetup group' if Secret('MEETUP.ACCESS_TOKEN').
                   value else '') +
                (' and discourse' if Secret('DISCOURSE.API_KEY').exists ==
                 True else '') + '.\n' +
                '🚫-> Does this event already exist or is it spam? Open on the following event link and click "Delete event".\n'
                +
                '✅-> You have a user account for our website and want to publish the event directly? Open on the following event link and click "Approve event".\n'
                + 'https://' + DOMAIN + '/' + new_event.str_slug)
        else:
            print(
                '--> Request not sent via hackerspace domain. Skipped notifying via Slack.'
            )

        # if event is repeating, create upcoming instances
        new_event = new_event.create_upcoming_instances()

        # if user is signed in and event autoapproved - direct to event page, else show info
        self.value = JsonResponse({'url_next': '/' + new_event.str_slug})
Пример #8
0
 def save(self, *args, **kwargs):
     from _database.models import Helper
     self = Helper().RESULT__updateTime(self)
     super(Consensus, self).save(*args, **kwargs)
Пример #9
0
    def __init__(self, what, request):
        from django.http import JsonResponse
        from _database.models import Helper, MeetingNote, Event, Project, Space, Machine, Guilde, Consensus
        if what and request.GET.get('from', None):
            if what == 'meeting_notes':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'meetings/meetings_list.html',
                    MeetingNote.objects.past())
            elif what == 'events':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'results_list_entries.html',
                    Event.objects.QUERYSET__upcoming())
            elif what == 'projects':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'results_list_entries.html',
                    Project.objects.latest())
            elif what == 'spaces':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'results_list_entries.html', Space.objects.all())
            elif what == 'machines':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'results_list_entries.html',
                    Machine.objects.all())
            elif what == 'guildes':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'results_list_entries.html', Guilde.objects.all())
            elif what == 'consensus':
                response = Helper().JSON_RESPONSE_more_results(
                    request, 'consensus_items_entries.html',
                    Consensus.objects.latest())
            elif what == 'photos':
                response = Helper().JSON_RESPONSE_more_photos(request)
        else:
            response = JsonResponse({'error': 'Request incomplete or wrong'})
            response.status_code = 404

        self.value = response