Exemple #1
0
def share(request, what, item):
    if what == 'collection':
        item = get_object_or_404(Collection, slug=item)
        collection = item
        thing = item.get_kind_display()
        artist = item.artist()

    elif what == 'track':
        item = get_object_or_404(Track, slug=item)
        thing = 'track'
        collection = item.collection
        artist = item.artist

    else:
        raise Http404

    share_url_params = {
        'title': collection.slug,
    }
    if what == 'track':
        share_url_params['play'] = item.slug

    artist = artist or 'Mx3'

    share_url = 'https://mx3creations.com' + reverse('track',
                                                     kwargs=share_url_params)
    share_title = f'"{item.title}" by {artist}'
    share_message = f'Listen to {share_title} at <a href="{share_url}">{share_url}</a>'

    page_title = globs.page_title(_("Share"))
    return render(request, 'share.pug', locals())
Exemple #2
0
def track(request, data):
    tracks_count = len(data['tracks'])

    # fill collection playlist_url with the only track's video url
    if tracks_count == 1 and data['tracks'][0].video_url:
        data['collection'].playlist_url = data['tracks'][0].video_url

    btn_array_class = 'quad' if data['collection'].playlist_url else 'tri'

    # auto-play collections w/ 1 track
    if tracks_count == 1:
        data['play_track'] = data['tracks'].first()

    # set page title
    if data.get('play_track', None) is None:
        # artist – title kind
        # eg.
        # Mx3 – Patterns EP
        page_title = f"{data['collection'].title}"
    else:
        # artist – title
        page_title = f"{data['play_track'].artist} – {data['play_track'].title}"

    # set artist in page if they're all the same (treated in template)
    # Collection.artist returns False if multiple different artists are in the same collection's tracks
    multiple_artists = not data['collection'].artist()

    page_title = globs.page_title(page_title)
    data.update(locals())

    return render(request, 'track.pug', data)
Exemple #3
0
def coding(request):

    projects = globs.use_cache('github')

    if projects is None:
        repos = requests.get(
            'https://api.github.com/users/ewen-lbh/repos').json()
        pinned_repos = requests.get(
            'https://gh-pinned-repos.now.sh/?username=ewen-lbh').json()
        pinned_repos_names = [r['repo'] for r in pinned_repos]
        projects = list()

        for repo in repos:
            if repo['fork']: continue
            # print(repo, end="\n\n\n")
            project = {
                "url": repo['html_url'],
                "description": repo['description'],
                "name": repo['name'],
                "full_name": repo['full_name'],
                "creation": repo['created_at'],
                "update": repo['updated_at'],
                # "license": repo['license']['name'],
                # "license_url": repo['license']['url'],
                "pinned": repo['name'] in pinned_repos_names
            }
            projects.append(project)

        globs.write_cache('github', projects)

    page_title = globs.page_title('coding')
    return render(request, 'coding.pug', locals())
Exemple #4
0
def home(request):

    proudest_tracks = Track.objects.order_by('-goodness',
                                             '-collection__date')[:4]
    proudest = list()
    for track in proudest_tracks:
        proudest.append((track, track.collection))
    page_title = globs.page_title('')
    return render(request, 'home.pug', locals())
Exemple #5
0
def graphism(request):

    total_size = 0
    for dirpath, dirnames, filenames in os.walk(
            staticfiles_storage.path(f'static/graphism/images/')):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            # skip if it is symbolic link
            if not os.path.islink(fp):
                total_size += os.path.getsize(fp)

    page_title = globs.page_title('graphism')
    return render(request, 'graphism.pug', locals())
Exemple #6
0
def contact(request):
    form = ContactForm(request.POST or None)
    if form.is_valid():
        try:
            send_mail(
                # subject
                f'[mx3creations] Contact from {form.cleaned_data["email"]}',
                # body
                form.cleaned_data['message'],
                # from email
                form.cleaned_data['email'],
                # to email
                (
                    '*****@*****.**', ))
            sent = True
        except Exception as e:
            sent = False
            regex = re.compile(r'\[.+\](.+)')
            send_error = regex.sub(r'\1', str(e)) + " :/"

    page_title = globs.page_title(_("Contact"))
    return render(request, 'contact.pug', locals())
Exemple #7
0
def music(request, sort='date'):
    latest = Collection.objects.latest('date')
    collections = Collection.objects.all()
    total_hours = sum(
        [t.duration().total_seconds() / 3600 for t in collections])
    total_count = sum([len(t.tracks()) for t in collections])
    page_title = globs.page_title(_('Music'))

    sort_options = [
        #format: model field, pretty
        ('date', _('Release date', )),
        ('goodness', _('Goodness')),
        ('kinds', _('Kinds')),
        ('work-time', _('Work time')),
    ]

    def goodness_sort(collection):
        goodness = Collection.goodness(slug=collection.slug)

        return goodness

    if sort == 'goodness':
        collections = sorted(collections, reverse=True, key=goodness_sort)
    elif sort == 'date':
        collections = collections.order_by('-date')
    elif sort == 'kinds':
        collections = {
            'EP': collections.filter(kind='EP').order_by('-date'),
            'AB': collections.filter(kind='AB').order_by('-date'),
            'SG': collections.filter(kind='SG').order_by('-date')
        }
    elif sort == 'work-time':
        collections = collections.order_by('-work_time')
    else:
        collections = collections.order_by(sort)

    return render(request, 'music.pug', locals())
Exemple #8
0
def about(request):

    page_title = globs.page_title(_("About"))
    return render(request, 'about.pug', locals())
Exemple #9
0
def legal(request):

    page_title = 'Legal'
    return render(request, 'legal.pug',
                  {'page_title': globs.page_title(page_title)})
Exemple #10
0
def videos(request):

    page_title = globs.page_title(_("Videos"))
    return render(request, 'videos.pug', locals())
Exemple #11
0
def image(request, data):

    data.update(locals())
    return render(request, 'image.pug', data)
Exemple #12
0
def cover_art(request, title):
    collection = get_object_or_404(Collection, slug=title)
    page_title = globs.page_title(_("Download artworks"))
    collection_title = collection.title
    return render(request, 'cover_art.pug', locals())
Exemple #13
0
def brand_resources(request):

    page_title = globs.page_title(_("Brand resources"))
    return render(request, 'brand_resources.pug', locals())
Exemple #14
0
def search(request, q=None):
    if 'AJAX' in request.POST:
        q = request.POST['q']
        # results count limit per category
        results_count_limit = 4
    else:
        q = q or request.POST['q'] or request.GET['q']
        results_count_limit = False

    search_query = q

    if search_query in ('>allresults'):
        music_tracks = Track.objects.all()
        music_collections = Collection.objects.all()

    else:

        # search in collections
        # search similarity threshold
        threshold = 75

        def fuzzy_search(Model, field: str, threshold: int = 75):

            results = list(
                set([e[0] for e in Model.objects.all().values_list(field)]))
            results = process.extract(q, results)
            results = [e[0] for e in results if e[1] > threshold]
            return results

        # get list of strings containing matching artists
        tracks_artists = fuzzy_search(Track, 'artist', threshold)
        # initialize the QuerySet object
        music_tracks = Track.objects.none()
        # for string of the list, "convert" the string to a QuerySet
        # and merge it to keep a single QuerySet
        for track_artist in tracks_artists:
            music_tracks |= Track.objects.filter(artist=track_artist)
        # repeat this procedure for track titles and collections titles
        tracks_titles = fuzzy_search(Track, 'title', threshold)
        for track_title in tracks_titles:
            music_tracks |= Track.objects.filter(title=track_title)
        collections_titles = fuzzy_search(Collection, 'title', threshold)

        music_collections = Collection.objects.none()
        for collection_title in collections_titles:
            music_collections |= Collection.objects.filter(
                title=collection_title)

    original_results_count = len(music_collections) + len(music_tracks)
    if results_count_limit:
        limit = floor(results_count_limit / 2)
        music_collections = music_collections[:limit]
        music_tracks = music_tracks[:limit]
    results_count = len(music_collections) + len(music_tracks)
    more_results_available = original_results_count > results_count

    if 'AJAX' in request.POST:
        return render(request, 'ajax-search.pug', locals())
    else:
        if len(music_tracks) == 1:
            trk = music_tracks.first()
            return redirect('track', title=trk.collection.slug, play=trk.slug)

        if len(music_collections) == 1:
            col = music_collections.first()
            return redirect('track', title=col.slug)

        page_title = globs.page_title(_("Search"))
        return render(request, 'search.pug', locals())
Exemple #15
0
def stats(request):
    music_hours = round(
        sum([e.duration().seconds for e in Collection.objects.all()]) / 3600,
        2)
    music_count = len(Track.objects.all())
    music_albums = len(Collection.objects.filter(kind='AB'))
    music_eps = len(Collection.objects.filter(kind='EP'))
    music_singles = len(Collection.objects.filter(kind='SG'))
    music_remixes = len(Track.objects.filter(is_remix=True))
    # If the video_url field is not empty nor null
    music_videos = len(
        Track.objects.exclude(video_url__isnull=True).exclude(
            video_url__exact=''))
    # NOTICE: If we have more or less than 2 cover arts for each collection, this will break
    graphism_covers = len(Collection.objects.all()) * 2
    newsletter_members = len(Member.objects.all())
    coding_repos = 14

    stats = [{
        'name':
        _("Music"),
        'stats': [
            {
                'value': music_count,
                'desc': _("Tracks")
            },
            {
                'value': music_hours,
                'desc': _("Hours of music")
            },
            {
                'value': music_videos,
                'desc': _("Music videos")
            },
            {
                'value': music_remixes,
                'desc': _("Remixes")
            },
            {
                'value': music_albums + music_eps,
                'desc': _("Albums & EPs")
            },
            {
                'value': music_singles,
                'desc': _("Singles")
            },
        ]
    }, {
        'name': _("Graphism"),
        'stats': [{
            'value': graphism_covers,
            'desc': _("Cover arts")
        }]
    }, {
        'name': _("Newsletter"),
        'stats': [{
            'value': newsletter_members,
            'desc': _("Members")
        }]
    }, {
        'name':
        _("Coding"),
        'stats': [{
            'value': coding_repos,
            'desc': _("Projects on GitHub")
        }]
    }]

    page_title = globs.page_title(_("Statistics"))
    return render(request, 'stats.pug', locals())
Exemple #16
0
def coding(request):

    page_title = globs.page_title(_('coding'))
    return render(request, 'coding.pug', locals())
Exemple #17
0
def graphism(request):

    page_title = globs.page_title(_("Graphism"))
    return render(request, 'graphism.pug', locals())
Exemple #18
0
def project(request, data):

    data.update(locals())
    return render(request, 'project.pug', data)
Exemple #19
0
def get_error_page(request, status_code):
    return render(request, 'error.pug', error_texts(status_code))