def delete_post(post_url): log('delete_post()') if BOOLEAN__key_exists('DISCOURSE.API_KEY') == False: log('--> Failed: DISCOURSE.API_KEY not set') return None # get ID of post response = requests.get(post_url) if response.status_code != 200: log('--> Couldn\'t find post on Discourse. Skipped deleting.') return False topic_id = response.url.split('/')[-1] response = requests.delete(DISCOURSE_URL+'/t/'+topic_id+'.json', headers={ 'content-type': 'application/json' }, params={ 'api_key': STR__get_key('DISCOURSE.API_KEY'), 'api_username': STR__get_key('DISCOURSE.API_USERNAME') }) if response.status_code == 200: log('--> Deleted') return True else: log('--> Not deleted') print(response.status_code) print(response.json()) return False
def create_post(str_headline, str_text, str_category): log('create_post()') from html import unescape import emoji if BOOLEAN__key_exists('DISCOURSE.API_KEY') == False: log('--> Failed: DISCOURSE.API_KEY not set') return None response = requests.post(DISCOURSE_URL+'posts.json', headers={ 'content-type': 'application/json' }, params={ 'api_key': STR__get_key('DISCOURSE.API_KEY'), 'api_username': STR__get_key('DISCOURSE.API_USERNAME'), 'title': emoji.get_emoji_regexp().sub(u'', unescape(str_headline)), 'raw': str_text, 'category': get_category_id(str_category) # TODO add event details # 'event': {'start': '2019-12-13T15:00:00+00:00', 'end': '2019-12-13T19:00:00+00:00'} }) if response.status_code == 200: if DISCOURSE_URL.endswith('/'): url = DISCOURSE_URL+'t/'+str(response.json()['topic_id']) log('--> Created Discourse post: '+url) return url else: url = DISCOURSE_URL+'/t/'+str(response.json()['topic_id']) log('--> Created Discourse post: '+url) return url else: print(response.status_code) print(response.json())
def upload_view(request,what): log('upload_view(request,what={})'.format(what)) if what == 'event-image': if request.FILES['images[0]'].content_type!='image/jpeg' and request.FILES['images[0]'].content_type!='image/png': response = JsonResponse({ 'notification': get_template('components/notification.html').render({ 'text_message': 'Please upload a JPG or PNG image.', 'str_icon': 'error' })}) response.status_code = 500 else: import boto3 import os,sys if BOOLEAN__key_exists('AWS.ACCESS_KEYID') and BOOLEAN__key_exists('AWS.SECRET_ACCESS_KEY') and BOOLEAN__key_exists('AWS.S3.BUCKET_NAME') and BOOLEAN__key_exists('AWS.S3.SERVER_AREA'): AWS_S3_URL = STR__get_key('AWS.S3.BUCKET_NAME')+'.s3-' + \ STR__get_key('AWS.S3.SERVER_AREA')+'.amazonaws.com' session = boto3.Session( aws_access_key_id=STR__get_key('AWS.ACCESS_KEYID'), aws_secret_access_key=STR__get_key('AWS.SECRET_ACCESS_KEY'), ) s3 = session.resource('s3') image = request.FILES['images[0]'] s3.Bucket(STR__get_key('AWS.S3.BUCKET_NAME')).put_object(Key=image.name, Body=image,ACL='public-read') response = JsonResponse({'url_image': 'https://'+AWS_S3_URL+'/'+image.name}) else: log('--> AWS secrets are missing. Couldnt upload image.') response = JsonResponse({'url_image': None}) log('--> return response') return response
def import_from_discourse(self): print('import_from_discourse()') from hackerspace.models import Person from dateutil import parser from getKey import STR__get_key import time import requests from asci_art import show_message DISCOURSE_URL = STR__get_key('DISCOURSE.DISCOURSE_URL') if DISCOURSE_URL: show_message( '✅ Found DISCOURSE.DISCOURSE_URL - start importing Consensus Items from Discourse.' ) time.sleep(2) if requests.get(DISCOURSE_URL + '/c/consensus-items').status_code == 200: consensus_items = get_category_posts( category='consensus-items', all_pages=True) print('process {} consensus-items'.format( len(consensus_items))) for consensus_item in consensus_items: if consensus_item[ 'title'] != 'About the Consensus Items category': Consensus().create( json_content={ 'str_name_en_US': consensus_item['title'], 'url_discourse': STR__get_key('DISCOURSE.DISCOURSE_URL') + 't/' + consensus_item['slug'], 'text_description_en_US': consensus_item['excerpt'], 'int_UNIXtime_created': round( datetime.timestamp( parser.parse( consensus_item['created_at']))), 'one_creator': Person.objects.get_discourse_creator( consensus_item['slug']), }) else: show_message( 'WARNING: Can\'t find the "consensus-items" category on your Discourse. Skipped importing Consensus Items from Discourse.' ) time.sleep(4) else: show_message( 'WARNING: Can\'t find the DISCOURSE.DISCOURSE_URL in your secrets.json. Will skip Discourse for now.' ) time.sleep(4)
def create_meetup_event(self): # API Doc: https://www.meetup.com/meetup_api/docs/:urlname/events/#create log('event.create_meetup_event()') import requests from getKey import STR__get_key from getConfig import get_config if not STR__get_key('MEETUP.ACCESS_TOKEN'): log('--> No MEETUP.ACCESS_TOKEN') log('--> return None') return None response = requests.post('https://api.meetup.com/'+get_config('EVENTS.MEETUP_GROUP')+'/events', params={ 'access_token': STR__get_key('MEETUP.ACCESS_TOKEN'), 'sign': True, 'announce': False, 'publish_status':'draft', 'description': self.text_description_en_US, 'duration':self.int_minutes_duration*60*1000, 'event_hosts':None,# TODO figure out meetup user IDs and how to add them here 'fee':{ 'accepts':None, # TODO add option for paid events later 'amount':None, 'currency':None, 'refund_policy':None }, 'guest_limit':2, # from 0 to 2 'how_to_find_us':get_config('PHYSICAL_SPACE.ADDRESS')['HOW_TO_FIND_US'], 'lat':self.float_lat, 'lon':self.float_lon, 'name':self.str_name_en_US, 'self_rsvp':False, 'time': self.int_UNIXtime_event_start, 'venue_id':None, #TODO figure out how to get venue id 'venue_visibility':None #TODO }) #TODO returns 400 response - scope_error: Insufficient oauth scope if response.status_code==200: self.url_meetup_event = response.json()['link'] self.save() log('--> return event') else: log('--> '+str(response.status_code)+' response: '+str(response.json())) return self
def QUERYSET__by_name(self, name): if not name or name == '': return None from django.db.models import Q from getKey import STR__get_key return self.filter( Q(url_discourse=STR__get_key('DISCOURSE.DISCOURSE_URL') + 'u/' + name) | Q(str_name_en_US__icontains=name)).first()
def BOOLEAN__API_access_works(): log('BOOLEAN__API_access_works()') if BOOLEAN__key_exists('DISCOURSE.API_KEY') == False: log('--> Failed: DISCOURSE.API_KEY not set') return None response = requests.get(DISCOURSE_URL+'notifications.json', headers={ 'content-type': 'multipart/form-data' }, params={ 'api_key': STR__get_key('DISCOURSE.API_KEY'), 'api_username': STR__get_key('DISCOURSE.API_USERNAME'), }) if response.status_code == 200: return True else: print(response.status_code) print(response.json()) return False
def import_from_discourse(self): print('import_from_discourse()') from hackerspace.models import Person from hackerspace.APIs.discourse import get_category_posts from datetime import datetime from dateutil import parser from getKey import STR__get_key from asci_art import show_message import time import requests DISCOURSE_URL = STR__get_key('DISCOURSE.DISCOURSE_URL') if DISCOURSE_URL: show_message( '✅ Found DISCOURSE.DISCOURSE_URL - start importing projects from Discourse.') time.sleep(2) if requests.get(DISCOURSE_URL+'/c/projects').status_code == 200: projects = get_category_posts( category='projects', all_pages=True) log('--> process {} projects'.format(len(projects))) for project in projects: if project['title'] != 'About the Projects category': Project().create(json_content={ 'str_name_en_US': project['title'], 'url_featured_photo': project['image_url'] if project['image_url'] and '/uploads' in project['image_url'] else None, 'url_discourse': STR__get_key('DISCOURSE.DISCOURSE_URL') + 't/'+project['slug'], 'text_description_en_US': project['excerpt'] if 'excerpt' in project else None, 'one_creator': Person.objects.get_discourse_creator(project['slug']), 'int_UNIXtime_created': round(datetime.timestamp(parser.parse(project['created_at']))) } ) else: show_message( 'WARNING: Can\'t find the "projects" category on your Discourse. Skipped importing Consensus Items from Discourse.') time.sleep(4) else: show_message( 'WARNING: Can\'t find the DISCOURSE.DISCOURSE_URL in your secrets.json. Will skip Discourse for now.') time.sleep(4)
def send_message(message, channel='#general'): log('send_message(message, channel={})'.format(channel)) if BOOLEAN__key_exists('SLACK.API_TOKEN') == False: log('--> KEY MISSING: SLACK.API_TOKEN not defined. Couldnt sent notification via Slack.' ) else: client = slack.WebClient(token=STR__get_key('SLACK.API_TOKEN')) # see https://github.com/slackapi/python-slackclient#sending-a-message-to-slack response = client.chat_postMessage(channel=channel, text=message) if response['ok'] == True: log('--> Success! Sent message to Slack') else: log('--> Failed!')
def delete_photo(self): log('event.delete_photo()') import boto3 from getKey import STR__get_key # if url_featured_photo - delete on AWS if self.url_featured_photo and 'amazonaws.com' in self.url_featured_photo: s3 = boto3.client('s3') s3.delete_object(Bucket=STR__get_key('AWS.S3.BUCKET_NAME'), Key=self.url_featured_photo.split('amazonaws.com/')[1]) self.url_featured_photo = None super(Event, self).save() return self # else delete in local folder elif self.image_featured_photo: self.image_featured_photo.delete(save=True) return self
def import_from_discourse(self): from hackerspace.APIs.discourse import get_users from getKey import STR__get_key import time import requests from asci_art import show_message DISCOURSE_URL = STR__get_key('DISCOURSE.DISCOURSE_URL') if DISCOURSE_URL: show_message( '✅ Found DISCOURSE.DISCOURSE_URL - start importing persons from Discourse.' ) time.sleep(2) if requests.get(DISCOURSE_URL).status_code == 200: users = get_users() log('--> process {} users'.format(len(users))) for user in users: Person().create( json_content={ 'str_name_en_US': user['user']['name'] if user['user']['name'] and user['user']['name'] != '' else user['user'] ['username'], 'url_featured_photo': DISCOURSE_URL + user['user'] ['avatar_template'].replace('{size}', '240'), 'url_discourse': DISCOURSE_URL + 'u/' + user['user']['username'], 'text_description_en_US': user['user']['title'] if user['user']['title'] != '' else None }) else: show_message( 'WARNING: I can\'t access your Discourse page. Is the URL correct? Will skip Discourse for now.' ) time.sleep(4) else: show_message( 'WARNING: Can\'t find the DISCOURSE.DISCOURSE_URL in your secrets.json. Will skip Discourse for now.' ) time.sleep(4)
https://docs.djangoproject.com/en/2.2/ref/settings/ """ import mimetypes import os from getKey import STR__get_key # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = STR__get_key('DJANGO.SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False SECURE_SSL_REDIRECT = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True ALLOWED_HOSTS = ['*'] # Application definition INSTALLED_APPS = [ 'hackerspace', 'django.contrib.admin',
def new_view(request): log('new_view(request)') if request.method == 'GET' and request.GET.get('what', None) == 'meeting': new_meeting = MeetingNote() new_meeting.save() response = JsonResponse( { 'html': get_template( 'components/body/meetings/current_meeting.html').render({ 'language':getLanguage(request), 'current_meeting': new_meeting }) } ) elif request.method == 'POST' and request.POST.get('what', None) == 'event': from hackerspace.APIs.slack import send_message from hackerspace.Website.views_helper_functions import INT__UNIX_from_date_and_time_STR,INT__duration_minutes DOMAIN = get_config('WEBSITE.DOMAIN') int_UNIXtime_event_start = INT__UNIX_from_date_and_time_STR(request.POST.get('date',None),request.POST.get('time',None)) int_minutes_duration = 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)!=get_config('BASICS.NAME'): 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 = 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: send_message( '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 STR__get_key('MEETUP.ACCESS_TOKEN') else '')+(' and discourse' if BOOLEAN__key_exists('DISCOURSE.API_KEY')==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: log('--> 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 response = JsonResponse( { 'url_next': '/'+new_event.str_slug } ) log('--> return response') return response
def get_view_response(request, page, sub_page, hashname): context = { 'view': page+'_view', 'in_space': True if request.COOKIES.get('in_space') or request.GET.get('in_space',None)=='True' else False, 'hash': hashname, 'ADMIN_URL': STR__get_key('DJANGO.ADMIN_URL'), 'user': request.user, 'language': getLanguage(request), 'auto_search':request.GET.get('search',None) } if page == 'landingpage': return {**context, **{ 'slug': '/', 'page_git_url': '/tree/master/hackerspace/Website/templates/landingpage_view.html', 'page_name': get_config('BASICS.NAME'), 'page_description': make_description_sentence(), 'is_open_status': getOpenNowStatus(context['language']), 'upcoming_events': Event.objects.QUERYSET__upcoming()[:5], 'photos': Photo.objects.latest()[:33] }} elif page == 'values': return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/values_view.html', 'page_name': get_config('BASICS.NAME')+' | Values', 'page_description': 'Our values at '+get_config('BASICS.NAME') }} elif page == 'meetings': return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/meetings_view.html', 'page_name': get_config('BASICS.NAME')+' | Meetings', 'page_description': 'Join our weekly meetings!', 'current_meeting': MeetingNote.objects.current(), 'next_meeting': Event.objects.QUERYSET__next_meeting(), 'past_meetings': MeetingNote.objects.past()[:10] }} elif page == 'meeting': selected = MeetingNote.objects.filter( text_date = sub_page).first() return {**context, **{ 'slug': '/meeting/'+selected.text_date, 'page_git_url': '/tree/master/hackerspace/Website/templates/meeting_view.html', 'page_name': get_config('BASICS.NAME')+' | Meeting | '+selected.text_date, 'page_description': 'Join our weekly meetings!', 'selected': selected, 'next_meeting': Event.objects.QUERYSET__next_meeting(), 'past_meetings': MeetingNote.objects.past(selected)[:10] }} elif page == 'meeting_present': return {**context, **{ 'slug': '/meeting/present', 'page_name': get_config('BASICS.NAME')+' | Meeting | Presentation mode', 'page_description': 'Join our weekly meetings!', 'current_meeting': MeetingNote.objects.current() }} elif page == 'guildes': all_results=Guilde.objects.all()[:10] return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/results_list.html', 'page_name': get_config('BASICS.NAME')+' | Guildes', 'page_description': 'Join a guilde at '+get_config('BASICS.NAME')+'!', 'headline': 'Guildes', 'description': 'A guilde is ...', 'wiki_url': None, 'add_new_requires_user': True, 'addnew_url': '/{}/hackerspace/guilde/add/'.format(STR__get_key('DJANGO.ADMIN_URL')), 'addnew_text': 'Add guilde', 'all_results': all_results if all_results else True, 'results_count': Guilde.objects.count(), 'show_more': page }} elif page == 'guilde': if 'guilde/' not in sub_page: sub_page='guilde/'+sub_page selected=Guilde.objects.filter(str_slug = sub_page).first() return {**context, **{ 'slug': '/guilde/'+sub_page, 'page_git_url': '/tree/master/hackerspace/Website/templates/guilde_view.html', 'page_name': get_config('BASICS.NAME')+' | Guilde | '+selected.str_name_en_US, 'page_description': 'Join our weekly meetings!', 'selected': selected }} elif page == 'spaces': all_results=Space.objects.all()[:10] return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/results_list.html', 'page_name': get_config('BASICS.NAME')+' | Spaces', 'page_description': get_config('BASICS.NAME')+' has many awesome spaces!', 'headline': 'Spaces', 'description': 'At SPACE fellow hackers created all kind of awesome spaces...', 'wiki_url': None, 'add_new_requires_user': True, 'addnew_url': '/{}/hackerspace/space/add/'.format(STR__get_key('DJANGO.ADMIN_URL')), 'addnew_text': 'Add space', 'all_results': all_results if all_results else True, 'results_count': Space.objects.count(), 'show_more': page }} elif page == 'space': if 'space/' not in sub_page: sub_page='space/'+sub_page selected=Space.objects.filter(str_slug = sub_page).first() return {**context, **{ 'slug': '/space/'+sub_page, 'page_git_url': '/tree/master/hackerspace/Website/templates/space_view.html', 'page_name': get_config('BASICS.NAME')+' | Space | '+selected.str_name_en_US, 'page_description': selected.text_description_en_US, 'selected': selected }} elif page == 'machines': all_results=Machine.objects.all()[:10] return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/results_list.html', 'page_name': get_config('BASICS.NAME')+' | Machines', 'page_description': get_config('BASICS.NAME')+' has all kinds of awesome machines!', 'headline': 'Machines', 'description': 'We have many useful machines ...', 'wiki_url': None, 'add_new_requires_user': True, 'addnew_url': '/{}/hackerspace/machine/add/'.format(STR__get_key('DJANGO.ADMIN_URL')), 'addnew_text': 'Add machine', 'all_results': all_results if all_results else True, 'results_count': Machine.objects.count(), 'show_more': page }} elif page == 'machine': if 'machine/' not in sub_page: sub_page='machine/'+sub_page selected=Machine.objects.filter(str_slug = sub_page).first() return {**context, **{ 'slug': '/machine/'+sub_page, 'page_git_url': '/tree/master/hackerspace/Website/templates/machine_view.html', 'page_name': get_config('BASICS.NAME')+' | Machine | '+selected.str_name_en_US, 'page_description': selected.text_description_en_US, 'selected': selected }} elif page == 'projects': all_results=Project.objects.latest()[:10] return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/results_list.html', 'page_name': get_config('BASICS.NAME')+' | Projects', 'page_description': 'People at '+get_config('BASICS.NAME')+' created all kinds of awesome projects!', 'headline': 'Projects', 'description': 'At SPACE fellow hackers created awesome projects...', 'wiki_url': None, 'add_new_requires_user': False, 'addnew_url': '{}c/projects/'.format(STR__get_key('DISCOURSE.DISCOURSE_URL')), 'addnew_text': 'Add project', 'all_results': all_results if all_results else True, 'results_count': Project.objects.count(), 'show_more': page }} elif page == 'project': if 'project/' not in sub_page: sub_page='project/'+sub_page selected=Project.objects.filter(str_slug = sub_page).first() return {**context, **{ 'slug': '/project/'+sub_page, 'page_git_url': '/tree/master/hackerspace/Website/templates/project_view.html', 'page_name': get_config('BASICS.NAME')+' | Project | '+selected.str_name_en_US, 'page_description': selected.text_description_en_US, 'selected': selected }} elif page == 'consensus': return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/consensus_view.html', 'page_name': get_config('BASICS.NAME')+' | Big-C consensus items', 'page_description': 'When you want to do something that would drastically change '+get_config('BASICS.NAME')+' (or need a lot of money from Noisebridge for a project) - suggest a Big-C consensus item!', 'all_current_items': Consensus.objects.current(), 'all_current_items_count': Consensus.objects.current().count(), 'all_archived_items': Consensus.objects.archived(), 'all_archived_items_count': Consensus.objects.archived().count(), }} elif page == 'photos': return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/photos_view.html', 'page_name': get_config('BASICS.NAME')+' | Photos', 'page_description': 'Explore '+get_config('BASICS.NAME')+'\'s history in photos!', 'photos': Photo.objects.latest()[:30], }} elif page == 'events': all_results=Event.objects.QUERYSET__upcoming()[:10] return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/results_list.html', 'page_name': get_config('BASICS.NAME')+' | Events', 'page_description': 'At '+get_config('BASICS.NAME')+' we have all kinds of cool events - organized by your fellow hackers!', 'headline': 'Events', 'description': 'SPACE is a place where people come together ...', 'add_new_requires_user': False, 'addnew_url': '/event/new', 'addnew_text': 'Organize an event', 'addnew_target': 'same_tab', 'addnew_menu_selected': 'menu_h_events', 'all_results': all_results if all_results else True, 'results_count': Event.objects.count(), 'show_more': page }} elif page == 'event': if 'event/' not in sub_page: sub_page='event/'+sub_page selected=Event.objects.filter(str_slug = sub_page).first() return {**context, **{ 'slug': '/event/'+sub_page, 'page_git_url': '/tree/master/hackerspace/Website/templates/event_view.html', 'page_name': get_config('BASICS.NAME')+' | Event | '+selected.str_name_en_US, 'page_description': selected.text_description_en_US, 'selected': selected, 'photos': Photo.objects.latest()[:33] }} elif page == 'event_banner': if 'event/' not in sub_page: sub_page='event/'+sub_page selected=Event.objects.filter(str_slug = sub_page).first() return {**context, **{ 'selected': selected, }} elif page == 'event_new': from django.middleware.csrf import get_token EVENTS_SPACE_DEFAULT=get_config('EVENTS.EVENTS_SPACE_DEFAULT') return {**context, **{ 'slug': '/'+page, 'page_git_url': '/tree/master/hackerspace/Website/templates/event_new_view.html', 'page_name': get_config('BASICS.NAME')+' | New event', 'page_description': 'Organize an event at '+get_config('BASICS.NAME'), 'upcoming_events': Event.objects.QUERYSET__upcoming()[:4], 'default_space': Space.objects.filter(str_name_en_US = EVENTS_SPACE_DEFAULT).first(), 'all_spaces': Space.objects.exclude(str_name_en_US = EVENTS_SPACE_DEFAULT), 'all_guildes': Guilde.objects.all(), 'csrf_token': get_token(request) }}
def get_key(str_key_name): return STR__get_key(str_key_name)
1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from hackerspace.Website import views from django.views.generic.base import RedirectView from getKey import STR__get_key from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path(STR__get_key('DJANGO.ADMIN_URL') + '/', admin.site.urls), path('', views.landingpage_view, name='landingpage'), path('values', views.values_view, name='values'), path('values/', RedirectView.as_view(url='values', permanent=False), name='values/'), path('ourvalues', RedirectView.as_view(url='values', permanent=False), name='ourvalues/'), path('ourvalues/', RedirectView.as_view(url='values', permanent=False), name='ourvalues'), path('meetings', views.meetings_view, name='meetings'), path('meeting', RedirectView.as_view(url='meetings', permanent=False), name='meeting'),
import requests from getKey import STR__get_key, BOOLEAN__key_exists from hackerspace.log import log # see Discourse API - https://docs.discourse.org/ DISCOURSE_URL = STR__get_key('DISCOURSE.DISCOURSE_URL') def discourse_search(query, limit=5): log('discourse_search()') results = [] response_json = requests.get( DISCOURSE_URL+'/search/query.json?term='+query).json() if 'topics' in response_json: for post in response_json['topics']: results.append({ 'icon': 'discourse', 'name': post['title'], 'url': DISCOURSE_URL+'/t/'+str(post['id']) }) return results def BOOLEAN__API_access_works(): log('BOOLEAN__API_access_works()') if BOOLEAN__key_exists('DISCOURSE.API_KEY') == False: log('--> Failed: DISCOURSE.API_KEY not set') return None response = requests.get(DISCOURSE_URL+'notifications.json',