Exemplo n.º 1
0
def login(request, success_url=None):

    if request.user.is_authenticated():
        return redirect(reverse('profile'))

    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            try:
                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password'))
                if user is not None:
                    auth.login(request, user)
                    messages.error(request, "You have successfully logged in")
                    return redirect(reverse('profile'))
                else:
                    subscription_not_ended = arrow.now() < arrow.get(user.subscription_end)

                    if not subscription_not_ended:
                        form.add_error(None,"Your subscription has now ended")

                    form.add_error(None,"Your email or password was not recognised")

            except SubscriptionEnded:
                form.add_error(None,"Your subscription has now ended")

    else:
        form = UserLoginForm()

    args = {'form':form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
Exemplo n.º 2
0
    def date_time(self,
                  missing: Optional[str] = '',
                  ignore_file_modify_date: bool = False) -> datetime.datetime:
        """
        Use pymediainfo (if present) to extract file encoding date.

        Also use ExifTool if appropriate.

        :param ignore_file_modify_date: if True, don't return the file
        modification date
        :return  python datetime format the date and time the video was
        recorded, else missing
        """

        if have_pymediainfo:
            try:
                d = self.media_info.to_data()['tracks'][0][
                    'encoded_date']  # type: str
            except KeyError:
                logging.debug(
                    'Failed to extract date time from %s using pymediainfo: trying ExifTool',
                    self.full_file_name)
                return super().date_time(
                    missing=missing,
                    ignore_file_modify_date=ignore_file_modify_date)
            else:
                # format of date string is something like:
                # UTC 2016-05-09 03:28:03
                try:
                    if d.startswith('UTC'):
                        u = d[4:]
                        a = arrow.get(u, "YYYY-MM-DD HH:mm:ss")  # type: Arrow
                        dt_mi = a.to('local')
                        dt = dt_mi.datetime  # type: datetime.datetime

                        # Compare the value returned by mediainfo against that
                        # returned by ExifTool, if and only if there is a time zone
                        # setting in the video file that ExifTool can extract
                        tz = self._get('TimeZone', None)
                        if tz is None:
                            logging.debug(
                                "Using pymediainfo datetime (%s), because ExifTool did "
                                "not detect a time zone in %s", dt_mi,
                                self.full_file_name)
                        if tz is not None:
                            dt_et = super().date_time(
                                missing=None, ignore_file_modify_date=True)
                            if dt_et is not None:
                                hour = tz // 60 * -1
                                minute = tz % 60 * -1
                                if arrow_shift_support:
                                    adjusted_dt_mi = dt_mi.shift(
                                        hours=hour, minutes=minute).naive
                                else:
                                    adjusted_dt_mi = dt_mi.replace(
                                        hours=hour, minutes=minute).naive
                                if datetime_roughly_equal(
                                        adjusted_dt_mi, dt_et):
                                    logging.debug(
                                        "Favoring ExifTool datetime metadata (%s) "
                                        "over mediainfo (%s) for %s, because it includes "
                                        "a timezone", dt_et, adjusted_dt_mi,
                                        self.full_file_name)
                                    dt = dt_et
                                else:
                                    logging.debug(
                                        "Although ExifTool located a time zone"
                                        "in %s's metadata, using the mediainfo result, "
                                        "because the two results are different. Mediainfo: %s / "
                                        "%s  (before / after). ExifTool: %s. Time zone: %s",
                                        self.full_file_name, dt,
                                        adjusted_dt_mi, dt_et, tz)

                    else:
                        dt = datetime.datetime.strptime(d, "%Y-%m-%d %H:%M:%S")
                except (ValueError, OverflowError):
                    logging.warning(
                        "Error parsing date time metadata %s for video %s. Will try ExifTool.",
                        d, self.full_file_name)
                    return super().date_time(missing)
                except arrow.arrow.parser.ParserError:
                    logging.warning(
                        "Error parsing date time metadata using Arrow %s for video %s. Will try "
                        "ExifTool.", d, self.full_file_name)
                    return super().date_time(missing)
                except Exception as e:
                    logging.error(
                        "Unknown error parsing date time metadata %s for video %s. %s. "
                        "Will try ExifTool.", d, self.full_file_name, e)
                    return super().date_time(missing)
                except:
                    logging.error(
                        "Unknown error parsing date time metadata %s for video %s. "
                        "Will try ExifTool.", d, self.full_file_name)
                    return super().date_time(missing)
                else:
                    return dt

        else:
            return super().date_time(missing)
Exemplo n.º 3
0
def profile(request):
    subscription_humanize = arrow.get(request.user.subscription_end).humanize()
    login_humanize = arrow.get(request.user.date_joined).humanize()
    args = {'subscription_humanize':subscription_humanize, 'login_humanize':login_humanize}
    return render(request,'profile.html', args)