예제 #1
0
    def __createICS__(self):
        try:
            cal = vobject.iCalendar()
            cal.add('method').value = 'PUBLISH'

            item = Event.objects.get(pk=self.eventid)
            item.startTime, item.eventDt = getEventTimes(
                self.request, item.startTime, item.eventDt, True)
            item.endTime, item.eventDt = getEventTimes(self.request,
                                                       item.endTime,
                                                       item.eventDt, False)

            vEvent = cal.add('vevent')
            for vkey, key in EVENT_ITEMS:
                value = getattr(self, key)(item)
                if value:
                    vEvent.add(vkey).value = value

            vtzone = cal.add('vtimezone')
            vtzone.add('TZID').value = 'UTC'  #self.tzone
            VtimeDet = vtzone.add('STANDARD')
            for vkey, key in EVENT_VTIMEZONE:
                value = getattr(self, key)()
                if value:
                    VtimeDet.add(vkey).value = value

            response = HttpResponse(cal.serialize())
            strdata = str(response)
            RESPONSE_HDR_TXT = 'Content-Type: text/html; charset=utf-8'
            if (strdata.__contains__(RESPONSE_HDR_TXT)):
                strdata = strdata.replace(RESPONSE_HDR_TXT, '')
            eventpath = settings.EVENT_PATH + '/Event.ics'
            w = open(eventpath, "w")
            w.write(strdata)
            w.close()
            Email().send_email(item.name, item.message, self.sendingIds, '',
                               eventpath)
            for each in self.sendingIdsPwd:
                user = User.objects.filter(email=each)
                pwd = Util().Guid()[:6]
                email_message = ''
                if len(user) > 0:
                    user[0].set_password(pwd)  # setting the encrypted PWD
                    user[0].save()
                    email_message = settings.EMAIL_MESSAGE % (user[0].email,
                                                              pwd)
                email_message = email_message + '\n' + item.message
                Email().send_email(item.name, email_message, [
                    each,
                ], '', eventpath)
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)
            CapturLog().LogData(request, 'E-MailError', MODULE, errMessage)
        else:
            CapturLog().LogData(request, 'E-Mail', MODULE,
                                'Email sent successfully')
        finally:
            return ''
예제 #2
0
class ProjectMail(Job):
    """
        Cron Job that checks the lgr users mailbox and adds any approved senders' attachments to the db
    """

    # run every 43200 seconds (12 minutes)
    run_every = 43200

    def job(self):
        # This will be executed every 1 minutes
        programs = Project.objects.filter(approvalDate = (datetime.date.today()))
        owner_email = [ each for each in programs ]
        email_subject = 'approval mail'
        emailMessage = 'Today is the project approval due date for ' + str(each.name) + '.'
        for each in owner_email :
            message = emailMessage
            try:
                Email().send_email(email_subject, message,
                    [each.apexBodyOwner.userProfile.authUser.email],
                    CONTENT_TYPE)
            except Exception, e :
                errMessage = 'Email Sending failed \n %s' % (Exception)
        allprograms = Project.objects.filter(nextInvoiceDate = (datetime.date.today()))
        invoice_email = [ each for each in allprograms ]
        invoice_subject = 'invoice mail'
        invoicemail = 'Invoice date due for ' + str(each.name) + '.'
        for eachProgram in invoice_email:
            message = invoicemail
            try:
                Email().send_email(invoice_subject, message,
                    [each.apexBodyOwner.userProfile.authUser.email],
                    CONTENT_TYPE)
            except Exception, e :
                errMessage = 'Email Sending failed \n %s' % (Exception)
예제 #3
0
def sendingEmail(request, task):
    """  send email to the members when a non project task is assigned """
    taskallocationusers = NonProjectTaskAssignees.objects.filter(
        non_project_taskID=task.pk)
    if (len(taskallocationusers) > 0):
        #fivegusers = [FiveGUser.objects.filter(pk = each.user_id)
        fivegusers = [
            User.objects.filter(pk=each.user_id)
            for each in taskallocationusers
        ]
        userprofiles = [
            UserProfile.objects.get(pk=each[0].userProfile_id)
            for each in fivegusers
        ]
        users = [
            User.objects.get(pk=each.authUser_id) for each in userprofiles
        ]
        email_message = settings.NONPROJECT_TASK_ASSIGN_UNASSIGN % (task.name)
        try:
            for each in users:
                Email().send_email('Assign/Unassign Task', email_message, [
                    each.email,
                ], request)
                CapturLog().LogData(request, 'E-Mail', MODULE,
                                    'mail sent successfull')
        except Exception:
            errMessage = 'Email Sennding failed \n %s' % (Exception)
            CapturLog().LogData(request, 'E-MailErr', MODULE, errMessage)
예제 #4
0
파일: views.py 프로젝트: raveena17/ILASM
def SaveAnnouncement(request):
    msg = ''
    recipients = ''
    user = ''
    login_user = request.user
    announcement = GetAnnouncementDetail(request)
    if request.method == 'POST':
        announcement.save()
        email_subject = 'New Announcement for approval'
        user = User.objects.get(username=announcement.approved_by)
        recipients = user.email
        try:
            email_message = 'A new announcement ' + \
                str(announcement.title) + ' has been created by ' + \
                str(announcement.requested_by)
        except Exception:
            pass

        try:
            Email().send_email(email_subject, email_message, [recipients],
                               CONTENT_TYPE)
            msg = 'CREATED'
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)

    return render(
        request,
        'CreateAnnouncement.html',
        {
            'msg': actionMsg[msg],
            'login_user': login_user
        },
    )
예제 #5
0
 def job(self):
     # This will be executed every 1 minutes
     programs = Project.objects.filter(approvalDate = (datetime.date.today()))
     owner_email = [ each for each in programs ]
     email_subject = 'approval mail'
     emailMessage = 'Today is the project approval due date for ' + str(each.name) + '.'
     for each in owner_email :
         message = emailMessage
         try:
             Email().send_email(email_subject, message,
                 [each.apexBodyOwner.userProfile.authUser.email],
                 CONTENT_TYPE)
         except Exception, e :
             errMessage = 'Email Sending failed \n %s' % (Exception)
예제 #6
0
파일: views.py 프로젝트: raveena17/ILASM
def SaveAnnouncement(request):
    #approved_by = User.objects.filter(groups__name = 'Corporate Admin')
    #requested_by = request.user
    msg = ''
    recipients = ''
    user = ''
    login_user = request.user
    announcement = GetAnnouncementDetail(request)
    if request.method == 'POST':
        if request.POST.get('mode', '') == 'update':
            announcement.creation_date = request.POST.get(
                'announcementdate', '')

        announcement.save()

        email_subject = 'New Announcement for approval'
        # for each in User.objects.filter(groups__name = 'Corporate Admin'):
        #    recipients = each.email

        user = User.objects.get(username=announcement.approved_by)
        recipients = user.email
        #template = get_template('Announcement_Mail.html')
        # data = {'Requested_by' : str(announcement.requested_by),
        #        'Title' : str(announcement.title),
        #        'Content' : str(announcement.content),
        #        'Created_on' : str(announcement.creation_date),
        #        'approved_by' : str(announcement.approved_by)
        #        }
        #email_message = template.render(Context(data))

        email_message = 'A new announcement ' + \
            str(announcement.title) + ' has been created by ' + str(announcement.requested_by)

        try:
            Email().send_email(email_subject, email_message, [recipients],
                               CONTENT_TYPE)
            msg = 'CREATED'
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)

    return render(
        request,
        'CreateAnnouncement.html',
        {
            'msg': actionMsg[msg],
            'login_user': login_user
        },
    )
예제 #7
0
파일: cron.py 프로젝트: raveena17/django
 def job(self):
     # This will be executed every 1 minutes
     book_conference_room = BookConference.objects.all()
     meeting = MeetingAttendees.objects.filter(
         conference_room=book_conference_room.name_of_meeting)
     conference = BookConference.objects.filter(
         meeting_date=(datetime.date.today()))
     print datetime.date.today()
     email_subject = 'Remainder Mail'
     emailMessage = 'Today is the date for the meeting ' + str(
         book_onference_room.name_of_meeting) + '.'
     for each in User.objects.filter(is_active='True').exclude(
             username='******'):
         for each1 in meeting:
             if str(each1.attendees) == str(each.username):
                 Email().send_email(email_subject, message, [each.email],
                                    CONTENT_TYPE)
예제 #8
0
    def __createICS__(self):
        try:
            cal = vobject.iCalendar()
            cal.add('method').value = 'PUBLISH'

            item = Event.objects.get(pk=self.eventid)
            item.startTime, item.eventDt = getEventTimes(
                self.request, item.startTime, item.eventDt, True)
            item.endTime, item.eventDt = getEventTimes(self.request,
                                                       item.endTime,
                                                       item.eventDt, False)

            vEvent = cal.add('vevent')
            for vkey, key in EVENT_ITEMS:
                value = getattr(self, key)(item)
                if value:
                    vEvent.add(vkey).value = value

            vtzone = cal.add('vtimezone')
            vtzone.add('TZID').value = 'UTC'
            VtimeDet = vtzone.add('STANDARD')
            for vkey, key in EVENT_VTIMEZONE:
                value = getattr(self, key)()
                if value:
                    VtimeDet.add(vkey).value = value

            response = HttpResponse(cal.serialize())
            strdata = str(response)
            RESPONSE_HDR_TXT = 'Content-Type: text/html; charset=utf-8'
            if (strdata.__contains__(RESPONSE_HDR_TXT)):
                strdata = strdata.replace(RESPONSE_HDR_TXT, '')
            eventpath = settings.EVENT_PATH + '/Event.ics'
            w = open(eventpath, "w")
            w.write(strdata)
            w.close()
            Email().send_email(item.name, item.message, self.sendingIds, '',
                               eventpath)
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)
            CapturLog().LogData(request, 'E-MailError', MODULE, errMessage)
        else:
            CapturLog().LogData(request, 'E-Mail', MODULE,
                                'Email sent successfully')
        finally:
            return ''
예제 #9
0
def manage_project_initiation_request(request):
    """
        Create/Edit project Initiation request.
    """
    project = None
    user = request.user.id
    is_approved = ''
    msg = ''
    schedules = addressClient = None
    specific_dates_form = None
    time_based_form = None
    milestone_form = None
    id = request.GET.get('id', None)
    user = ProjectInitiationRequestForm(user=request.user)
    MilestoneFormSet = init_milestone_formset(
        ('name', 'percentage'), True,
        extra_form(project, BILLING_CATEGORY['Milestone']))
    TimeBasedFormSet = init_milestone_formset(
        ('invoice_terms', 'start_date', 'end_date'),
        True,
        extra_form(project, BILLING_CATEGORY['Time-Based']),
        max_num=TIME_BASED_MAX_FORM)
    SpecificDatesFormSet = init_milestone_formset(
        ('start_date', 'percentage'), True,
        extra_form(project, BILLING_CATEGORY['Specific-Dates']))
    if id:
        project = get_object_or_404(Project, code=id)
        schedules = project.schedules
        projectOwner = project.customer
        address_client = BusinessUnit.objects.filter(type__name='Customer')
        for each in address_client:
            if str(projectOwner) == each.name:
                addressClient = each.address

        MilestoneFormSet = init_milestone_formset(
            ('name', 'percentage'), True,
            extra_form(project, BILLING_CATEGORY['Milestone']))
        TimeBasedFormSet = init_milestone_formset(
            ('invoice_terms', 'start_date', 'end_date'),
            True,
            extra_form(project, BILLING_CATEGORY['Time-Based']),
            max_num=TIME_BASED_MAX_FORM)
        SpecificDatesFormSet = init_milestone_formset(
            ('start_date', 'percentage'), True,
            extra_form(project, BILLING_CATEGORY['Specific-Dates']))

    if request.method == 'POST':
        request_form = ProjectInitiationRequestForm(request.POST,
                                                    instance=project,
                                                    user=request.user)
        schedules_form = ProjectSchedulesRequestForm(request.POST,
                                                     instance=schedules)

        if request.user.has_perm('projects.add_project'):
            if id:
                milestone_form = MilestoneFormSet(
                    request.POST,
                    queryset=get_milestone(project,
                                           BILLING_CATEGORY['Milestone']),
                    prefix='milestone')
                time_based_form = TimeBasedFormSet(
                    request.POST,
                    queryset=get_milestone(project,
                                           BILLING_CATEGORY['Time-Based']),
                    prefix='timebased')
                specific_dates_form = SpecificDatesFormSet(
                    request.POST,
                    queryset=get_milestone(project,
                                           BILLING_CATEGORY['Specific-Dates']),
                    prefix='specificdates')

                if validate(
                    [milestone_form, time_based_form, specific_dates_form]):

                    save_milestone_formset(
                        milestone_form, project,
                        InvoiceTerms.objects.get(name='Milestone'))
                    save_milestone_formset(time_based_form, project)
                    save_milestone_formset(
                        specific_dates_form, project,
                        InvoiceTerms.objects.get(name='Specific-Date'))

        if request_form.is_valid() and schedules_form.is_valid():
            schedules = schedules_form.save()
            is_approved = request_form.cleaned_data[
                'is_approvedby'] == 'Approve'
            request_form.save(schedules=schedules, is_approved=is_approved)

            if request.user.has_perm(
                    'projects.add_project') and id and is_approved != "":
                if is_approved:
                    email_message = "Project " + str(
                        request_form.cleaned_data['name']
                    ) + ' was approved by ' + str(
                        request_form.cleaned_data['approved_by']
                    ) + ' on ' + str(
                        schedules_form.cleaned_data['approved_date'])
                    #template = get_template('Approved_Project_Link_Mail.html')
                    #if request_form.is_valid():
                    #    project_id = Project.objects.get(name = request_form.cleaned_data['name'])
                    #    email_subject1 = "Print of Project detail"
                    #    recipent_list = ['*****@*****.**']
                    #    data = {'project_id': project_id.id,
                    #            'user': request.user,
                    #            'project': project_id}
                    #    email_message1 = template.render(Context(data))
                    #    for email_id in recipent_list:
                    #        Email().send_email(email_subject1, email_message1, [email_id], CONTENT_TYPE)
                else:
                    email_message = "Project " + str(
                        request_form.cleaned_data['name']
                    ) + ' was Rejected by ' + str(
                        request_form.cleaned_data['approved_by']
                    ) + ' on ' + str(
                        schedules_form.cleaned_data['approved_date'])
                email_subject = 'Project Approval Status'

                user = User.objects.get(
                    username=request_form.cleaned_data['requested_by'])
                recipients = user.email

                try:
                    Email().send_email(email_subject, email_message,
                                       [recipients], CONTENT_TYPE)
                    if is_approved:
                        msg = 'project_Approve'
                    else:
                        msg = 'project_Reject'
                    #next = request.GET.get("next", None)
                    #if next:
                    #    return HttpResponseRedirect(next)
                except Exception:
                    errMessage = 'Email Sending failed \n %s' % (Exception)

            if (id == None) or (
                    not request.user.has_perm('projects.add_project')
                    and request.user.has_perm('projects.change_project')
                    and id):

                email_subject = 'Project initiation request'
                if request_form.cleaned_data['project_type'].name == 'Others':
                    project_type = str(
                        request_form.cleaned_data['other_project_type']
                    ) + '\r\n'
                else:
                    project_type = str(
                        request_form.cleaned_data['project_type']) + '\r\n'

                user = User.objects.get(
                    username=request_form.cleaned_data['approved_by'])
                recipients = user.email

                template = get_template('Project_Initiate_Request_Mail.html')
                data = {
                    'project_name':
                    request_form.cleaned_data['name'],
                    'user_name':
                    request.user,
                    'request_date':
                    schedules_form.cleaned_data['initiation_request_date'],
                    'division':
                    request_form.cleaned_data['business_unit'],
                    'project_category':
                    request_form.cleaned_data['approval_type'],
                    'project_type':
                    project_type,
                    'expected_start_date':
                    schedules_form.cleaned_data['expected_start_date'],
                    'expected_end_date':
                    schedules_form.cleaned_data['expected_end_date'],
                    'estimated_efforts':
                    request_form.cleaned_data['planned_effort'],
                    'objective':
                    request_form.cleaned_data['objective'],
                    'approved_by':
                    request_form.cleaned_data['approved_by'],
                }
                email_message = template.render(Context(data))

                try:
                    Email().send_email(email_subject, email_message,
                                       [recipients], CONTENT_TYPE)
                    msg = 'project_initiated'
                except Exception:
                    errMessage = 'Email Sending failed \n %s' % (Exception)
        #next = request.GET.get("next", None)
        #if next:
        #    return HttpResponseRedirect(next)

    else:

        request_form = ProjectInitiationRequestForm(instance=project,
                                                    user=request.user)
        schedules_form = ProjectSchedulesRequestForm(instance=schedules)
        milestone_form = MilestoneFormSet(queryset=get_milestone(
            project, BILLING_CATEGORY['Milestone']),
                                          prefix='milestone')
        time_based_form = TimeBasedFormSet(queryset=get_milestone(
            project, BILLING_CATEGORY['Time-Based']),
                                           prefix='timebased')
        specific_dates_form = SpecificDatesFormSet(queryset=get_milestone(
            project, BILLING_CATEGORY['Specific-Dates']),
                                                   prefix='specificdates')

    return render(
        request,
        'project_initiation_request.html',
        {
            'request_form': request_form,
            'schedules_form': schedules_form,
            'msg': actionMsg[msg],
            'is_approved': is_approved,
            'specific_dates_form': specific_dates_form,
            'milestone_form': milestone_form,
            'user': user,
            'time_based_form': time_based_form,
            'project': project,
            'schedules': schedules,
            'addressClient': addressClient
        },
    )
예제 #10
0
파일: views.py 프로젝트: raveena17/django
def ApproveAnnouncement(request):
    msg = ''

    toApprove = request.GET.get('ids', '')
    login_user = request.user

    announcement = Announcement.objects.filter(
        pk=toApprove) if toApprove != '' else ''

    announcement = announcement[0] if announcement else announcement
    approve = request.POST.get('Approve', '')
    reject = request.POST.get('Reject', '')
    title = request.POST.get('announcementname', '')
    content = request.POST.get('announcementcontent', '')
    #created_date = request.POST.get('announcementdate','')

    if approve == "Approve":
        announcement.is_approved = "1"
        announcement.title = title
        announcement.content = content
        #announcement.creation_date = created_date
        announcement.save()

        email_subject = 'New Announcement Approval Status'
        email_subject1 = 'New Announcement - ' + str(announcement.title)
        #for each in User.objects.filter(groups__name = 'Corporate Admin'):
        #    recipients = each.email

        #user = User.objects.get(username = announcement.requested_by)
        #recipients = user.email

        #template = get_template('Announcement_Mail.html')
        #data = {'Requested_by' : str(announcement.requested_by),
        #        'Title' : str(announcement.title),
        #        'Content' : str(announcement.content),
        #        'Created_on' : str(announcement.creation_date),
        #        'approved_by' : str(announcement.approved_by)
        #        }
        #email_message = template.render(Context(data))
        Title = str(announcement.title)
        email_message = 'Announcement ' + str(
            announcement.title) + ' was approved by ' + str(
                announcement.approved_by)
        template = get_template('Approved_Announcement_Mail.html')
        data = {'Title': Title}
        email_message1 = template.render(Context(data))
        try:
            #            Email().send_email(email_subject, email_message, [recipients], CONTENT_TYPE)
            ommission = "@example.com"
            for each in UserProfile.objects.filter(
                    Q(code__startswith="E") | Q(user__username='******')):
                if (each.user.is_active == True):
                    if (each.user.email.endswith(ommission) != True):
                        #Email().send_email(email_subject1, email_message1, [each.user.email], CONTENT_TYPE)
                        alert_generate(request, 'Announcement',
                                       'alertdataconfig15', announcement.pk,
                                       [each.user.email])
            msg = 'APPROVED'
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)

    elif reject == "Reject":
        #import pdb; pdb.set_trace()
        announcement.is_rejected = "1"
        announcement.save()
        msg = 'REJECTED'
        user = User.objects.get(username=announcement.requested_by)
        recipients2 = user.email
        email_message = 'Your request to a new announcement was rejected by ' + str(
            announcement.approved_by)
        Email().send_email('Announcement Approval Status', email_message,
                           [recipients2], CONTENT_TYPE)
    return render(
        request,
        'CreateAnnouncement.html',
        {
            'announcement': announcement,
            'mode': 'update',
            'login_user': login_user,
            'msg': msg
        },
    )
예제 #11
0
def manage_book_conference_room(request):
    book_conference_room = conference_id = conference_requesting_date = FromTime = ToTime = None
    book_conf_id = 0
    id = request.GET.get('id', None)
    is_approved = requestingMember = None
    user_list = id_list = []
    attendees_list = AssigneesInvited = []

    if id:
        book_conference_room = get_object_or_404(BookConference, pk=id)
        conference_id = book_conference_room.id
        requestingMember = book_conference_room.requested_by
        FromTime = book_conference_room.from_time.strftime('%H:%M')
        ToTime = book_conference_room.to_time.strftime('%H:%M')
        attendees_list = MeetingAttendees.objects.filter(
            conference_name=book_conference_room.name_of_meeting)
        attendees_set = set([each.attendees_id for each in attendees_list])
        for each in attendees_set:
            list2 = User.objects.filter(id=each)

    user_list = User.objects.filter(is_active='True').exclude(
        username='******')

    if request.method == 'POST':
        form = BookConferenceRoomForm(data=request.POST,
                                      instance=book_conference_room,
                                      user=request.user)
        if form.is_valid():
            form.save()
            selected_MeetingTeam = set([
                User.objects.get(id=ID)
                for ID in request.POST.getlist('selectedmeetinginvitees')
            ])

            existing_MeetingTeam = set([
                each.attendees for each in MeetingAttendees.objects.filter(
                    conference_name=form.cleaned_data['name_of_meeting'])
            ])
            insertAssignees = set(selected_MeetingTeam) - set(
                existing_MeetingTeam)
            deleteAssignees = set(existing_MeetingTeam) - set(
                selected_MeetingTeam)
            [
                MeetingAttendees.objects.filter(
                    conference_name=form.cleaned_data['name_of_meeting'],
                    attendees=each).delete() for each in deleteAssignees
            ]
            [
                MeetingAttendees(
                    conference_name=form.cleaned_data['name_of_meeting'],
                    attendees=each).save() for each in insertAssignees
            ]

            attendees_list = MeetingAttendees.objects.filter(
                conference_name=form.cleaned_data['name_of_meeting'])

            if id:
                attendees_list = MeetingAttendees.objects.filter(
                    conference_name=book_conference_room.name_of_meeting)

            if id and book_conference_room.is_approved:

                attendees_list = MeetingAttendees.objects.filter(
                    conference_name=book_conference_room.name_of_meeting)
                email_subject = "Meeting Attending Request"
                email_message = "You are invited for " + str(
                    book_conference_room.name_of_meeting) + ' on ' + str(
                        book_conference_room.meeting_date) + ' from ' + str(
                            book_conference_room.from_time) + ' to ' + str(
                                book_conference_room.to_time) + ' from ' + str(
                                    book_conference_room.requested_by)
                for each in User.objects.filter(is_active='True').exclude(
                        username='******'):
                    for each1 in attendees_list:
                        if str(each1.attendees) == str(each.username):
                            Email().send_email(email_subject, email_message,
                                               [each.email], CONTENT_TYPE)

            is_approved = form.cleaned_data['is_approvedby']
            if id and is_approved != "":
                if is_approved == 'Approve':
                    email_message = "Conference room booked on " + str(
                        form.cleaned_data['meeting_date']) + ' from ' + str(
                            form.cleaned_data['from_time']) + 'to ' + str(
                                form.cleaned_data['to_time']
                            ) + ' was approved by ' + str(
                                form.cleaned_data['approved_by'])
                else:
                    email_message = "Conference room booked on " + str(
                        form.cleaned_data['meeting_date']) + ' from ' + str(
                            form.cleaned_data['from_time']) + 'to ' + str(
                                form.cleaned_data['to_time']
                            ) + ' was rejected by ' + str(
                                form.cleaned_data['approved_by'])
                email_subject = 'Conference room Approval Status'

                user = User.objects.get(
                    username=form.cleaned_data['requested_by'])
                recipients = user.email
                #user1 = User.objects.filter(groups__name = 'Manager', is_active = True).exclude(username = form.cleaned_data['requested_by'])
                #for each in user1:
                #    recipents1 = each.email
                try:
                    Email().send_email(email_subject, email_message,
                                       [recipients], CONTENT_TYPE)
                    if is_approved:
                        messages.success(
                            request, _('Conference room request - Approved'))
                    else:
                        messages.success(
                            request, _('Conference room request - Rejected'))
                except Exception:
                    errMessage = 'Email Sending failed \n %s' % (Exception)
            if id == None:
                email_subject = 'Conference Room Booking'
                email_message = 'Conference Room ' + str(
                    form.cleaned_data['conference_room']
                ) + ' has been requested by ' + str(
                    form.cleaned_data['requested_by']) + ' on ' + str(
                        form.cleaned_data['meeting_date']) + ' from ' + str(
                            form.cleaned_data['from_time']) + 'to ' + str(
                                form.cleaned_data['to_time'])

                user = User.objects.get(
                    username=form.cleaned_data['approved_by'])
                recipients = user.email
                try:
                    Email().send_email(email_subject, email_message,
                                       [recipients], CONTENT_TYPE)
                except Exception:
                    errMessage = 'Email Sending failed \n %s' % (Exception)
                messages.success(
                    request,
                    _('Your conference room request has been sent for approval'
                      ))
    else:
        form = BookConferenceRoomForm(instance=book_conference_room,
                                      user=request.user)

    return render(
        request,
        'book_conference_room.html',
        {
            'form': form,
            'conference_id': conference_id,
            'book_conference_room': book_conference_room,
            'times': __getTimes__(),
            'FromTime': FromTime,
            'ToTime': ToTime,
            'requestingMember': requestingMember,
            'user_list': user_list,
            'attendees_list': attendees_list,
            'id_list': id_list
        },
    )
예제 #12
0
파일: views.py 프로젝트: raveena17/ILASM
def ApproveAnnouncement(request):
    msg = ''

    toApprove = request.GET.get('ids', '')
    login_user = request.user
    announcement = Announcement.objects.filter(
        pk=toApprove) if toApprove != '' else ''
    announcement = announcement[0] if announcement else announcement
    approve = request.POST.get('Approve', '')
    reject = request.POST.get('Reject', '')
    title = request.POST.get('announcementname', '')
    content = request.POST.get('announcementcontent', '')

    if approve == "Approve":
        announcement.is_approved = "1"
        announcement.title = title
        announcement.content = content
        announcement.save()
        email_subject = 'New Announcement Approval Status'
        email_subject1 = 'New Announcement - ' + str(announcement.title)

        Title = str(announcement.title)
        email_message = 'Announcement ' + \
            str(announcement.title) + ' was approved by ' + \
            str(announcement.approved_by)
        template = get_template('Approved_Announcement_Mail.html')
        data = {'Title': Title}
        # email_message1 = template.render(Context(data))
        email_message1 = template.render(data)
        try:
            ommission = "@example.com"
            for each in UserProfile.objects.filter(
                    Q(code__startswith="E") | Q(user__username='******')):
                if (each.user.is_active):
                    if (each.user.email.endswith(ommission) != True):
                        Email().send_email(email_subject1, email_message1,
                                           [each.user.email], CONTENT_TYPE)
                        # alert_generate(
                        #     request, 'Announcement', 'alertdataconfig15', announcement.pk, [
                        #         each.user.email])
            msg = 'Announcement - Approved successfully'
        except Exception:
            errMessage = 'Email Sending failed \n %s' % (Exception)

    elif reject == "Reject":
        announcement.is_rejected = "1"
        announcement.save()
        msg = 'Announcement has been Rejected'
        try:
            user = User.objects.get(username=announcement.requested_by)
        except Exception:
            pass
        recipients2 = user.email
        email_message = 'Your request to a new announcement was rejected by ' + \
            str(announcement.approved_by)
        Email().send_email('Announcement Approval Status', email_message,
                           [recipients2], CONTENT_TYPE)
    return render(
        request,
        'CreateAnnouncement.html',
        {
            'announcement': announcement,
            'mode': 'update',
            'login_user': login_user,
            'msg': msg
        },
    )