示例#1
0
def school_awards_pdf(request, username, slug, school_id, cqs_name):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_dir = os.path.join(_profile_file_path(
        profile, os.path.join(slug, school_id, 'all')))
    cert_fname = cqs_name + '.pdf'
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_fname = os.path.join(settings.MEDIA_ROOT, cert_path)
    try:
        assert False
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        try:
            cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        data = []
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        stcs = profile.schoolteachercode_set.filter(
                    code__codegenerator=competition.competitor_code_generator,
                    competition_questionset__name=cqs_name,
                    school_id=school_id
                ).order_by(
                    'code'
                ).prefetch_related(
                    'code')
        # print stcs
        for stc in stcs:
            stc.assign_si_awards(revoked_by=profile)
            awards = stc.attempt_awards().order_by(
                    'attempt__competitor__last_name',
                    'attempt__competitor__first_name'
                ).select_related(
                    'award')
            for award in awards:
                data.append(
                    {
                        'name': award.competitor_name,
                        'competition': award.attempt.competitionquestionset.competition,
                        'group': award.attempt.competitionquestionset.name,
                        'school': award.school_name,
                        'group': award.group_name,
                        'serial': award.serial,
                        'template': award.award.template,
                    }
                )
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
            # TODO: handle exception
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#2
0
文件: views.py 项目: polz113/bober
def school_awards_pdf(request, username, slug, school_id, cqs_name):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_dir = os.path.join(_profile_file_path(
        profile, os.path.join(slug, school_id, 'all')))
    cert_fname = cqs_name + '.pdf'
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_fname = os.path.join(settings.MEDIA_ROOT, cert_path)
    try:
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        try:
            cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        data = []
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        stcs = profile.schoolteachercode_set.filter(
                    code__codegenerator=competition.competitor_code_generator,
                    competition_questionset__name=cqs_name,
                    school_id=school_id
                ).order_by(
                    'code'
                ).prefetch_related(
                    'code')
        # print stcs
        for stc in stcs:
            stc.assign_si_awards(revoked_by=profile)
            awards = stc.attempt_awards().order_by(
                    'attempt__competitor__last_name',
                    'attempt__competitor__first_name'
                ).select_related(
                    'award')
            for award in awards:
                data.append(
                    {
                        'name': award.competitor_name,
                        'competition': award.attempt.competitionquestionset.competition,
                        'group': award.attempt.competitionquestionset.name,
                        'school': award.school_name,
                        'group': award.group_name,
                        'serial': award.serial,
                        'template': award.award.template,
                    }
                )
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
            # TODO: handle exception
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#3
0
def awards_type_pdf(request, username, slug, award_name, cqs_name):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_dir = os.path.join(_profile_file_path(
        profile, os.path.join(slug, 'by_type', award_name)))
    cert_fname = cqs_name + '-' + award_name + '.pdf'
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_fname = os.path.join(settings.MEDIA_ROOT, cert_path)
    try:
        # print "f:", os.path.join(settings.MEDIA_ROOT, cert_path)
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        try:
            cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        data = []
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        awards = AttemptAward.objects.filter(
                attempt__competitionquestionset__competition=competition,
                attempt__competitionquestionset__name=cqs_name,
                award__name=award_name,
                revoked_by=None,
            ).order_by(
                'attempt__competitor__last_name',
                'attempt__competitor__first_name'
            ).select_related(
                'award')
        for award in awards:
            data.append(
                {
                    'name': award.competitor_name,
                    'school': award.school_name,
                    'group': award.group_name,
                    # 'date': '7. - 11. novembra 2016',
                    'serial': award.serial,
                    'template': award.award.template,
                }
            )
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            # TODO: handle exception
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#4
0
文件: views.py 项目: polz113/bober
def awards_type_pdf(request, username, slug, award_name, cqs_name):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_dir = os.path.join(_profile_file_path(
        profile, os.path.join(slug, 'by_type', award_name)))
    cert_fname = cqs_name + '-' + award_name + '.pdf'
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_fname = os.path.join(settings.MEDIA_ROOT, cert_path)
    try:
        # print "f:", os.path.join(settings.MEDIA_ROOT, cert_path)
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        try:
            cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        data = []
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        awards = AttemptAward.objects.filter(
                attempt__competitionquestionset__competition=competition,
                attempt__competitionquestionset__name=cqs_name,
                award__name=award_name,
                revoked_by=None,
            ).order_by(
                'attempt__competitor__last_name',
                'attempt__competitor__first_name'
            ).select_related(
                'award')
        for award in awards:
            data.append(
                {
                    'name': award.competitor_name,
                    'school': award.school_name,
                    'group': award.group_name,
                    # 'date': '7. - 11. novembra 2016',
                    'serial': award.serial,
                    'template': award.award.template,
                }
            )
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            # TODO: handle exception
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#5
0
文件: views.py 项目: polz113/bober
def mentor_recognition_pdf(request, slug, username):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_fname = "bober-potrdilo-{}.pdf".format(slug)
    cert_dir = _profile_file_path(profile, slug)
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
    cert_full_fname = os.path.join(cert_full_dir, cert_fname)
    try:
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        try:
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            # TODO: handle exception
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
        data = []
        for recognition in profile.teacherrecognition_set.filter(
                template__competition=competition, revoked_by=None):
            d = {
                'text': recognition.text,
                'serial': recognition.serial,
                'name': recognition.recipient,
                'template': recognition.template.template
            }
            data.append(d)
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#6
0
 def handle(self, *args, **options):
     if len(args) < 4:
         args += (None,) * (4 - len(args))
     cslug = unicode(options.get('competition_slug', [args[0]])[0])
     cqs_name = unicode(options.get('questionset_name', [args[1]])[0])
     award_name = unicode(options.get('award_name', [args[2]])[0])
     output_filename = unicode(options.get('output_filename', [args[3]])[0])
     cqss = CompetitionQuestionSet.objects.filter(
         competition__slug = cslug,
         name = cqs_name
     )
     competition = SchoolCompetition.objects.get(slug=cslug)
     organizer = competition.administrator_code_generator.codes.filter(
             code_parts__name='admin_privileges', 
             code_parts__value='view_all_admin_codes'
         )[0].creator_set.all()[0]
     data = []
     for cqs in cqss:
         awards = AttemptAward.objects.filter(
             attempt__competitionquestionset = cqs, 
             award__name=award_name
         ).order_by(
             'attempt__competitor__last_name',
             'attempt__competitor__first_name'
         ).select_related(
             'award')
         for award in awards:
             data.append(
             {
                 'name': award.competitor_name,
                 'school': award.school_name,
                 'group': award.group_name,
                 'serial': award.serial,
                 'template': award.award.template,
             })
     template_file = os.path.join(AWARD_TEMPLATE_DIR, 'all_si.svg')
     generate_award_pdf(output_filename,
         data, template_file)
示例#7
0
文件: views.py 项目: polz113/bober
def mentor_recognition_pdf(request, slug, username):
    profile = Profile.objects.get(user__username=username)
    if profile.user != request.user and \
            request.profile.managed_profiles.filter(
                id=profile.id).count() <= 0:
        raise PermissionDenied
    cert_fname = "bober-potrdilo-{}.pdf".format(slug)
    cert_dir = _profile_file_path(profile, slug)
    cert_path = os.path.join(cert_dir, cert_fname)
    cert_full_dir = os.path.join(settings.MEDIA_ROOT, cert_dir)
    cert_full_fname = os.path.join(cert_full_dir, cert_fname)
    try:
        assert os.path.isfile(cert_full_fname)
    except Exception:
        # TODO: handle exception
        competition = SchoolCompetition.get_cached_by_slug(slug=slug)
        try:
            os.makedirs(cert_full_dir)
        except Exception as e:
            # TODO: handle exception
            pass
        try:
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, competition.slug)
            assert os.path.isdir(template_dir)
        except Exception:
            # TODO: handle exception
            template_dir = os.path.join(AWARD_TEMPLATE_DIR, 'default')
        data = []
        for recognition in profile.teacherrecognition_set.filter(
                template__competition=competition, revoked_by=None):
            d = {'text': recognition.text,
                 'serial': recognition.serial,
                 'name': recognition.recipient,
                 'template': recognition.template.template
                 }
            data.append(d)
        generate_award_pdf(cert_full_fname, data, template_dir)
    return safe_media_redirect(cert_path)
示例#8
0
 def handle(self, *args, **options):
     if len(args) < 4:
         args += (None,) * (4 - len(args))
     cslug = unicode(options.get('competition_slug', [args[0]])[0])
     cqs_name = unicode(options.get('questionset_name', [args[1]])[0])
     award_name = unicode(options.get('award_name', [args[2]])[0])
     output_filename = unicode(options.get('output_filename', [args[3]])[0])
     cqss = CompetitionQuestionSet.objects.filter(
         competition__slug = cslug,
         name = cqs_name
     )
     competition = SchoolCompetition.objects.get(slug=cslug)
     organizer = competition.administrator_code_generator.codes.filter(
             code_parts__name='admin_privileges', 
             code_parts__value='view_all_admin_codes'
         )[0].creator_set.all()[0]
     data = []
     for cqs in cqss:
         awards = AttemptAward.objects.filter(
             attempt__competitionquestionset = cqs, 
             award__name=award_name
         ).order_by(
             'attempt__competitor__last_name',
             'attempt__competitor__first_name'
         ).select_related(
             'award')
         for award in awards:
             data.append(
             {
                 'name': award.competitor_name,
                 'school': award.school_name,
                 'group': award.group_name,
                 'serial': award.serial,
                 'template': award.award.template,
             })
     template_file = os.path.join(AWARD_TEMPLATE_DIR, 'all_si.svg')
     generate_award_pdf(output_filename, data, template_file)