Beispiel #1
0
def get_members(request, entity, entity_name):

    # which entity type is the user requesting members for?
    if entity == "groups":
        entity_obj = Group.objects.get(name=entity_name)
    elif entity == "companies":
        entity_obj = Company.objects.get(name=entity_name)

    # get the members belonging to this entity
    if entity_obj:
        members = Member.get_members(entity_obj)
    else:
        members = ""

    members = Member.sort_by_role(members)

    # serialize each member's data as JSON
    members_data = []
    for member in members:
        members_data.append({
            'role': member.role,
            'username': member.user.username,
            'full_name': member.user.get_full_name(),
            'avatar': member.user.avatar_url,
            'is_consultant': member.user.is_consultant()
        })

    data = {
        'members': members_data,
    }

    return JsonResponse(data)
Beispiel #2
0
    def get(self, request, company):
        """
        User is editing profile...
        """

        try:
            company_obj = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        entity_obj = Entity.objects.get(company=company_obj)
        events = Event.get_entity_events(entity_obj)
        location = Nominatim.geocode(self=Nominatim(),
                                     query=company_obj.address)

        return render(
            request, 'company/profile/profile.html', {
                'company': company_obj,
                'events': events,
                'lat': location.latitude,
                'lon': location.longitude,
                'is_owner': Member.is_owner(request.user, company_obj),
                'is_editor': Member.is_editor(request.user, company_obj),
            })
Beispiel #3
0
    def post(self, request, company):
        try:
            company = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        # is the user an editor (or owner)?
        if not Member.is_editor(request.user, company):
            return page_not_found(request,
                                  exception=None,
                                  template_name='403.html')

        form = EditCompanyForm(request.POST,
                               request.FILES or None,
                               instance=company)

        # save company if valid
        if form.is_valid():
            form.save()
            messages.success(
                request, 'The company profile has successfully been updated.')
            form = EditCompanyForm()

        return render(
            request, 'company/edit_comp_profile.html', {
                'company': company,
                'is_owner': Member.is_owner(request.user, company),
                'is_editor': Member.is_editor(request.user, company),
                'form': form
            })
Beispiel #4
0
def remove_member(request, entity, entity_name, username):
    
    if entity == "groups":
        entity_obj = Group.objects.get(name=entity_name)
    elif entity == "companies":
        entity_obj = Company.objects.get(name=entity_name)

    user = request.user
    data = dict()
    
    if entity_obj:
        if not Member.is_owner(user, entity_obj):
            data['error'] = "403"
        
        else:
            try:
                member = User.objects.get(username=username)
                member = Member.objects.filter(entity=entity_obj).get(user=member)
                member.delete()

                data['error'] = "200"
            except ObjectDoesNotExist:
                data['error'] = "404"

    else:
        data['error'] = "404"
    
    return JsonResponse(data)
Beispiel #5
0
def add_member(request, entity, entity_name, username):
    """
    Adds a new member to some entity
    """

    if entity == "groups":
        entity_obj = Group.objects.get(name=entity_name)
    elif entity == "companies":
        entity_obj = Company.objects.get(name=entity_name)

    user = request.user
    data = dict()

    if entity_obj:
        if not Member.is_owner(user, entity_obj):
            data['error'] = "403"

        else:
            try:
                new_member = User.objects.get(username=username)
                Member.objects.create(entity=entity_obj, user=new_member, role=MemberRoles.MEMBER)
                data['error'] = "200"
            except ObjectDoesNotExist:
                data['error'] = "404"

    else:
        data['error'] = "404"

    return JsonResponse(data)
Beispiel #6
0
    def get(self, request):

        try:
            search_term = request.GET.get('search')

            # get all results from companies & consultants
            companies = Company.search_companies(search_term)

        except KeyError:
            # get all companies and consultants
            companies = Company.search_companies(None)

        company_filter = CompanyFilter(request.GET, queryset=companies)
        results = company_filter.qs

        paginator = Paginator(results, 8)
        page = request.GET.get('page')
        show_businesses = paginator.get_page(page)

        return render(request, 'companies.html', {
            'company': Member.get_user_company(request.user),
            'show_sidepane': True,
            'companies': show_businesses,
            'page': page,
            'filter': company_filter,
        })
Beispiel #7
0
    def post(self, request, group):

        # get the group object
        try:
            group = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        # is the user an editor (or owner)?
        if not Member.is_editor(request.user, group):
            return page_not_found(request,
                                  exception=None,
                                  template_name='403.html')

        form = EditGroupForm(request.POST,
                             request.FILES or None,
                             instance=group)

        # save group if valid
        if form.is_valid():
            form.save()
            messages.success(
                request, 'The group profile has successfully been updated.')
            form = EditGroupForm()

        return HttpResponseRedirect(
            reverse('entity:group_profile_edit', args=[group.name]))
Beispiel #8
0
    def get(self, request, company):
        try:
            company_obj = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        if not Member.is_editor(request.user, company_obj):
            return page_not_found(request.path, exception=None, template_name='403.html')

        form = EditCompanyForm(instance=company_obj)

        return render(request, 'company/edit_comp_profile.html', {
            'company': company_obj,
            'is_owner': Member.is_owner(request.user, company_obj),
            'is_editor': Member.is_editor(request.user, company_obj),
            'form': form,
        })
Beispiel #9
0
    def get(self, request, group):
        """
        User is viewing a profile
        """

        try:
            group_obj = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        form = EditGroupForm(instance=group_obj)

        return render(request, 'group/edit_profile.html', {
            'group': group_obj,
            'is_owner': Member.is_owner(request.user, group_obj),
            'is_editor': Member.is_editor(request.user, group_obj),
            'form': form,
        })
Beispiel #10
0
    def test_editors(self):
        # get editors & owners
        company = Company.objects.get(name="Activision")
        editors = Member.get_members(company)

        # there are two editors (1 owner, 1 editor)
        self.assertTrue(len(editors) == 2)
        # the users are editors
        self.assertTrue(Member.is_editor(editors[0].user, company))
        self.assertTrue(Member.is_editor(editors[1].user, company))

        # test company applications
        self.assertEqual(
            company.application.date_submitted,
            datetime.date.today()
        )

        company.application.approve(
            user=editors[0].user,
            comment="A well made application, approved!"
        )
        self.assertEqual(
            company.application.status,
            Application.StatusType.Approved
        )

        print("""
            Company test successful. A single company was created,
            company.name=%s
            company.size=%d
            total company editors: %d
            editor #1: %s
            editor #2: %s
            A company application was also created with this company,
            company.application.date_submitted=%s
            company.application.date_approved=%s
            company.application.approved_by=%s
            company.application.comment=%s
            """ % (
                company.name, company.size, len(editors), editors[0], editors[1],
                company.application.date_submitted, company.application.date_approved, company.application.approved_by,
                company.application.comment
            )
        )
Beispiel #11
0
    def test_editors(self):
        # get group & its members
        group = Group.objects.get(name="PUGB")
        editors = Member.get_members(group)

        # there are two editors (1 owner, 1 editor)
        self.assertTrue(len(editors) == 2)
        # the users are editors
        self.assertTrue(Member.is_editor(editors[0].user, group))
        self.assertTrue(Member.is_editor(editors[1].user, group))

        # test company applications
        self.assertEqual(
            group.application.date_submitted,
            datetime.date.today()
        )

        group.application.approve(
            user=editors[0].user,
            comment="A well made application, approved!"
        )
        self.assertEqual(
            group.application.status,
            Application.StatusType.Approved
        )

        print("""
            Group test successful. A single group was created,
            group.name=%s
            total group editors: %d
            editor #1: %s
            editor #2: %s
            A group application was also created with this group,
            group.application.date_submitted=%s
            group.application.date_approved=%s
            group.application.approved_by=%s
            group.application.comment=%s
            """ % (
                group.name, len(editors), editors[0], editors[1],
                group.application.date_submitted, group.application.date_approved, group.application.approved_by,
                group.application.comment
            )
        )
Beispiel #12
0
    def get(self, request):

        # search ---
        search_term = request.GET.get('search')
        if search_term is not None:
            jobs = Job.search_jobs(search_term)

        else:
            jobs = Job.search_jobs(None)
        # ---

        # filters ---
        location = request.GET.get('location')
        company = request.GET.get('company')

        if location is not None:
            jobs = jobs.filter(location=location)

        if company is not None:
            jobs = jobs.filter(company=company)
        # ---

        # pages (6 jobs/page) ---
        paginator = Paginator(jobs, 6)
        page = request.GET.get('page')
        show_jobs = paginator.get_page(page)
        # ---

        create_job_form = JobCreationForm()

        return render(
            request, 'jobs.html', {
                'show_sidepane':
                Member.is_editor_any(request.user)
                ^ Member.is_owner_any(request.user),
                'jobs':
                show_jobs,
                'page':
                page,
                'creation_form':
                create_job_form
            })
Beispiel #13
0
    def get(self, request, event_title, event_id):

        try:
            event = Event.objects.get(pk=event_id)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        entity_obj = event.entity
        location = Nominatim.geocode(self=Nominatim(), query=event.location)

        return render(
            request, 'events/event_details.html', {
                'event': event,
                'is_owner': Member.is_owner(request.user, entity_obj),
                'is_editor': Member.is_editor(request.user, entity_obj),
                'lat': location.latitude,
                'lon': location.longitude
            })
Beispiel #14
0
    def get(self, request, event_title, event_id):

        event = Event.objects.get(pk=event_id)
        form = EditEventForm(instance=event)
        entity_obj = event.entity

        try:
            event_obj = Event.objects.get(pk=event_id)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        return render(
            request, 'events/edit_event.html', {
                'form': form,
                'is_owner': Member.is_owner(request.user, entity_obj),
                'is_editor': Member.is_editor(request.user, entity_obj),
                'event': event_obj,
            })
Beispiel #15
0
    def get(self, request, group):
        """
        User is viewing a profile
        """

        try:
            group_obj = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        entity_obj = Entity.objects.get(group=group_obj)
        events = Event.get_entity_events(entity=entity_obj)

        return render(request, 'group/profile.html', {
            'group': group_obj,
            'events': events,
            'members': Member.get_members(group_obj),
            'is_owner': Member.is_owner(request.user, group_obj),
            'is_editor': Member.is_editor(request.user, group_obj),
        })
Beispiel #16
0
def events(request):
    page = requests.get('https://techevents.nz/pnorth')
    tree = html.fromstring(page.content)
    event = tree.xpath('//div[contains(@class,"event")]')[0]
    event_months = event.xpath('//div[@class="date"]/strong/text()')
    event_days = event.xpath('//div[@class="date"]/big/text()')
    event_times = event.xpath('//div[@class="date"]/text()')
    event_times_new = list(filter(None, [x.strip() for x in event_times]))
    event_head = tree.xpath('//div[@class="body"]/h5/text()')
    event_head_new = list(filter(None, [x.strip() for x in event_head]))
    event_desc = tree.xpath('//div[@class="body"]/p/text()')
    event_urls = tree.xpath('//span[@class="info"]//a/@href')
    all_events = []
    for i in range(0, len(event_months)):
        new_event = {}
        new_event['day'] = event_days[i]
        new_event['month'] = event_months[i]
        new_event['time'] = event_times_new[i]
        new_event['heading'] = event_head_new[i]
        new_event['desc'] = event_desc[i]
        new_event['url'] = event_urls[2 * i]
        all_events.append(new_event)

    # get all events belonging to techpalmy which have not already happened
    techpalmy_events = Event.get_events()

    event_filter = EventSearch(request.GET, queryset=techpalmy_events)
    results = event_filter.qs

    return render(
        request, 'events/rss_feed.html', {
            'show_sidepane':
            Member.is_editor_any(request.user)
            ^ Member.is_owner_any(request.user),
            'tree':
            all_events,
            'events':
            results,
            'filter':
            event_filter,
        })
Beispiel #17
0
    def get(self, request, group):
        """
        User is viewing a profile
        """

        try:
            group_obj = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        form = EditGroupForm(instance=group_obj)

        return render(
            request, 'group/edit_profile.html', {
                'group': group_obj,
                'is_owner': Member.is_owner(request.user, group_obj),
                'is_editor': Member.is_editor(request.user, group_obj),
                'form': form,
            })
Beispiel #18
0
    def get(self, request, company):
        """
        User is editing profile...
        """

        try:
            company_obj = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        entity_obj = Entity.objects.get(company=company_obj)
        events = Event.get_entity_events(entity_obj)
        location = Nominatim.geocode(self=Nominatim(), query=company_obj.address)

        return render(request, 'company/profile/profile.html', {
            'company': company_obj,
            'events': events,
            'lat': location.latitude,
            'lon': location.longitude,
            'is_owner': Member.is_owner(request.user, company_obj),
            'is_editor': Member.is_editor(request.user, company_obj),
        })
Beispiel #19
0
    def get(self, request, company):
        try:
            company_obj = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        if not Member.is_editor(request.user, company_obj):
            return page_not_found(request.path,
                                  exception=None,
                                  template_name='403.html')

        form = EditCompanyForm(instance=company_obj)

        return render(
            request, 'company/edit_comp_profile.html', {
                'company': company_obj,
                'is_owner': Member.is_owner(request.user, company_obj),
                'is_editor': Member.is_editor(request.user, company_obj),
                'form': form,
            })
Beispiel #20
0
def company_remove(request, company):
    try:
        company_obj = Company.objects.get(name=company)
    except ObjectDoesNotExist:
        return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

    if not Member.is_owner(request.user, company_obj):
        return page_not_found(request, exception=None, template_name='403.html')

    remove = get_object_or_404(Company, pk=company_obj.id)
    instance = Company.objects.get(id=company_obj.id)
    instance.delete()
    remove.delete()
    return redirect("/")    
Beispiel #21
0
def group_remove(request, group):
    try:
        group_obj = Group.objects.get(name=group)
    except ObjectDoesNotExist:
        return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

    if not Member.is_owner(request.user, group_obj):
        return page_not_found(request, exception=None, template_name='403.html')

    remove = get_object_or_404(Group, pk=group_obj.id)
    instance = Group.objects.get(id=group_obj.id)
    instance.delete()
    remove.delete()
    return redirect('entity:group_listing')    
Beispiel #22
0
    def get(self, request, group):
        """
        User is viewing a profile
        """

        try:
            group_obj = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request,
                                  exception=ObjectDoesNotExist(),
                                  template_name='404.html')

        entity_obj = Entity.objects.get(group=group_obj)
        events = Event.get_entity_events(entity=entity_obj)

        return render(
            request, 'group/profile.html', {
                'group': group_obj,
                'events': events,
                'members': Member.get_members(group_obj),
                'is_owner': Member.is_owner(request.user, group_obj),
                'is_editor': Member.is_editor(request.user, group_obj),
            })
Beispiel #23
0
    def post(self, request, company):
        try:
            company = Company.objects.get(name=company)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        # is the user an editor (or owner)?
        if not Member.is_editor(request.user, company):
            return page_not_found(request, exception=None, template_name='403.html')

        form = EditCompanyForm(request.POST, request.FILES or None, instance=company)

        # save company if valid
        if form.is_valid():
            form.save()
            messages.success(request, 'The company profile has successfully been updated.')
            form = EditCompanyForm()

        return render(request, 'company/edit_comp_profile.html', {
            'company': company,
            'is_owner': Member.is_owner(request.user, company),
            'is_editor': Member.is_editor(request.user, company),
            'form': form
        })
Beispiel #24
0
    def get(self, request):

        # search ---
        search_term = request.GET.get('search')
        if search_term is not None:
            jobs = Job.search_jobs(search_term)

        else:
            jobs = Job.search_jobs(None)
        # ---

        # filters ---
        location = request.GET.get('location')
        company = request.GET.get('company')

        if location is not None:
            jobs = jobs.filter(location=location)
        
        if company is not None:
            jobs = jobs.filter(company=company)
        # ---

        # pages (6 jobs/page) ---
        paginator = Paginator(jobs, 6)
        page = request.GET.get('page')
        show_jobs = paginator.get_page(page)
        # ---

        create_job_form = JobCreationForm()

        return render(request, 'jobs.html', {
            'show_sidepane': Member.is_editor_any(request.user) ^ Member.is_owner_any(request.user),
            'jobs': show_jobs,
            'page': page,
            'creation_form': create_job_form
        })
Beispiel #25
0
def company_remove(request, company):
    try:
        company_obj = Company.objects.get(name=company)
    except ObjectDoesNotExist:
        return page_not_found(request,
                              exception=ObjectDoesNotExist(),
                              template_name='404.html')

    if not Member.is_owner(request.user, company_obj):
        return page_not_found(request,
                              exception=None,
                              template_name='403.html')

    remove = get_object_or_404(Company, pk=company_obj.id)
    instance = Company.objects.get(id=company_obj.id)
    instance.delete()
    remove.delete()
    return redirect("/")
Beispiel #26
0
def group_remove(request, group):
    try:
        group_obj = Group.objects.get(name=group)
    except ObjectDoesNotExist:
        return page_not_found(request,
                              exception=ObjectDoesNotExist(),
                              template_name='404.html')

    if not Member.is_owner(request.user, group_obj):
        return page_not_found(request,
                              exception=None,
                              template_name='403.html')

    remove = get_object_or_404(Group, pk=group_obj.id)
    instance = Group.objects.get(id=group_obj.id)
    instance.delete()
    remove.delete()
    return redirect('entity:group_listing')
Beispiel #27
0
    def get(self, request):

        try:
            search_term = request.GET.get('search')
            groups = Group.search_groups(search_term)

        except KeyError:
            groups = Group.search_groups(None)

        paginator = Paginator(groups, 6)
        page = request.GET.get('page')
        show_groups = paginator.get_page(page)

        return render(request, 'groups.html', {
            'group': Member.get_user_group(request.user),
            'show_sidepane': True,
            'groups': show_groups,
            'page': page
        })
Beispiel #28
0
    def get(self, request):

        try:
            search_term = request.GET.get('search')
            groups = Group.search_groups(search_term)

        except KeyError:
            groups = Group.search_groups(None)

        paginator = Paginator(groups, 6)
        page = request.GET.get('page')
        show_groups = paginator.get_page(page)

        return render(
            request, 'groups.html', {
                'group': Member.get_user_group(request.user),
                'show_sidepane': True,
                'groups': show_groups,
                'page': page
            })
Beispiel #29
0
def remove_event(request, event_title, event_id):
    try:
        event_obj = Event.objects.get(pk=event_id)
    except ObjectDoesNotExist:
        return page_not_found(request,
                              exception=ObjectDoesNotExist(),
                              template_name='404.html')

    entity_obj = Event.objects.get(pk=event_id).entity

    if not Member.is_owner(request.user, entity_obj):
        return page_not_found(request,
                              exception=None,
                              template_name='403.html')

    remove = get_object_or_404(Event, pk=event_obj.id)
    instance = Event.objects.get(id=event_obj.id)
    instance.delete()
    remove.delete()
    return redirect("/")
Beispiel #30
0
    def post(self, request, group):

        # get the group object
        try:
            group = Group.objects.get(name=group)
        except ObjectDoesNotExist:
            return page_not_found(request, exception=ObjectDoesNotExist(), template_name='404.html')

        # is the user an editor (or owner)?
        if not Member.is_editor(request.user, group):
            return page_not_found(request, exception=None, template_name='403.html')

        form = EditGroupForm(request.POST, request.FILES or None, instance=group)

        # save group if valid
        if form.is_valid():
            form.save()
            messages.success(request, 'The group profile has successfully been updated.')
            form = EditGroupForm()

        return HttpResponseRedirect(reverse('entity:group_profile_edit', args=[group.name]))
Beispiel #31
0
    def post(self, request):

        form = CreateEventForm(data=request.POST)

        if form.is_valid():

            # assure they own the company/group they are creating an event for
            # this also needs to be adjusted in the form
            entity = form.cleaned_data.get('entity')

            if Member.is_editor(request.user, entity):
                form.save()
                event = form.instance

                # if it's a group, send an email to all group members
                if isinstance(event.entity.group, Group):
                    group = event.entity.group

                    link = settings.SITE_DOMAIN + reverse(
                        'event:event_details', args=[event.title, event.id])
                    msg_plain = render_to_string(
                        'emails/group_event.txt', {
                            'site': settings.SITE_DOMAIN,
                            'event_title': event.title,
                            'group_name': group.name,
                            'event_link': link
                        })
                    group.email_group("Event: {0}".format(event.title),
                                      msg_plain)

                messages.success(request,
                                 'The event has successfully been created.')
                form = CreateEventForm()
            else:
                messages.error(
                    request,
                    'You must be an editor of the company or group you are creating an event for.'
                )

        return HttpResponseRedirect(reverse('event:events_listing'))
Beispiel #32
0
 def email_group(self, subject: str, msg: str):
     members = Member.get_members(self)
     for member in members:
         member.user.email_user(subject, msg)