def imprints(request, publisher_id):
    """
    Finds imprints of a publisher.  Imprints are defined as those
    publishers whose parent_id matches the given publisher.
    """

    publisher = get_object_or_404(Publisher, id = publisher_id)
    if publisher.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'publisher', 'id': publisher_id}))

    imps = publisher.active_imprints()

    sort = ORDER_ALPHA
    if 'sort' in request.GET:
        sort = request.GET['sort']

    if (sort == ORDER_CHRONO):
        imps = imps.order_by('year_began', 'name')
    else:
        imps = imps.order_by('name', 'year_began')

    return paginate_response(request, imps, 'gcd/details/imprints.html', {
      'publisher' : publisher,
      'error_subject' : '%s imprints' % publisher,
      })
def covers(request, series_id, style="default"):
    """
    Display the index status matrix for a series.
    """

    series = get_object_or_404(Series, id=series_id)
    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = 5

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and request.user.groups.filter(name="editor"):
        can_mark = True
    else:
        can_mark = False

    covers = series.cover_set.select_related("issue").filter(has_image="1")
    style = get_style(request)
    vars = {
        "series": series,
        "error_subject": "%s covers" % series,
        "table_width": table_width,
        "style": style,
        "can_mark": can_mark,
    }

    return paginate_response(
        request,
        covers,
        "gcd/details/covers.html",
        vars,
        page_size=50,
        callback_key="tags",
        callback=lambda page: get_image_tags_per_page(page, series),
    )
def brands(request, publisher_id):
    """
    Finds brands of a publisher.
    """

    publisher = get_object_or_404(Publisher, id = publisher_id)
    if publisher.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'publisher', 'id': publisher_id}))

    brands = publisher.active_brands()

    sort = ORDER_ALPHA
    if 'sort' in request.GET:
        sort = request.GET['sort']

    if (sort == ORDER_CHRONO):
        brands = brands.order_by('year_began', 'name')
    else:
        brands = brands.order_by('name', 'year_began')

    return paginate_response(request, brands, 'gcd/details/brands.html', {
      'publisher' : publisher,
      'error_subject' : '%s brands' % publisher,
    })
def series_and_issue(request, series_name, issue_nr, sort=ORDER_ALPHA):
    """ Looks for issue_nr in series_name """
    things = Issue.objects.filter(series__name__exact = series_name) \
                .filter(number__exact = issue_nr)
    
    if things.count() == 1: # if one display the issue
        return HttpResponseRedirect(urlresolvers.reverse(issue,
                                    kwargs={ 'issue_id': things[0].id }))
    else: # if more or none use issue_list.html from search
        p = QuerySetPaginator(things, 100)
        page_num = 1
        if (request.GET.has_key('page')):
            page_num = int(request.GET['page'])
        page = p.page(page_num)
        
        context = {
            'items' : things,
            'item_name' : 'issue',
            'plural_suffix' : 's',
            'heading' : series_name + ' #' + issue_nr,
            'style' : 'default',
        }
        if 'style' in request.GET:
            context['style'] = request.GET['style']

        return paginate_response(
          request, things, 'gcd/search/issue_list.html', context)
Exemplo n.º 5
0
def brand_uses(request, publisher_id):
    """
    Finds brand emblems used at a publisher and presents them as a paginated list.
    """

    publisher = get_object_or_404(Publisher, id = publisher_id)
    if publisher.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'publisher', 'id': publisher_id}))

    brand_uses = publisher.branduse_set.all()

    sort = ORDER_ALPHA
    if 'sort' in request.GET:
        sort = request.GET['sort']

    if (sort == ORDER_CHRONO):
        brand_uses = brand_uses.order_by('year_began', 'emblem__name')
    else:
        brand_uses = brand_uses.order_by('emblem__name', 'year_began')

    return paginate_response(request, brand_uses,
      'gcd/details/brand_uses.html', {
        'publisher' : publisher,
        'error_subject' : '%s brands' % publisher,
      })
def covers_to_replace(request, starts_with=None):
    """
    Display the covers that are marked for replacement.
    """

    covers = Cover.objects.filter(marked = True)
    if starts_with:
        covers = covers.filter(issue__series__name__startswith = starts_with)
    covers = covers.order_by("issue__series__name",
                             "issue__series__year_began",
                             "issue__key_date")

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    return paginate_response(
      request,
      covers,
      'gcd/status/covers_to_replace.html',
      {
        'table_width' : table_width,
        'starts_with' : starts_with
      },
      page_size=50,
      callback_key='tags',
      callback=get_image_tags_per_page)
def covers(request, series_id):
    """
    Display the cover gallery for a series.
    """

    series = get_object_or_404(Series, id = series_id)
    if series.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'series', 'id': series_id}))

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and \
      request.user.groups.filter(name='editor'):
        can_mark = True
    else:
        can_mark = False

    covers = Cover.objects.filter(issue__series=series, deleted=False) \
                          .select_related('issue')

    vars = {
      'series': series,
      'error_subject': '%s covers' % series,
      'table_width': table_width,
      'can_mark': can_mark
    }

    return paginate_response(request, covers, 'gcd/details/covers.html', vars,
      page_size=50,
      callback_key='tags',
      callback=lambda page: get_image_tags_per_page(page, series))
def imprints(request, publisher_id):
    """
    Finds imprints of a publisher.  Imprints are defined as those
    publishers whose parent_id matches the given publisher.
    """

    publisher = get_object_or_404(Publisher, id=publisher_id)
    imps = publisher.imprint_set.all()

    sort = ORDER_ALPHA
    if "sort" in request.GET:
        sort = request.GET["sort"]

    if sort == ORDER_CHRONO:
        imps = imps.order_by("year_began", "name")
    else:
        imps = imps.order_by("name", "year_began")

    style = get_style(request)
    return paginate_response(
        request,
        imps,
        "gcd/details/imprints.html",
        {"publisher": publisher, "error_subject": "%s imprints" % publisher, "imprints": imps, "style": style},
    )
Exemplo n.º 9
0
def covers(request, series_id):
    """
    Display the cover gallery for a series.
    """

    series = get_object_or_404(Series, id=series_id)
    if series.deleted:
        return HttpResponseRedirect(
            urlresolvers.reverse("change_history", kwargs={"model_name": "series", "id": series_id})
        )

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and request.user.groups.filter(name="editor"):
        can_mark = True
    else:
        can_mark = False

    covers = Cover.objects.filter(issue__series=series, deleted=False).select_related("issue")

    vars = {"series": series, "error_subject": "%s covers" % series, "table_width": table_width, "can_mark": can_mark}

    return paginate_response(
        request,
        covers,
        "gcd/details/covers.html",
        vars,
        page_size=50,
        callback_key="tags",
        callback=lambda page: get_image_tags_per_page(page, series),
    )
def covers(request, series_id, style="default"):
    """
    Display the index status matrix for a series.
    """

    series = get_object_or_404(Series, id = series_id)
    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = 5

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and \
      request.user.groups.filter(name='editor'):
        can_mark = True
    else:
        can_mark = False

    covers =series.cover_set.select_related('issue').filter(has_image = '1')
    style = get_style(request)
    vars = {
      'series': series,
      'error_subject': '%s covers' % series,
      'table_width': table_width,
      'style': style,
      'can_mark': can_mark
    }

    return paginate_response(request, covers, 'gcd/details/covers.html', vars,
      page_size=50,
      callback_key='tags',
      callback=lambda page: get_image_tags_per_page(page, series))
Exemplo n.º 11
0
def indicia_publishers(request, publisher_id):
    """
    Finds indicia publishers of a publisher and presents them as
    a paginated list.
    """

    publisher = get_object_or_404(Publisher, id=publisher_id)
    if publisher.deleted:
        return HttpResponseRedirect(
            urlresolvers.reverse("change_history", kwargs={"model_name": "publisher", "id": publisher_id})
        )

    indicia_publishers = publisher.active_indicia_publishers()

    sort = ORDER_ALPHA
    if "sort" in request.GET:
        sort = request.GET["sort"]

    if sort == ORDER_CHRONO:
        indicia_publishers = indicia_publishers.order_by("year_began", "name")
    else:
        indicia_publishers = indicia_publishers.order_by("name", "year_began")

    return paginate_response(
        request,
        indicia_publishers,
        "gcd/details/indicia_publishers.html",
        {"publisher": publisher, "error_subject": "%s indicia publishers" % publisher},
    )
Exemplo n.º 12
0
def add_selected_issues_to_collection(request, data):
    selections = data['selections']
    issues = Issue.objects.filter(id__in=selections['issue'])
    if 'story' in selections:
        issues |= Issue.objects.filter(story__id__in=selections['story'])
    issues = issues.distinct()
    if not issues.count():
        raise ErrorWithMessage("No issues were selected.")

    if 'confirm_selection' in request.POST:
        collection_id = int(request.POST['collection_id'])
        return add_issues_to_collection(request,
          collection_id, issues, urlresolvers.reverse('view_collection',
                                 kwargs={'collection_id': collection_id}))
    else:
        collection_list = request.user.collector.ordered_collections()
        context = {
                'item_name': 'issue',
                'plural_suffix': 's',
                'no_bulk_edit': True,
                'heading': 'Issues',
                'confirm_selection': True,
                'collection_list': collection_list
            }
        return paginate_response(request, issues,
                                 'gcd/search/issue_list.html', context,
                                 per_page=issues.count())
Exemplo n.º 13
0
def select_issues_from_preselection(request, issues, cancel,
                                    post_process_selection=None,
                                    collection_list=None):
    if not issues.exists():
        raise ErrorWithMessage("No issues to select from.")
    data = {'issue': True,
            'allowed_selects': ['issue',],
            'return': add_selected_issues_to_collection,
            'cancel': cancel}
    if post_process_selection:
        data['post_process_selection'] = post_process_selection
    if collection_list:
        data['collection_list'] = collection_list
    select_key = store_select_data(request, None, data)
    context = {'select_key': select_key,
            'multiple_selects': True,
            'item_name': 'issue',
            'plural_suffix': 's',
            'no_bulk_edit': True,
            'all_pre_selected': True,
            'heading': 'Issues'
    }
    return paginate_response(request, issues,
                            'gcd/search/issue_list.html', context,
                            per_page=issues.count())
def publisher(request, publisher_id):
    """Display the details page for a Publisher."""

    style = get_style(request)
    pub = get_object_or_404(Publisher, id=publisher_id)

    vars = {"publisher": pub, "error_subject": pub, "style": style, "media_url": settings.MEDIA_URL}
    return paginate_response(request, pub.series_set.order_by("name"), "gcd/details/publisher.html", vars)
def show_brand(request, brand, preview=False):
    brand_issues = brand.issue_set.order_by('series__name', 'sort_code')

    vars = { 'brand' : brand, 'error_subject': '%s' % brand, 'preview': preview }
    return paginate_response(request,
                             brand_issues,
                             'gcd/details/brand.html',
                             vars)
def generic_by_name(request, name, q_obj, sort,
                    class_=Story,
                    template='gcd/search/content_list.html',
                    credit=None):
    """
    Helper function for the most common search cases.
    """

    base_name = 'unknown'
    plural_suffix = 's'
    if (class_ is Series):
        base_name = 'series'
        plural_suffix = ''
        things = Series.objects.filter(q_obj).select_related('publisher')
        if (sort == ORDER_ALPHA):
            things = things.order_by("name", "year_began")
        elif (sort == ORDER_CHRONO):
            things = things.order_by("year_began", "name")
        heading = 'Series Search Results'

    elif (class_ is Story):
        # TODO: move this outside when series deletes are implemented
        q_obj &= Q(deleted=False)

        base_name = 'stor'
        plural_suffix = 'y,ies'

        things = class_.objects.filter(q_obj)
        things = things.select_related('issue__series__publisher',
                                       'type')

        # TODO: This order_by stuff only works for Stories, which is 
        # TODO: OK for now, but might not always be.
        if (sort == ORDER_ALPHA):
            things = things.order_by("issue__series__name",
                                     "issue__series__year_began",
                                     "issue__key_date",
                                     "sequence_number")
        elif (sort == ORDER_CHRONO):
            things = things.order_by("issue__key_date",
                                     "issue__series__name",
                                     "issue__series__year_began",
                                     "sequence_number")
        heading = 'Story Search Results'

    else:
        raise TypeError, "Unsupported search target!"

    vars = { 'item_name': base_name,
             'plural_suffix': plural_suffix,
             'heading': heading,
             'search_term' : name,
             'media_url' : settings.MEDIA_URL, 
             'style' : 'default',
             'which_credit' : credit }
    return paginate_response(request, things, template, vars)
def publisher(request, publisher_id):
    """
    Display the details page for a Publisher.
    """
    style = get_style(request)
    pub = get_object_or_404(Publisher, id = publisher_id)

    vars = { 'publisher': pub, 'error_subject': pub }
    return paginate_response(request, pub.series_set.order_by('name'),
                             'gcd/details/publisher.html', vars)
Exemplo n.º 18
0
def show_publisher(request, publisher, preview=False):
    publisher_series = publisher.active_series().order_by("sort_name")
    vars = {
        "publisher": publisher,
        "current": publisher.series_set.filter(deleted=False, is_current=True),
        "error_subject": publisher,
        "preview": preview,
    }

    return paginate_response(request, publisher_series, "gcd/details/publisher.html", vars)
Exemplo n.º 19
0
def show_publisher(request, publisher, preview=False):
    publisher_series = publisher.active_series().order_by('sort_name')
    vars = { 'publisher': publisher,
             'current': publisher.series_set.filter(deleted=False,
                                                    is_current=True),
             'error_subject': publisher,
             'preview': preview}
    
    return paginate_response(request, publisher_series,
                             'gcd/details/publisher.html', vars)
def imprint(request, imprint_id):
    """
    Display the details page for an Imprint.
    """

    style = get_style(request)
    imprint = get_object_or_404(Publisher, id=imprint_id)
    imprint_series = imprint.imprint_series_set.order_by("name")

    vars = {"publisher": imprint, "error_subject": "%s" % imprint, "style": style}
    return paginate_response(request, imprint_series, "gcd/details/publisher.html", vars)
def show_indicia_publisher(request, indicia_publisher, preview=False):
    indicia_publisher_issues = indicia_publisher.active_issues().order_by(
      'series__name', 'sort_code')

    vars = { 'indicia_publisher' : indicia_publisher,
             'error_subject': '%s' % indicia_publisher,
             'preview': preview }
    return paginate_response(request,
                             indicia_publisher_issues,
                             'gcd/details/indicia_publisher.html',
                             vars)
def series_with_both_notes(request):
    series = Series.objects.filter(deleted=False)\
                           .exclude(publication_notes='').exclude(notes='')
    vars = {
        'heading': 'Series',
        'search_item': 'With Publication Notes and Notes',
        'item_name': 'series',
        'plural_suffix': '',
    }

    return paginate_response(request, series,
                             'projects/series_with_both_notes.html', vars)
Exemplo n.º 23
0
def imprints_in_use(request):
    """
    This project is geared towards clearing out the old imprint field so we can
    either remove it or start over with a new 'imprint' concept with a consistent
    definition.  For this we need a list of imprints in use that can be filtered
    and sorted by a few basic attributes.
    """

    imprints = Publisher.objects.filter(deleted=0, is_master=0)

    qargs = {'deleted': 0, 'is_master': 0}
    qorder = ['series_count', 'parent__name', 'name']

    vars = {
        'heading': 'Imprints',
        'search_item': 'In Use',
        'item_name': 'imprint',
        'plural_suffix': 's',
    }

    if (request.GET):
        form = ImprintsInUseForm(request.GET)
        form.is_valid()
        if form.is_valid():
            data = form.cleaned_data

            # Extra filters
            if data['parent']:
                qargs['parent'] = data['parent']
            if data['parent_country']:
                qargs['parent__country'] = data['parent_country']
            if data['imprint_country']:
                qargs['country'] = data['imprint_country']

            # Override order
            if data['order1'] or data['order2'] or data['order3']:
                qorder = []
                if data['order1']:
                    qorder.append(data['order1'])
                if data['order2']:
                    qorder.append(data['order2'])
                if data['order3']:
                    qorder.append(data['order3'])
    else:
        form = ImprintsInUseForm(auto_id=True,
          initial=dict(zip(('order1', 'order2', 'order3'), qorder)))

    imprints = imprints.filter(**qargs).order_by(*qorder)
    vars['form'] = form

    return paginate_response(request, imprints,
                             'projects/imprints_in_use.html', vars)
Exemplo n.º 24
0
def show_brand(request, brand, preview=False):
    brand_issues = brand.active_issues().order_by('series__sort_name',
                                                  'sort_code')

    vars = {
        'brand' : brand,
        'error_subject': '%s' % brand,
        'preview': preview
    }
    return paginate_response(request,
                             brand_issues,
                             'gcd/details/brand.html',
                             vars)
Exemplo n.º 25
0
def imprint(request, imprint_id):
    """
    Display the details page for an Imprint.
    """
    style = get_style(request)
    imprint = get_object_or_404(Publisher, id = imprint_id)
    imprint_series = imprint.imprint_series_set.order_by('name')

    vars = { 'publisher' : imprint, 'error_subject': '%s' % imprint }
    return paginate_response(request,
                             imprint_series,
                             'gcd/details/publisher.html',
                             vars)
def imprint(request, imprint_id):
    """
    Display the details page for an Imprint.
    """
    style = get_style(request)
    imprint = get_object_or_404(Publisher, id = imprint_id)
    imprint_series = imprint.imprint_series_set.order_by('name')

    vars = { 'publisher' : imprint, 'error_subject': '%s' % imprint }
    return paginate_response(request,
                             imprint_series,
                             'gcd/details/publisher.html',
                             vars)
Exemplo n.º 27
0
def publisher(request, publisher_id):
    """Display the details page for a Publisher."""

    style = get_style(request)
    pub = get_object_or_404(Publisher, id=publisher_id)

    vars = {
        'publisher': pub,
        'error_subject': pub,
        'style': style,
        'media_url': settings.MEDIA_URL
    }
    return paginate_response(request, pub.series_set.order_by('name'),
                             'gcd/details/publisher.html', vars)
Exemplo n.º 28
0
def show_brand(request, brand, preview=False):
    brand_issues = brand.active_issues().order_by('series__sort_name',
                                                  'sort_code')
    uses = brand.in_use.all()
    vars = {
        'brand' : brand,
        'uses' : uses,
        'error_subject': '%s' % brand,
        'preview': preview
    }
    return paginate_response(request,
                             brand_issues,
                             'gcd/details/brand.html',
                             vars)
Exemplo n.º 29
0
def publisher(request, publisher_id):
    """
    Display the details page for a Publisher.
    """
    pub = get_object_or_404(Publisher, id = publisher_id)
    if pub.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'publisher', 'id': publisher_id}))

    vars = { 'publisher': pub,
             'current': pub.series_set.filter(deleted=False, is_current=True),
             'error_subject': pub }
    return paginate_response(request, pub.active_series().order_by('name'),
                             'gcd/details/publisher.html', vars)
Exemplo n.º 30
0
def show_brand_group(request, brand_group, preview=False):
    brand_issues = brand_group.active_issues().order_by('series__sort_name',
                                                        'sort_code')
    brand_emblems = brand_group.active_emblems()

    vars = {
        'brand' : brand_group,
        'brand_emblems': brand_emblems,
        'error_subject': '%s' % brand_group,
        'preview': preview
    }
    return paginate_response(request,
                             brand_issues,
                             'gcd/details/brand_group.html',
                             vars)
def issues_with_several_covers(request):
    """
    This project is geared towards moving variant covers into variant issues.
    For this we need a list of such issues that can be filtered and sorted
    by a few basic attributes.
    """

    issues=Issue.objects.annotate(covers=Count('cover'))
    issues=issues.annotate(covers_deleted=Sum('cover__deleted'))
    issues=issues.filter(covers__gt=1+F('covers_deleted'), deleted=False)

    qargs = {'deleted': False}
    qorder = ['series__name', 'series__year_began', 'number']

    vars = {
        'heading': 'Issues',
        'search_item': 'with several covers',
        'item_name': 'issue',
        'plural_suffix': 's',
    }

    if (request.GET):
        form = IssuesWithCoversForm(request.GET)
        form.is_valid()
        if form.is_valid():
            data = form.cleaned_data

            # Extra filters
            if data['publisher']:
                qargs['series__publisher__id'] = data['publisher']

        get_copy = request.GET.copy()
        get_copy.pop('page', None)
        vars['query_string'] = get_copy.urlencode()
    else:
        form = IssuesWithCoversForm()
        issues = issues.filter(series__publisher__id=78) # initial is Marvel, need to keep #issues smaller
        # for the pagination bar and select box
        vars['query_string'] = 'publisher=54'
        get_copy = request.GET.copy()
        get_copy['items'] = [(u'publisher', 54),]
        request.GET = get_copy
    issues = issues.filter(**qargs).order_by(*qorder)
    vars['form'] = form
    vars['advanced_search'] = True

    return paginate_response(request, issues,
                             'projects/issues_with_several_covers.html', vars, per_page=50)
def issue_cover_notes(request):
    """
    This project is geared towards cleaning up identical cover and issue notes.
    For this we need a list of such issues that can be filtered and sorted
    by a few basic attributes.
    """
    cover = StoryType.objects.get(name="cover")
    issues = (
        Issue.objects.exclude(notes__exact="")
        .filter(story__type=cover, story__notes=F("notes"), story__deleted=False, deleted=False)
        .all()
    )

    qargs = {"deleted": False}
    qorder = ["series__sort_name", "series__year_began", "sort_code", "number"]

    vars = {
        "heading": "Issues",
        "search_item": "with identical notes and cover notes",
        "item_name": "issue",
        "plural_suffix": "s",
    }

    if request.GET:
        form = IssueCoverNotesForm(request.GET)
        form.is_valid()
        if form.is_valid():
            data = form.cleaned_data

            # Extra filters
            if data["publisher"]:
                qargs["series__publisher__id"] = data["publisher"]
            if data["country"]:
                qargs["series__country"] = data["country"]
            if data["language"]:
                qargs["series__language"] = data["language"]

        get_copy = request.GET.copy()
        get_copy.pop("page", None)
        vars["query_string"] = get_copy.urlencode()
    else:
        form = IssueCoverNotesForm()
    issues = issues.filter(**qargs).order_by(*qorder)
    vars["form"] = form
    vars["advanced_search"] = True

    return paginate_response(request, issues, "projects/issue_cover_notes.html", vars, page_size=50)
Exemplo n.º 33
0
def select_issues_from_preselection(request, issues, cancel):
    data = {'issue': True,
            'allowed_selects': ['issue',],
            'return': add_selected_issues_to_collection,
            'cancel': cancel}
    select_key = store_select_data(request, None, data)
    context = {'select_key': select_key,
            'multiple_selects': True,
            'item_name': 'issue',
            'plural_suffix': 's',
            'no_bulk_edit': True,
            'all_pre_selected': True,
            'heading': 'Issues'
    }
    return paginate_response(request, issues,
                            'gcd/search/issue_list.html', context,
                            per_page=issues.count())
Exemplo n.º 34
0
def story_reprint_inspection(request):
    stories = Story.objects.filter(
        deleted=False, migration_status__reprint_needs_inspection=True)

    qargs = {'deleted': False}
    qorder = [
        'issue__series__sort_name', 'issue__series__year_began',
        'issue__sort_code', 'issue__number', 'sequence_number'
    ]

    vars = {
        'heading': 'Sequences',
        'search_item': 'whose migrated reprint notes need inspection',
        'item_name': 'sequence',
        'plural_suffix': 's',
    }

    if (request.GET):
        form = ReprintInspectionForm(request.GET)
        form.is_valid()
        if form.is_valid():
            data = form.cleaned_data

            # Extra filters
            if data['publisher']:
                qargs['issue__series__publisher__id'] = data['publisher']
            if data['country']:
                qargs['issue__series__country'] = data['country']
            if data['language']:
                qargs['issue__series__language'] = data['language']

        get_copy = request.GET.copy()
        get_copy.pop('page', None)
        vars['query_string'] = get_copy.urlencode()
    else:
        form = ReprintInspectionForm()
    stories = stories.filter(**qargs).order_by(*qorder)
    print stories.count()
    vars['form'] = form
    vars['advanced_search'] = True

    return paginate_response(request,
                             stories,
                             'projects/story_reprint_inspection.html',
                             vars,
                             page_size=50)
Exemplo n.º 35
0
def issue_cover_notes(request):
    """
    This project is geared towards cleaning up identical cover and issue notes.
    For this we need a list of such issues that can be filtered and sorted
    by a few basic attributes.
    """
    cover = StoryType.objects.get(name='cover')
    issues = Issue.objects.exclude(notes__exact='').\
             filter(story__type=cover, story__notes=F('notes'),
                    story__deleted=False, deleted=False).all()

    qargs = {'deleted': False}
    qorder = ['series__sort_name', 'series__year_began', 'sort_code', 'number']

    vars = {
        'heading': 'Issues',
        'search_item': 'with identical notes and cover notes',
        'item_name': 'issue',
        'plural_suffix': 's',
    }

    if (request.GET):
        form = IssueCoverNotesForm(request.GET)
        form.is_valid()
        if form.is_valid():
            data = form.cleaned_data

            # Extra filters
            if data['publisher']:
                qargs['series__publisher__id'] = data['publisher']
            if data['country']:
                qargs['series__country'] = data['country']
            if data['language']:
                qargs['series__language'] = data['language']

        get_copy = request.GET.copy()
        get_copy.pop('page', None)
        vars['query_string'] = get_copy.urlencode()
    else:
        form = IssueCoverNotesForm()
    issues = issues.filter(**qargs).order_by(*qorder)
    vars['form'] = form
    vars['advanced_search'] = True

    return paginate_response(request, issues,
                             'projects/issue_cover_notes.html', vars, page_size=50)
Exemplo n.º 36
0
def select_from_on_sale_weekly(request, year=None, week=None):
    issues_on_sale, context = do_on_sale_weekly(request, year, week)
    if context is None:
        return issues_on_sale
    data = {'issue': True,
            'allowed_selects': ['issue'],
            'return': add_selected_issues_to_collection}
    select_key = store_select_data(request, None, data)
    context.update({'select_key': select_key,
                    'multiple_selects': True,
                    'item_name': 'issue',
                    'plural_suffix': 's',
                    'no_bulk_edit': True,
                    'all_pre_selected': True,
                    'heading': 'Issues'
                    })
    return paginate_response(request, issues_on_sale,
                             'gcd/status/issues_on_sale.html', context,
                             per_page=max(1, issues_on_sale.count()))
Exemplo n.º 37
0
def series_and_issue(request, series_name, issue_nr, sort=ORDER_ALPHA):
    """ Looks for issue_nr in series_name """
    things = Issue.objects.exclude(deleted=True) \
               .filter(series__name__exact = series_name) \
               .filter(number__exact = issue_nr)

    if things.count() == 1:  # if one display the issue
        return HttpResponseRedirect(
            urlresolvers.reverse(issue, kwargs={'issue_id': things[0].id}))
    else:  # if more or none use issue_list.html from search
        context = {
            'items': things,
            'item_name': 'issue',
            'plural_suffix': 's',
            'heading': series_name + ' #' + issue_nr,
        }

        return paginate_response(request, things, 'gcd/search/issue_list.html',
                                 context)
Exemplo n.º 38
0
def covers(request, series_id):
    """
    Display the cover gallery for a series.
    """

    series = get_object_or_404(Series, id=series_id)
    if series.deleted:
        return HttpResponseRedirect(
            urlresolvers.reverse('change_history',
                                 kwargs={
                                     'model_name': 'series',
                                     'id': series_id
                                 }))

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and \
      request.user.groups.filter(name='editor'):
        can_mark = True
    else:
        can_mark = False

    covers = Cover.objects.filter(issue__series=series, deleted=False) \
                          .select_related('issue')

    vars = {
        'series': series,
        'error_subject': '%s covers' % series,
        'table_width': table_width,
        'can_mark': can_mark
    }

    return paginate_response(
        request,
        covers,
        'gcd/details/covers.html',
        vars,
        page_size=50,
        callback_key='tags',
        callback=lambda page: get_image_tags_per_page(page, series))
Exemplo n.º 39
0
def imprint(request, imprint_id):
    """
    Display the details page for an Imprint.
    """
    imprint = get_object_or_404(Publisher, id = imprint_id, parent__isnull=False)
    if imprint.parent.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'publisher', 'id': imprint.parent_id}))

    if imprint.deleted:
        return HttpResponseRedirect(urlresolvers.reverse('change_history',
          kwargs={'model_name': 'imprint', 'id': imprint_id}))

    imprint_series = imprint.imprint_series_set.exclude(deleted=True) \
      .order_by('name')

    vars = { 'publisher' : imprint, 'error_subject': '%s' % imprint }
    return paginate_response(request,
                             imprint_series,
                             'gcd/details/publisher.html',
                             vars)
Exemplo n.º 40
0
def brands(request, publisher_id):
    """
    Finds brands of a publisher.
    """

    publisher = get_object_or_404(Publisher, id = publisher_id)
    brands = publisher.brands.all()

    sort = ORDER_ALPHA
    if 'sort' in request.GET:
        sort = request.GET['sort']

    if (sort == ORDER_CHRONO):
        brands = brands.order_by('year_began', 'name')
    else:
        brands = brands.order_by('name', 'year_began')

    return paginate_response(request, brands, 'gcd/details/brands.html', {
      'publisher' : publisher,
      'error_subject' : '%s brands' % publisher,
    })
Exemplo n.º 41
0
def publishers_by_name(request, publisher_name, sort=ORDER_ALPHA):
    #Finds publishers and imprints

    pubs = Publisher.objects.filter(
      name__icontains = publisher_name)
    if (sort == ORDER_ALPHA):
        pubs = pubs.order_by('name', 'year_began')
    elif (sort == ORDER_CHRONO):
        pubs = pubs.order_by('year_began', 'name')

    get_copy = request.GET.copy()
    get_copy.pop('page', None)

    return paginate_response(request, pubs, 'gcd/search/publisher_list.html',
        { 'items': pubs,
          'item_name': 'publisher',
          'plural_suffix': 's',
          'heading' : 'Publisher Search Results',
          'query_string' : get_copy.urlencode(),
          'style' : 'default',
        })
Exemplo n.º 42
0
def imprints(request, publisher_id):
    """
    Finds imprints of a publisher.  Imprints are defined as those
    publishers whose parent_id matches the given publisher.
    """

    publisher = get_object_or_404(Publisher, id = publisher_id)
    imps = publisher.imprint_set.all()

    sort = ORDER_ALPHA
    if 'sort' in request.GET:
        sort = request.GET['sort']

    if (sort == ORDER_CHRONO):
        imps = imps.order_by('year_began', 'name')
    else:
        imps = imps.order_by('name', 'year_began')

    style = get_style(request)
    return paginate_response(request, imps, 'gcd/details/imprints.html', {
      'publisher' : publisher,
      'error_subject' : '%s imprints' % publisher,
      })
Exemplo n.º 43
0
def series_with_isbn(request):
    series = Series.objects.filter(notes__icontains='ISBN',deleted=False).\
             exclude(notes__icontains='ISBN 91-88334-36-8')

    qargs = {'deleted': False}
    qorder = ['sort_name', 'year_began']

    vars = {
        'heading': 'Series',
        'search_item': 'with ISBN in notes',
        'item_name': 'series',
        'plural_suffix': '',
    }

    if (request.GET):
        get_copy = request.GET.copy()
        get_copy.pop('page', None)
        vars['query_string'] = get_copy.urlencode()
    series = series.filter(**qargs).order_by(*qorder)
    vars['advanced_search'] = True

    return paginate_response(request, series,
                             'projects/series_with_isbn.html', vars, page_size=50)
Exemplo n.º 44
0
def covers_to_replace(request, starts_with=None):
    """
    Display the covers that are marked for replacement.
    """

    covers = Cover.objects.filter(marked=True)
    if starts_with:
        covers = covers.filter(issue__series__name__startswith=starts_with)
    covers = covers.order_by("issue__series__name",
                             "issue__series__year_began", "issue__key_date")

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    return paginate_response(request,
                             covers,
                             'gcd/status/covers_to_replace.html', {
                                 'table_width': table_width,
                                 'starts_with': starts_with
                             },
                             page_size=50,
                             callback_key='tags',
                             callback=get_image_tags_per_page)
Exemplo n.º 45
0
def add_selected_issues_to_collection(request, data):
    selections = data['selections']
    issues = Issue.objects.filter(id__in=selections['issue'])
    if 'story' in selections:
        issues |= Issue.objects.filter(story__id__in=selections['story'])
    issues = issues.distinct()
    if not issues.count():
        raise ErrorWithMessage("No issues were selected.")

    post_process_selection = data.get('post_process_selection', None)
    if 'confirm_selection' in request.POST:
        collection_id = int(request.POST['collection_id'])
        return add_issues_to_collection(
            request,
            collection_id,
            issues,
            urlresolvers.reverse('view_collection',
                                 kwargs={'collection_id': collection_id}),
            post_process_selection=post_process_selection)
    else:
        if 'collection_list' in data:
            collection_list = data['collection_list']
        else:
            collection_list = request.user.collector.ordered_collections()
        context = {
            'item_name': 'issue',
            'plural_suffix': 's',
            'no_bulk_edit': True,
            'heading': 'Issues',
            'confirm_selection': True,
            'collection_list': collection_list
        }
        return paginate_response(request,
                                 issues,
                                 'gcd/search/issue_list.html',
                                 context,
                                 per_page=issues.count())
Exemplo n.º 46
0
def covers(request, series_id, style="default"):
    """
    Display the cover gallery for a series.
    """

    series = get_object_or_404(Series, id=series_id)
    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = 5

    # TODO: once we get permissions going 'can_mark' should be one
    if request.user.is_authenticated() and \
      request.user.groups.filter(name='editor'):
        can_mark = True
    else:
        can_mark = False

    covers = Cover.objects.filter(issue__series=series)\
                          .filter(has_image = '1').select_related('issue')

    style = get_style(request)
    vars = {
        'series': series,
        'error_subject': '%s covers' % series,
        'table_width': table_width,
        'style': style,
        'can_mark': can_mark
    }

    return paginate_response(
        request,
        covers,
        'gcd/details/covers.html',
        vars,
        page_size=50,
        callback_key='tags',
        callback=lambda page: get_image_tags_per_page(page, series))
Exemplo n.º 47
0
def select_issues_from_preselection(request,
                                    issues,
                                    cancel,
                                    post_process_selection=None,
                                    collection_list=None,
                                    not_found=None):
    if not issues.exists():
        raise ErrorWithMessage("No issues to select from.")
    data = {
        'issue': True,
        'allowed_selects': [
            'issue',
        ],
        'return': add_selected_issues_to_collection,
        'cancel': cancel
    }
    if post_process_selection:
        data['post_process_selection'] = post_process_selection
    if collection_list:
        data['collection_list'] = collection_list
    select_key = store_select_data(request, None, data)
    context = {
        'select_key': select_key,
        'multiple_selects': True,
        'item_name': 'issue',
        'plural_suffix': 's',
        'no_bulk_edit': True,
        'all_pre_selected': True,
        'heading': 'Issues found that can be selected for import.',
        'not_found': not_found
    }
    return paginate_response(request,
                             issues,
                             'gcd/search/issue_list.html',
                             context,
                             per_page=issues.count())
Exemplo n.º 48
0
    template = 'gcd/search/%s_list.html' % \
                 ('content' if target == 'sequence' else item_name)

    search_values = request.GET.copy()
    target, method, logic, used_search_terms = used_search(search_values)
    context['target'] = target
    context['method'] = method
    context['logic'] = logic
    context['used_search_terms'] = used_search_terms

    if item_name == 'cover':
        context['table_width'] = COVER_TABLE_WIDTH
        return paginate_response(request,
                                 items,
                                 template,
                                 context,
                                 page_size=50,
                                 callback_key='tags',
                                 callback=get_image_tags_per_page)
    else:
        return paginate_response(request, items, template, context)


def combine_q(data, *qobjs):
    """
    The queries against each table must be anded as they will be run using
    JOINs in a single query.  The method compute_prefix adjusted the query
    terms to work with the JOIN as they were added in each of the
    search_* methods.
    """
    filtered = filter(lambda x: x != None, qobjs)
Exemplo n.º 49
0
def process_select_search(request, select_key):
    try:
        data = get_select_data(request, select_key)
    except KeyError:
        return _cant_get_key(request)
    publisher = data.get('publisher', False)
    series = data.get('series', False)
    issue = data.get('issue', False)
    story = data.get('story', False)
    if 'search_series' in request.GET:
        issue = False
    search_form = get_select_search_form(search_publisher=publisher,
                                         search_series=series,
                                         search_issue=issue,
                                         search_story=story)(request.GET)
    if not search_form.is_valid():
        return HttpResponseRedirect(
            urlresolvers.reverse('select_object',
                                 kwargs={'select_key': select_key}) + '?' +
            request.META['QUERY_STRING'])
    cd = search_form.cleaned_data

    if 'search_story' in request.GET or 'search_cover' in request.GET:
        search = Story.objects.filter(
            issue__number=cd['number'],
            deleted=False,
            issue__series__name__icontains=cd['series'],
            issue__series__publisher__name__icontains=cd['publisher'])
        publisher = cd['publisher'] if cd['publisher'] else '?'
        if cd['year']:
            search = search.filter(issue__series__year_began=cd['year'])
            heading = '%s (%s, %d series) #%s' % (cd['series'], publisher,
                                                  cd['year'], cd['number'])
        else:
            heading = '%s (%s, ? series) #%s' % (cd['series'], publisher,
                                                 cd['number'])
        if cd['sequence_number']:
            search = search.filter(sequence_number=cd['sequence_number'])
            heading += ', seq.# ' + str(cd['sequence_number'])
        if 'search_cover' in request.GET:
            # ? make StoryType.objects.get(name='cover').id a CONSTANT ?
            search = search.filter(type=StoryType.objects.get(name='cover'))
            base_name = 'cover'
            plural_suffix = 's'
        else:
            base_name = 'stor'
            plural_suffix = 'y,ies'
        template = 'gcd/search/content_list.html'
        heading = 'Search for: ' + heading
        search = search.order_by("issue__series__name",
                                 "issue__series__year_began",
                                 "issue__key_date", "sequence_number")
    elif 'search_issue' in request.GET:
        search = Issue.objects.filter(
            number=cd['number'],
            deleted=False,
            series__name__icontains=cd['series'],
            series__publisher__name__icontains=cd['publisher'])
        publisher = cd['publisher'] if cd['publisher'] else '?'
        if cd['year']:
            search = search.filter(series__year_began=cd['year'])
            heading = '%s (%s, %d series) #%s' % (cd['series'], publisher,
                                                  cd['year'], cd['number'])
        else:
            heading = '%s (%s, ? series) #%s' % (cd['series'], publisher,
                                                 cd['number'])
        heading = 'Issue search for: ' + heading
        template = 'gcd/search/issue_list.html'
        base_name = 'issue'
        plural_suffix = 's'
        search = search.order_by("series__name", "series__year_began",
                                 "key_date")
    elif 'search_series' in request.GET:
        search = Series.objects.filter(
            deleted=False,
            name__icontains=cd['series'],
            publisher__name__icontains=cd['publisher'])
        heading = 'Series search for: ' + cd['series']
        if cd['year']:
            search = search.filter(year_began=cd['year'])
            heading = '%s (%s, %d series)' % (cd['series'], publisher,
                                              cd['year'])
        template = 'gcd/search/series_list.html'
        base_name = 'series'
        plural_suffix = ''
        search = search.order_by("name")
    elif 'search_publisher' in request.GET:
        search = Publisher.objects.filter(deleted=False,
                                          name__icontains=cd['publisher'])
        heading = 'Publisher search for: ' + cd['publisher']
        template = 'gcd/search/publisher_list.html'
        base_name = 'publisher'
        plural_suffix = 's'
        search = search.order_by("name")

    context = {
        'item_name': base_name,
        'plural_suffix': plural_suffix,
        'items': search,
        'heading': heading,
        'select_key': select_key,
        'no_bulk_edit': True,
        'query_string': request.META['QUERY_STRING'],
        'publisher': cd['publisher'] if cd['publisher'] else '',
        'series': cd['series'] if 'series' in cd and cd['series'] else '',
        'year': cd['year'] if 'year' in cd and cd['year'] else '',
        'number': cd['number'] if 'number' in cd and cd['number'] else ''
    }
    return paginate_response(request, search, template, context)
Exemplo n.º 50
0
def generic_by_name(request,
                    name,
                    q_obj,
                    sort,
                    class_=Story,
                    template='gcd/search/content_list.html',
                    credit=None,
                    related=[]):
    """
    Helper function for the most common search cases.
    """
    name = name.encode('utf-8')
    base_name = 'unknown'
    plural_suffix = 's'
    query_val = {'method': 'icontains'}

    if (class_ in (Series, Brand, IndiciaPublisher)):
        if class_ is IndiciaPublisher:
            base_name = 'indicia_publisher'
            display_name = 'Indicia Publisher'
        else:
            display_name = class_.__name__
            base_name = display_name.lower()
        plural_suffix = '' if class_ is Series else 's'
        things = class_.objects.exclude(deleted=True).filter(q_obj)
        if related:
            things = things.select_related(*related)
        if (sort == ORDER_ALPHA):
            things = things.order_by("name", "year_began")
        elif (sort == ORDER_CHRONO):
            things = things.order_by("year_began", "name")
        heading = '%s Search Results' % display_name
        # query_string for the link to the advanced search
        query_val['target'] = base_name
        query_val[base_name] = name

    elif class_ is Issue:
        base_name = 'issue'
        things = Issue.objects.exclude(deleted=True).filter(q_obj) \
                   .select_related('series__publisher')
        if (sort == ORDER_ALPHA):
            things = things.order_by("series__name", "key_date")
        elif (sort == ORDER_CHRONO):
            things = things.order_by("key_date", "series__name")
        heading = 'Issue Search Results'
        # query_string for the link to the advanced search
        query_val['target'] = 'issue'
        query_val['isbn'] = name

    elif (class_ is Story):
        # TODO: move this outside when series deletes are implemented
        q_obj &= Q(deleted=False)

        base_name = 'stor'
        plural_suffix = 'y,ies'

        things = class_.objects.filter(q_obj)
        things = things.select_related('issue__series__publisher', 'type')

        # TODO: This order_by stuff only works for Stories, which is
        # TODO: OK for now, but might not always be.
        if (sort == ORDER_ALPHA):
            things = things.order_by("issue__series__name",
                                     "issue__series__year_began",
                                     "issue__key_date", "sequence_number")
        elif (sort == ORDER_CHRONO):
            things = things.order_by("issue__key_date", "issue__series__name",
                                     "issue__series__year_began",
                                     "sequence_number")
        heading = 'Story Search Results'
        # build the query_string for the link to the advanced search
        query_val['target'] = 'sequence'
        if credit in [
                'script', 'pencils', 'inks', 'colors', 'letters', 'job_number'
        ]:
            query_val[credit] = name
        # remove the ones which are not matched in display of results
        elif credit in ['reprint', 'title', 'feature']:
            query_val[credit] = name
            credit = None
        elif credit.startswith('editing_search'):
            query_val['story_editing'] = name
            query_val['issue_editing'] = name
            query_val['logic'] = True
        elif credit.startswith('any'):
            query_val['logic'] = True
            for credit_type in [
                    'script', 'pencils', 'inks', 'colors', 'letters',
                    'story_editing', 'issue_editing'
            ]:
                query_val[credit_type] = name
        elif credit.startswith('characters'):
            query_val['characters'] = name
            # OR-logic only applies to credits, so we cannnot use it
            # to mimic the double search for characters and features here
            # query_val['feature'] = name
            # query_val['logic'] = True
    else:
        raise TypeError, "Unsupported search target!"

    vars = {
        'item_name': base_name,
        'plural_suffix': plural_suffix,
        'heading': heading,
        'search_term': name,
        'media_url': settings.MEDIA_URL,
        'query_string': urlencode(query_val),
        'which_credit': credit
    }
    return paginate_response(request, things, template, vars)
Exemplo n.º 51
0
    # it to build the URLs for the links to other pages.
    get_copy = request.GET.copy()
    get_copy.pop('page', None)

    context = {
        'advanced_search': True,
        'item_name' : item_name,
        'plural_suffix' : plural_suffix,
        'heading' : data['target'].title() + ' Search Results',
        'query_string' : get_copy.urlencode(),
        'style' : 'default',
    }
    if request.GET.has_key('style'):
        context['style'] = request.GET['style']

    return paginate_response(request, items, template, context)


def combine_q(data, *qobjs):
    """
    The queries against each table must be anded as they will be run using
    JOINs in a single query.  The method compute_prefix adjusted the query
    terms to work with the JOIN as they were added in each of the
    search_* methods.
    """
    filtered = filter(lambda x: x != None, qobjs)
    if filtered:
        return reduce(lambda x, y: x & y, filtered)
    return None

Exemplo n.º 52
0
def on_sale_weekly(request, year=None, week=None):
    """
    Produce a page displaying the comics on-sale in a given week.
    """
    try:
        if 'week' in request.GET:
            year = int(request.GET['year'])
            week = int(request.GET['week'])
            # Do a redirect, otherwise pagination links point to today
            return HttpResponseRedirect(
                urlresolvers.reverse(
                'on_sale_weekly',
                kwargs={'year': year, 'week': week} ))
        if year:
            year = int(year)
        if week:
            week = int(week)
    except ValueError:
        year = None
    if year == None:
        year, week = date.today().isocalendar()[0:2]
    # gregorian calendar date of the first day of the given ISO year
    fourth_jan = date(int(year), 1, 4)
    delta = timedelta(fourth_jan.isoweekday()-1)
    year_start = fourth_jan - delta
    monday = year_start + timedelta(weeks=int(week)-1)
    sunday = monday + timedelta(days=6)
    # we need this to filter out incomplete on-sale dates
    if monday.month != sunday.month:
        endday = monday.replace(day=monthrange(monday.year,monday.month)[1])
        issues_on_sale = \
          Issue.objects.filter(on_sale_date__gte=monday.isoformat(),
                               on_sale_date__lte=endday.isoformat())
        startday = sunday.replace(day=1)
        issues_on_sale = issues_on_sale | \
          Issue.objects.filter(on_sale_date__gte=startday.isoformat(),
                               on_sale_date__lte=sunday.isoformat())

    else:
        issues_on_sale = Issue.objects\
                              .filter(on_sale_date__gte=monday.isoformat(),
                                      on_sale_date__lte=sunday.isoformat())
    previous_week = (monday - timedelta(weeks=1)).isocalendar()[0:2]
    if monday + timedelta(weeks=1) <= date.today():
        next_week = (monday + timedelta(weeks=1)).isocalendar()[0:2]
    else:
        next_week = None
    heading = "Issues on-sale in week %s/%s" % (week, year)
    dates = "from %s to %s" % (monday.isoformat(), sunday.isoformat())
    query_val = {'target': 'issue', 
                 'method': 'icontains'}
    query_val['start_date'] = monday.isoformat()
    query_val['end_date'] = sunday.isoformat()
    query_val['use_on_sale_date'] = True
    vars = { 
        'items': issues_on_sale,
        'heading': heading,
        'dates': dates,
        'previous_week': previous_week,
        'next_week': next_week,
        'query_string': urlencode(query_val),
    }

    return paginate_response(request, issues_on_sale, 'gcd/status/issues_on_sale.html', vars)
Exemplo n.º 53
0
def daily_covers(request, show_date=None):
    """
    Produce a page displaying the covers uploaded on a given day.
    """

    # similar to the section in daily_changes. if we need it elsewhere,
    # time to split it out.
    requested_date = None
    try:
        if 'day' in request.GET:
            year = int(request.GET['year'])
            month = int(request.GET['month'])
            day = int(request.GET['day'])
            # Do a redirect, otherwise pagination links point to today
            requested_date = date(year, month, day)
            show_date = requested_date.strftime('%Y-%m-%d')
            return HttpResponseRedirect(
                urlresolvers.reverse('covers_by_date',
                                     kwargs={'show_date': show_date}))

        elif show_date:
            year = int(show_date[0:4])
            month = int(show_date[5:7])
            day = int(show_date[8:10])
            requested_date = date(year, month, day)

        else:
            # Don't redirect, as this is a proper default.
            requested_date = date.today()
            show_date = requested_date.strftime('%Y-%m-%d')

    except (TypeError, ValueError):
        # Redirect so the user sees the date in the URL that matches
        # the output, instead of seeing the erroneous date.
        return HttpResponseRedirect(
            urlresolvers.reverse(
                'covers_by_date',
                kwargs={'show_date': date.today().strftime('%Y-%m-%d')}))

    date_before = requested_date + timedelta(-1)
    if requested_date < date.today():
        date_after = requested_date + timedelta(1)
    else:
        date_after = None

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = COVER_TABLE_WIDTH

    covers = Cover.objects.filter(last_upload__range=(\
                                  datetime.combine(requested_date, time.min),
                                  datetime.combine(requested_date, time.max)),
                                  deleted=False)

    covers = covers.order_by("issue__series__publisher__name",
                             "issue__series__sort_name",
                             "issue__series__year_began", "issue__sort_code")

    return paginate_response(request,
                             covers,
                             'gcd/status/daily_covers.html', {
                                 'date': show_date,
                                 'date_after': date_after,
                                 'date_before': date_before,
                                 'table_width': table_width,
                             },
                             page_size=50,
                             callback_key='tags',
                             callback=get_image_tags_per_page)
Exemplo n.º 54
0
def daily_covers(request, show_date=None):
    """
    Produce a page displaying the covers uploaded on a given day.
    """

    requested_date = None
    try:
        if 'day' in request.GET:
            year = int(request.GET['year'])
            month = int(request.GET['month'])
            day = int(request.GET['day'])
            # Do a redirect, otherwise pagination links point to today
            requested_date = date(year, month, day)
            show_date = requested_date.strftime('%Y-%m-%d')
            return HttpResponseRedirect(
                urlresolvers.reverse('covers_by_date',
                                     kwargs={'show_date': show_date}))

        elif show_date:
            year = int(show_date[0:4])
            month = int(show_date[5:7])
            day = int(show_date[8:10])

        else:
            # Don't redirect, as this is a proper default.
            requested_date = date.today()

        if requested_date is None:
            requested_date = date(year, month, day)

        if show_date is None:
            show_date = requested_date.strftime('%Y-%m-%d')

    except (TypeError, ValueError):
        # Redirect so the user sees the date in the URL that matches
        # the output, instead of seeing the erroneous date.
        return HttpResponseRedirect(
            urlresolvers.reverse(
                'covers_by_date',
                kwargs={'show_date': date.today().strftime('%Y-%m-%d')}))

    date_before = requested_date + timedelta(-1)
    if requested_date < date.today():
        date_after = requested_date + timedelta(1)
    else:
        date_after = None

    # TODO: Figure out optimal table width and/or make it user controllable.
    table_width = 5
    style = get_style(request)

    covers = Cover.objects.filter(modified__range=(\
                                  datetime.combine(requested_date, time.min),
                                  datetime.combine(requested_date, time.max)))

    covers = covers.filter(has_image=True)
    covers = covers.order_by("issue__series__publisher__name",
                             "issue__series__name",
                             "issue__series__year_began", "issue__sort_code")

    # TODO: once we have permissions 'can_mark' should be one
    if request.user.is_authenticated() and \
      request.user.groups.filter(name='editor'):
        can_mark = True
    else:
        can_mark = False

    return paginate_response(request,
                             covers,
                             'gcd/status/daily_covers.html', {
                                 'date': show_date,
                                 'date_after': date_after,
                                 'date_before': date_before,
                                 'table_width': table_width,
                                 'style': style,
                                 'can_mark': can_mark
                             },
                             page_size=50,
                             callback_key='tags',
                             callback=get_image_tags_per_page)